OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # On Android we build unit test bundles as shared libraries. To run | 7 # On Android we build unit test bundles as shared libraries. To run |
8 # tests, we launch a special "test runner" apk which loads the library | 8 # tests, we launch a special "test runner" apk which loads the library |
9 # then jumps into it. Since java is required for many tests | 9 # then jumps into it. Since java is required for many tests |
10 # (e.g. PathUtils.java), a "pure native" test bundle is inadequate. | 10 # (e.g. PathUtils.java), a "pure native" test bundle is inadequate. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 [strip, '--strip-unneeded', self._native_library, '-o', dest]) | 121 [strip, '--strip-unneeded', self._native_library, '-o', dest]) |
122 if self._jars: | 122 if self._jars: |
123 destdir = os.path.join(self._output_directory, 'java/libs') | 123 destdir = os.path.join(self._output_directory, 'java/libs') |
124 if not os.path.exists(destdir): | 124 if not os.path.exists(destdir): |
125 os.makedirs(destdir) | 125 os.makedirs(destdir) |
126 for jar in self._jars: | 126 for jar in self._jars: |
127 dest = os.path.join(destdir, os.path.basename(jar)) | 127 dest = os.path.join(destdir, os.path.basename(jar)) |
128 logging.warn('%s --> %s', jar, dest) | 128 logging.warn('%s --> %s', jar, dest) |
129 shutil.copyfile(jar, dest) | 129 shutil.copyfile(jar, dest) |
130 | 130 |
131 def CreateBundle(self, ant_compile): | 131 def CreateBundle(self, sdk_build): |
132 """Create the apk bundle source and assemble components.""" | 132 """Create the apk bundle source and assemble components.""" |
133 if not ant_compile: | 133 if not sdk_build: |
134 self._SOURCE_FILES.append('Android.mk') | 134 self._SOURCE_FILES.append('Android.mk') |
135 self._REPLACEME_FILES.append('Android.mk') | 135 self._REPLACEME_FILES.append('Android.mk') |
136 self._CopyTemplateFilesAndClearDir() | 136 self._CopyTemplateFilesAndClearDir() |
137 self._ReplaceStrings() | 137 self._ReplaceStrings() |
138 self._CopyLibraryAndJars() | 138 self._CopyLibraryAndJars() |
139 | 139 |
140 def Compile(self, ant_args): | 140 def Compile(self, ant_args): |
141 """Build the generated apk with ant. | 141 """Build the generated apk with ant. |
142 | 142 |
143 Args: | 143 Args: |
(...skipping 29 matching lines...) Expand all Loading... |
173 parser.add_option('--verbose', | 173 parser.add_option('--verbose', |
174 help='Be verbose') | 174 help='Be verbose') |
175 parser.add_option('--native_library', | 175 parser.add_option('--native_library', |
176 help='Full name of native shared library test bundle') | 176 help='Full name of native shared library test bundle') |
177 parser.add_option('--jars', | 177 parser.add_option('--jars', |
178 help='Space separated list of jars to be included') | 178 help='Space separated list of jars to be included') |
179 parser.add_option('--output', | 179 parser.add_option('--output', |
180 help='Output directory for generated files.') | 180 help='Output directory for generated files.') |
181 parser.add_option('--app_abi', default='armeabi', | 181 parser.add_option('--app_abi', default='armeabi', |
182 help='ABI for native shared library') | 182 help='ABI for native shared library') |
| 183 parser.add_option('--sdk-build', type='int', default=1, |
| 184 help='Unless set to 0, build the generated apk with ant. ' |
| 185 'Otherwise assume compiling within the Android ' |
| 186 'source tree using Android.mk.') |
| 187 # FIXME(beverloo): Remove --ant-compile when all users adopted. |
183 parser.add_option('--ant-compile', action='store_true', | 188 parser.add_option('--ant-compile', action='store_true', |
184 help=('If specified, build the generated apk with ant. ' | 189 help=('If specified, build the generated apk with ant. ' |
185 'Otherwise assume compiling within the Android ' | 190 'Otherwise assume compiling within the Android ' |
186 'source tree using Android.mk.')) | 191 'source tree using Android.mk.')) |
187 parser.add_option('--ant-args', | 192 parser.add_option('--ant-args', |
188 help='extra args for ant') | 193 help='extra args for ant') |
189 | 194 |
190 options, _ = parser.parse_args(argv) | 195 options, _ = parser.parse_args(argv) |
191 | 196 |
192 # It is not an error to specify no native library; the apk should | 197 # It is not an error to specify no native library; the apk should |
193 # still be generated and build. It will, however, print | 198 # still be generated and build. It will, however, print |
194 # NATIVE_LOADER_FAILED when run. | 199 # NATIVE_LOADER_FAILED when run. |
195 if not options.output: | 200 if not options.output: |
196 raise Exception('No output directory specified for generated files') | 201 raise Exception('No output directory specified for generated files') |
197 | 202 |
198 if options.verbose: | 203 if options.verbose: |
199 logging.basicConfig(level=logging.DEBUG, format=' %(message)s') | 204 logging.basicConfig(level=logging.DEBUG, format=' %(message)s') |
200 | 205 |
201 # Remove all quotes from the jars string | 206 # Remove all quotes from the jars string |
202 jar_list = [] | 207 jar_list = [] |
203 if options.jars: | 208 if options.jars: |
204 jar_list = options.jars.replace('"', '').split() | 209 jar_list = options.jars.replace('"', '').split() |
205 | 210 |
206 ntag = NativeTestApkGenerator(native_library=options.native_library, | 211 ntag = NativeTestApkGenerator(native_library=options.native_library, |
207 jars=jar_list, | 212 jars=jar_list, |
208 output_directory=options.output, | 213 output_directory=options.output, |
209 target_abi=options.app_abi) | 214 target_abi=options.app_abi) |
210 ntag.CreateBundle(options.ant_compile) | 215 ntag.CreateBundle(options.sdk_build or options.ant_compile) |
211 | 216 |
212 if options.ant_compile: | 217 if options.sdk_build or options.ant_compile: |
213 ntag.Compile(options.ant_args) | 218 ntag.Compile(options.ant_args) |
214 else: | 219 else: |
215 ntag.CompileAndroidMk() | 220 ntag.CompileAndroidMk() |
216 | 221 |
217 logging.warn('COMPLETE.') | 222 logging.warn('COMPLETE.') |
218 | 223 |
219 if __name__ == '__main__': | 224 if __name__ == '__main__': |
220 sys.exit(main(sys.argv)) | 225 sys.exit(main(sys.argv)) |
OLD | NEW |