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 # |
11 # This script, generate_native_test.py, is used to generate the source | 11 # This script, generate_native_test.py, is used to generate the source |
12 # for an apk that wraps a unit test shared library bundle. That | 12 # for an apk that wraps a unit test shared library bundle. That |
13 # allows us to have a single boiler-plate application be used across | 13 # allows us to have a single boiler-plate application be used across |
14 # all unit test bundles. | 14 # all unit test bundles. |
15 | 15 |
16 import logging | 16 import logging |
17 import optparse | 17 import optparse |
18 import os | 18 import os |
19 import re | 19 import re |
20 import shutil | 20 import shutil |
21 import subprocess | 21 import subprocess |
22 import sys | 22 import sys |
23 | 23 |
| 24 # cmd_helper.py is under ../../build/android/ |
| 25 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', |
| 26 '..', 'build', 'android')) |
| 27 import cmd_helper # pylint: disable=F0401 |
| 28 |
24 | 29 |
25 class NativeTestApkGenerator(object): | 30 class NativeTestApkGenerator(object): |
26 """Generate a native test apk source tree. | 31 """Generate a native test apk source tree. |
27 | 32 |
28 TODO(jrg): develop this more so the activity name is replaced as | 33 TODO(jrg): develop this more so the activity name is replaced as |
29 well. That will allow multiple test runners to be installed at the | 34 well. That will allow multiple test runners to be installed at the |
30 same time. (The complication is that it involves renaming a java | 35 same time. (The complication is that it involves renaming a java |
31 class, which implies regeneration of a jni header, and on and on...) | 36 class, which implies regeneration of a jni header, and on and on...) |
32 """ | 37 """ |
33 | 38 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 dest = dest.replace('replaceme', self._root_name) # update the filename! | 116 dest = dest.replace('replaceme', self._root_name) # update the filename! |
112 open(dest, "w").write(contents) | 117 open(dest, "w").write(contents) |
113 | 118 |
114 def _CopyLibraryAndJars(self): | 119 def _CopyLibraryAndJars(self): |
115 """Copy the shlib and jars into the apk source tree (if relevant)""" | 120 """Copy the shlib and jars into the apk source tree (if relevant)""" |
116 if self._native_library: | 121 if self._native_library: |
117 destdir = os.path.join(self._output_directory, 'libs/armeabi') | 122 destdir = os.path.join(self._output_directory, 'libs/armeabi') |
118 if not os.path.exists(destdir): | 123 if not os.path.exists(destdir): |
119 os.makedirs(destdir) | 124 os.makedirs(destdir) |
120 dest = os.path.join(destdir, os.path.basename(self._native_library)) | 125 dest = os.path.join(destdir, os.path.basename(self._native_library)) |
121 logging.warn('%s --> %s' % (self._native_library, dest)) | 126 logging.warn('strip %s --> %s' % (self._native_library, dest)) |
122 shutil.copyfile(self._native_library, dest) | 127 strip = os.environ['STRIP'] |
| 128 cmd_helper.RunCmd( |
| 129 [strip, '--strip-unneeded', self._native_library, '-o', dest]) |
123 if self._jars: | 130 if self._jars: |
124 destdir = os.path.join(self._output_directory, 'libs') | 131 destdir = os.path.join(self._output_directory, 'libs') |
125 if not os.path.exists(destdir): | 132 if not os.path.exists(destdir): |
126 os.makedirs(destdir) | 133 os.makedirs(destdir) |
127 for jar in self._jars: | 134 for jar in self._jars: |
128 dest = os.path.join(destdir, os.path.basename(jar)) | 135 dest = os.path.join(destdir, os.path.basename(jar)) |
129 logging.warn('%s --> %s' % (jar, dest)) | 136 logging.warn('%s --> %s' % (jar, dest)) |
130 shutil.copyfile(jar, dest) | 137 shutil.copyfile(jar, dest) |
131 | 138 |
132 def CreateBundle(self): | 139 def CreateBundle(self): |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 jars=options.jar, | 192 jars=options.jar, |
186 output_directory=options.output) | 193 output_directory=options.output) |
187 ntag.CreateBundle() | 194 ntag.CreateBundle() |
188 if options.ant_compile: | 195 if options.ant_compile: |
189 ntag.Compile(options.ant_args) | 196 ntag.Compile(options.ant_args) |
190 | 197 |
191 logging.warn('COMPLETE.') | 198 logging.warn('COMPLETE.') |
192 | 199 |
193 if __name__ == '__main__': | 200 if __name__ == '__main__': |
194 sys.exit(main(sys.argv)) | 201 sys.exit(main(sys.argv)) |
OLD | NEW |