| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # On Android we build unit test bundles as shared libraries. To run | 6 # On Android we build unit test bundles as shared libraries. To run |
| 7 # tests, we launch a special "test runner" apk which loads the library | 7 # tests, we launch a special "test runner" apk which loads the library |
| 8 # then jumps into it. Since java is required for many tests | 8 # then jumps into it. Since java is required for many tests |
| 9 # (e.g. PathUtils.java), a "pure native" test bundle is inadequate. | 9 # (e.g. PathUtils.java), a "pure native" test bundle is inadequate. |
| 10 # | 10 # |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 ] | 39 ] |
| 40 | 40 |
| 41 # Files in the destion directory that have a "replaceme" string | 41 # Files in the destion directory that have a "replaceme" string |
| 42 # which should be replaced by the basename of the shared library. | 42 # which should be replaced by the basename of the shared library. |
| 43 # Note we also update the filename if 'replaceme' is itself found in | 43 # Note we also update the filename if 'replaceme' is itself found in |
| 44 # the filename. | 44 # the filename. |
| 45 _REPLACEME_FILES = ['AndroidManifest.xml', | 45 _REPLACEME_FILES = ['AndroidManifest.xml', |
| 46 'native_test_apk.xml', | 46 'native_test_apk.xml', |
| 47 'res/values/strings.xml'] | 47 'res/values/strings.xml'] |
| 48 | 48 |
| 49 def __init__(self, native_library, jars, output_directory): | 49 def __init__(self, native_library, jars, output_directory, target_abi): |
| 50 self._native_library = native_library | 50 self._native_library = native_library |
| 51 self._jars = jars | 51 self._jars = jars |
| 52 self._output_directory = output_directory | 52 self._output_directory = output_directory |
| 53 self._target_abi = target_abi |
| 53 self._root_name = None | 54 self._root_name = None |
| 54 if self._native_library: | 55 if self._native_library: |
| 55 self._root_name = self._LibraryRoot() | 56 self._root_name = self._LibraryRoot() |
| 56 logging.warn('root name: %s' % self._root_name) | 57 logging.warn('root name: %s' % self._root_name) |
| 57 | 58 |
| 58 | 59 |
| 59 def _LibraryRoot(self): | 60 def _LibraryRoot(self): |
| 60 """Return a root name for a shared library. | 61 """Return a root name for a shared library. |
| 61 | 62 |
| 62 The root name should be suitable for substitution in apk files | 63 The root name should be suitable for substitution in apk files |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 for f in self._REPLACEME_FILES: | 108 for f in self._REPLACEME_FILES: |
| 108 dest = os.path.join(self._output_directory, f) | 109 dest = os.path.join(self._output_directory, f) |
| 109 contents = open(dest).read() | 110 contents = open(dest).read() |
| 110 contents = contents.replace('replaceme', self._root_name) | 111 contents = contents.replace('replaceme', self._root_name) |
| 111 dest = dest.replace('replaceme', self._root_name) # update the filename! | 112 dest = dest.replace('replaceme', self._root_name) # update the filename! |
| 112 open(dest, "w").write(contents) | 113 open(dest, "w").write(contents) |
| 113 | 114 |
| 114 def _CopyLibraryAndJars(self): | 115 def _CopyLibraryAndJars(self): |
| 115 """Copy the shlib and jars into the apk source tree (if relevant)""" | 116 """Copy the shlib and jars into the apk source tree (if relevant)""" |
| 116 if self._native_library: | 117 if self._native_library: |
| 117 destdir = os.path.join(self._output_directory, 'libs/armeabi') | 118 destdir = os.path.join(self._output_directory, 'libs/' + self._target_abi) |
| 118 if not os.path.exists(destdir): | 119 if not os.path.exists(destdir): |
| 119 os.makedirs(destdir) | 120 os.makedirs(destdir) |
| 120 dest = os.path.join(destdir, os.path.basename(self._native_library)) | 121 dest = os.path.join(destdir, os.path.basename(self._native_library)) |
| 121 logging.warn('%s --> %s' % (self._native_library, dest)) | 122 logging.warn('%s --> %s' % (self._native_library, dest)) |
| 122 shutil.copyfile(self._native_library, dest) | 123 shutil.copyfile(self._native_library, dest) |
| 123 if self._jars: | 124 if self._jars: |
| 124 destdir = os.path.join(self._output_directory, 'libs') | 125 destdir = os.path.join(self._output_directory, 'libs') |
| 125 if not os.path.exists(destdir): | 126 if not os.path.exists(destdir): |
| 126 os.makedirs(destdir) | 127 os.makedirs(destdir) |
| 127 for jar in self._jars: | 128 for jar in self._jars: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 158 def main(argv): | 159 def main(argv): |
| 159 parser = optparse.OptionParser() | 160 parser = optparse.OptionParser() |
| 160 parser.add_option('--verbose', | 161 parser.add_option('--verbose', |
| 161 help='Be verbose') | 162 help='Be verbose') |
| 162 parser.add_option('--native_library', | 163 parser.add_option('--native_library', |
| 163 help='Full name of native shared library test bundle') | 164 help='Full name of native shared library test bundle') |
| 164 parser.add_option('--jar', action='append', | 165 parser.add_option('--jar', action='append', |
| 165 help='Include this jar; can be specified multiple times') | 166 help='Include this jar; can be specified multiple times') |
| 166 parser.add_option('--output', | 167 parser.add_option('--output', |
| 167 help='Output directory for generated files.') | 168 help='Output directory for generated files.') |
| 169 parser.add_option('--app_abi', |
| 170 help='ABI for native shared library') |
| 168 parser.add_option('--ant-compile', action='store_true', | 171 parser.add_option('--ant-compile', action='store_true', |
| 169 help='If specified, build the generated apk with ant') | 172 help='If specified, build the generated apk with ant') |
| 170 parser.add_option('--ant-args', | 173 parser.add_option('--ant-args', |
| 171 help='extra args for ant') | 174 help='extra args for ant') |
| 172 | 175 |
| 173 options, _ = parser.parse_args(argv) | 176 options, _ = parser.parse_args(argv) |
| 174 | 177 |
| 175 # It is not an error to specify no native library; the apk should | 178 # It is not an error to specify no native library; the apk should |
| 176 # still be generated and build. It will, however, print | 179 # still be generated and build. It will, however, print |
| 177 # NATIVE_LOADER_FAILED when run. | 180 # NATIVE_LOADER_FAILED when run. |
| 178 if not options.output: | 181 if not options.output: |
| 179 raise Exception('No output directory specified for generated files') | 182 raise Exception('No output directory specified for generated files') |
| 180 | 183 |
| 181 if options.verbose: | 184 if options.verbose: |
| 182 logging.basicConfig(level=logging.DEBUG, format=' %(message)s') | 185 logging.basicConfig(level=logging.DEBUG, format=' %(message)s') |
| 183 | 186 |
| 184 ntag = NativeTestApkGenerator(native_library=options.native_library, | 187 ntag = NativeTestApkGenerator(native_library=options.native_library, |
| 185 jars=options.jar, | 188 jars=options.jar, |
| 186 output_directory=options.output) | 189 output_directory=options.output, |
| 190 target_abi=options.app_abi) |
| 187 ntag.CreateBundle() | 191 ntag.CreateBundle() |
| 188 if options.ant_compile: | 192 if options.ant_compile: |
| 189 ntag.Compile(options.ant_args) | 193 ntag.Compile(options.ant_args) |
| 190 | 194 |
| 191 logging.warn('COMPLETE.') | 195 logging.warn('COMPLETE.') |
| 192 | 196 |
| 193 if __name__ == '__main__': | 197 if __name__ == '__main__': |
| 194 sys.exit(main(sys.argv)) | 198 sys.exit(main(sys.argv)) |
| OLD | NEW |