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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 ] | 45 ] |
46 | 46 |
47 # Files in the destion directory that have a "replaceme" string | 47 # Files in the destion directory that have a "replaceme" string |
48 # which should be replaced by the basename of the shared library. | 48 # which should be replaced by the basename of the shared library. |
49 # Note we also update the filename if 'replaceme' is itself found in | 49 # Note we also update the filename if 'replaceme' is itself found in |
50 # the filename. | 50 # the filename. |
51 _REPLACEME_FILES = ['AndroidManifest.xml', | 51 _REPLACEME_FILES = ['AndroidManifest.xml', |
52 'native_test_apk.xml', | 52 'native_test_apk.xml', |
53 'res/values/strings.xml'] | 53 'res/values/strings.xml'] |
54 | 54 |
55 def __init__(self, native_library, jars, output_directory, target_abi): | 55 def __init__(self, native_library, jars, strip_binary, output_directory, |
| 56 target_abi): |
56 self._native_library = native_library | 57 self._native_library = native_library |
57 self._jars = jars | 58 self._jars = jars |
| 59 self._strip_binary = strip_binary |
58 self._output_directory = os.path.abspath(output_directory) | 60 self._output_directory = os.path.abspath(output_directory) |
59 self._target_abi = target_abi | 61 self._target_abi = target_abi |
60 self._root_name = None | 62 self._root_name = None |
61 if self._native_library: | 63 if self._native_library: |
62 self._root_name = self._LibraryRoot() | 64 self._root_name = self._LibraryRoot() |
63 logging.warn('root name: %s', self._root_name) | 65 logging.warn('root name: %s', self._root_name) |
64 | 66 |
65 def _LibraryRoot(self): | 67 def _LibraryRoot(self): |
66 """Return a root name for a shared library. | 68 """Return a root name for a shared library. |
67 | 69 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 open(dest, 'w').write(contents) | 111 open(dest, 'w').write(contents) |
110 | 112 |
111 def _CopyLibraryAndJars(self): | 113 def _CopyLibraryAndJars(self): |
112 """Copy the shlib and jars into the apk source tree (if relevant).""" | 114 """Copy the shlib and jars into the apk source tree (if relevant).""" |
113 if self._native_library: | 115 if self._native_library: |
114 destdir = os.path.join(self._output_directory, 'libs/' + self._target_abi) | 116 destdir = os.path.join(self._output_directory, 'libs/' + self._target_abi) |
115 if not os.path.exists(destdir): | 117 if not os.path.exists(destdir): |
116 os.makedirs(destdir) | 118 os.makedirs(destdir) |
117 dest = os.path.join(destdir, os.path.basename(self._native_library)) | 119 dest = os.path.join(destdir, os.path.basename(self._native_library)) |
118 logging.warn('strip %s --> %s', self._native_library, dest) | 120 logging.warn('strip %s --> %s', self._native_library, dest) |
119 strip = os.environ['STRIP'] | |
120 cmd_helper.RunCmd( | 121 cmd_helper.RunCmd( |
121 [strip, '--strip-unneeded', self._native_library, '-o', dest]) | 122 [self._strip_binary, '--strip-unneeded', self._native_library, '-o', |
| 123 dest]) |
122 if self._jars: | 124 if self._jars: |
123 destdir = os.path.join(self._output_directory, 'java/libs') | 125 destdir = os.path.join(self._output_directory, 'java/libs') |
124 if not os.path.exists(destdir): | 126 if not os.path.exists(destdir): |
125 os.makedirs(destdir) | 127 os.makedirs(destdir) |
126 for jar in self._jars: | 128 for jar in self._jars: |
127 dest = os.path.join(destdir, os.path.basename(jar)) | 129 dest = os.path.join(destdir, os.path.basename(jar)) |
128 logging.warn('%s --> %s', jar, dest) | 130 logging.warn('%s --> %s', jar, dest) |
129 shutil.copyfile(jar, dest) | 131 shutil.copyfile(jar, dest) |
130 | 132 |
131 def CreateBundle(self, sdk_build): | 133 def CreateBundle(self, sdk_build): |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 parser.add_option('--verbose', | 175 parser.add_option('--verbose', |
174 help='Be verbose') | 176 help='Be verbose') |
175 parser.add_option('--native_library', | 177 parser.add_option('--native_library', |
176 help='Full name of native shared library test bundle') | 178 help='Full name of native shared library test bundle') |
177 parser.add_option('--jars', | 179 parser.add_option('--jars', |
178 help='Space separated list of jars to be included') | 180 help='Space separated list of jars to be included') |
179 parser.add_option('--output', | 181 parser.add_option('--output', |
180 help='Output directory for generated files.') | 182 help='Output directory for generated files.') |
181 parser.add_option('--app_abi', default='armeabi', | 183 parser.add_option('--app_abi', default='armeabi', |
182 help='ABI for native shared library') | 184 help='ABI for native shared library') |
| 185 parser.add_option('--strip-binary', |
| 186 help='Binary to use for stripping the native libraries.') |
183 parser.add_option('--sdk-build', type='int', default=1, | 187 parser.add_option('--sdk-build', type='int', default=1, |
184 help='Unless set to 0, build the generated apk with ant. ' | 188 help='Unless set to 0, build the generated apk with ant. ' |
185 'Otherwise assume compiling within the Android ' | 189 'Otherwise assume compiling within the Android ' |
186 'source tree using Android.mk.') | 190 'source tree using Android.mk.') |
187 # FIXME(beverloo): Remove --ant-compile when all users adopted. | 191 # FIXME(beverloo): Remove --ant-compile when all users adopted. |
188 parser.add_option('--ant-compile', action='store_true', | 192 parser.add_option('--ant-compile', action='store_true', |
189 help=('If specified, build the generated apk with ant. ' | 193 help=('If specified, build the generated apk with ant. ' |
190 'Otherwise assume compiling within the Android ' | 194 'Otherwise assume compiling within the Android ' |
191 'source tree using Android.mk.')) | 195 'source tree using Android.mk.')) |
192 parser.add_option('--ant-args', action='append', | 196 parser.add_option('--ant-args', action='append', |
193 help='extra args for ant') | 197 help='extra args for ant') |
194 | 198 |
195 options, _ = parser.parse_args(argv) | 199 options, _ = parser.parse_args(argv) |
196 | 200 |
197 # It is not an error to specify no native library; the apk should | 201 # It is not an error to specify no native library; the apk should |
198 # still be generated and build. It will, however, print | 202 # still be generated and build. It will, however, print |
199 # NATIVE_LOADER_FAILED when run. | 203 # NATIVE_LOADER_FAILED when run. |
200 if not options.output: | 204 if not options.output: |
201 raise Exception('No output directory specified for generated files') | 205 raise Exception('No output directory specified for generated files') |
202 | 206 |
203 if options.verbose: | 207 if options.verbose: |
204 logging.basicConfig(level=logging.DEBUG, format=' %(message)s') | 208 logging.basicConfig(level=logging.DEBUG, format=' %(message)s') |
205 | 209 |
| 210 if not options.strip_binary: |
| 211 options.strip_binary = os.getenv('STRIP') |
| 212 if not options.strip_binary: |
| 213 raise Exception('No tool for stripping the libraries has been supplied') |
| 214 |
206 # Remove all quotes from the jars string | 215 # Remove all quotes from the jars string |
207 jar_list = [] | 216 jar_list = [] |
208 if options.jars: | 217 if options.jars: |
209 jar_list = options.jars.replace('"', '').split() | 218 jar_list = options.jars.replace('"', '').split() |
210 | 219 |
211 ntag = NativeTestApkGenerator(native_library=options.native_library, | 220 ntag = NativeTestApkGenerator(native_library=options.native_library, |
212 jars=jar_list, | 221 jars=jar_list, |
| 222 strip_binary=options.strip_binary, |
213 output_directory=options.output, | 223 output_directory=options.output, |
214 target_abi=options.app_abi) | 224 target_abi=options.app_abi) |
215 ntag.CreateBundle(options.sdk_build or options.ant_compile) | 225 ntag.CreateBundle(options.sdk_build or options.ant_compile) |
216 | 226 |
217 if options.sdk_build or options.ant_compile: | 227 if options.sdk_build or options.ant_compile: |
218 ntag.Compile(options.ant_args) | 228 ntag.Compile(options.ant_args) |
219 else: | 229 else: |
220 ntag.CompileAndroidMk() | 230 ntag.CompileAndroidMk() |
221 | 231 |
222 logging.warn('COMPLETE.') | 232 logging.warn('COMPLETE.') |
223 | 233 |
224 if __name__ == '__main__': | 234 if __name__ == '__main__': |
225 sys.exit(main(sys.argv)) | 235 sys.exit(main(sys.argv)) |
OLD | NEW |