OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2015 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 """Adds the code parts to a resource APK.""" | 7 """Adds the code parts to a resource APK.""" |
8 | 8 |
9 import argparse | 9 import argparse |
10 import itertools | 10 import itertools |
(...skipping 13 matching lines...) Expand all Loading... |
24 '.3gpp2', '.amr', '.awb', '.wma', '.wmv', '.webm') | 24 '.3gpp2', '.amr', '.awb', '.wma', '.wmv', '.webm') |
25 | 25 |
26 | 26 |
27 def _ParseArgs(args): | 27 def _ParseArgs(args): |
28 parser = argparse.ArgumentParser() | 28 parser = argparse.ArgumentParser() |
29 build_utils.AddDepfileOption(parser) | 29 build_utils.AddDepfileOption(parser) |
30 parser.add_argument('--assets', | 30 parser.add_argument('--assets', |
31 help='GYP-list of files to add as assets in the form ' | 31 help='GYP-list of files to add as assets in the form ' |
32 '"srcPath:zipPath", where ":zipPath" is optional.', | 32 '"srcPath:zipPath", where ":zipPath" is optional.', |
33 default='[]') | 33 default='[]') |
| 34 parser.add_argument('--java-resources', |
| 35 help='GYP-list of java_resources JARs to include.', |
| 36 default='[]') |
34 parser.add_argument('--write-asset-list', | 37 parser.add_argument('--write-asset-list', |
35 action='store_true', | 38 action='store_true', |
36 help='Whether to create an assets/assets_list file.') | 39 help='Whether to create an assets/assets_list file.') |
37 parser.add_argument('--uncompressed-assets', | 40 parser.add_argument('--uncompressed-assets', |
38 help='Same as --assets, except disables compression.', | 41 help='Same as --assets, except disables compression.', |
39 default='[]') | 42 default='[]') |
40 parser.add_argument('--resource-apk', | 43 parser.add_argument('--resource-apk', |
41 help='An .ap_ file built using aapt', | 44 help='An .ap_ file built using aapt', |
42 required=True) | 45 required=True) |
43 parser.add_argument('--output-apk', | 46 parser.add_argument('--output-apk', |
(...skipping 12 matching lines...) Expand all Loading... |
56 'android-abi. Can be specified multiple times.', | 59 'android-abi. Can be specified multiple times.', |
57 default=[]) | 60 default=[]) |
58 parser.add_argument('--android-abi', | 61 parser.add_argument('--android-abi', |
59 help='Android architecture to use for native libraries') | 62 help='Android architecture to use for native libraries') |
60 parser.add_argument('--secondary-android-abi', | 63 parser.add_argument('--secondary-android-abi', |
61 help='The secondary Android architecture to use for' | 64 help='The secondary Android architecture to use for' |
62 'secondary native libraries') | 65 'secondary native libraries') |
63 parser.add_argument('--native-lib-placeholders', | 66 parser.add_argument('--native-lib-placeholders', |
64 help='GYP-list of native library placeholders to add.', | 67 help='GYP-list of native library placeholders to add.', |
65 default='[]') | 68 default='[]') |
66 parser.add_argument('--emma-device-jar', | |
67 help='Path to emma_device.jar to include.') | |
68 parser.add_argument('--uncompress-shared-libraries', | 69 parser.add_argument('--uncompress-shared-libraries', |
69 action='store_true', | 70 action='store_true', |
70 help='Uncompress shared libraries') | 71 help='Uncompress shared libraries') |
71 options = parser.parse_args(args) | 72 options = parser.parse_args(args) |
72 options.assets = build_utils.ParseGypList(options.assets) | 73 options.assets = build_utils.ParseGypList(options.assets) |
73 options.uncompressed_assets = build_utils.ParseGypList( | 74 options.uncompressed_assets = build_utils.ParseGypList( |
74 options.uncompressed_assets) | 75 options.uncompressed_assets) |
| 76 options.java_resources = build_utils.ParseGypList(options.java_resources) |
75 options.native_lib_placeholders = build_utils.ParseGypList( | 77 options.native_lib_placeholders = build_utils.ParseGypList( |
76 options.native_lib_placeholders) | 78 options.native_lib_placeholders) |
77 all_libs = [] | 79 all_libs = [] |
78 for gyp_list in options.native_libs: | 80 for gyp_list in options.native_libs: |
79 all_libs.extend(build_utils.ParseGypList(gyp_list)) | 81 all_libs.extend(build_utils.ParseGypList(gyp_list)) |
80 options.native_libs = all_libs | 82 options.native_libs = all_libs |
81 secondary_libs = [] | 83 secondary_libs = [] |
82 for gyp_list in options.secondary_native_libs: | 84 for gyp_list in options.secondary_native_libs: |
83 secondary_libs.extend(build_utils.ParseGypList(gyp_list)) | 85 secondary_libs.extend(build_utils.ParseGypList(gyp_list)) |
84 options.secondary_native_libs = secondary_libs | 86 options.secondary_native_libs = secondary_libs |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 190 |
189 secondary_native_libs = [] | 191 secondary_native_libs = [] |
190 if options.secondary_native_libs: | 192 if options.secondary_native_libs: |
191 secondary_native_libs = sorted(options.secondary_native_libs) | 193 secondary_native_libs = sorted(options.secondary_native_libs) |
192 input_paths += secondary_native_libs | 194 input_paths += secondary_native_libs |
193 depfile_deps += secondary_native_libs | 195 depfile_deps += secondary_native_libs |
194 | 196 |
195 if options.dex_file: | 197 if options.dex_file: |
196 input_paths.append(options.dex_file) | 198 input_paths.append(options.dex_file) |
197 | 199 |
198 if options.emma_device_jar: | |
199 input_paths.append(options.emma_device_jar) | |
200 | |
201 input_strings = [options.android_abi, | 200 input_strings = [options.android_abi, |
202 options.native_lib_placeholders, | 201 options.native_lib_placeholders, |
203 options.uncompress_shared_libraries] | 202 options.uncompress_shared_libraries] |
204 | 203 |
205 if options.secondary_android_abi: | 204 if options.secondary_android_abi: |
206 input_strings.append(options.secondary_android_abi) | 205 input_strings.append(options.secondary_android_abi) |
207 | 206 |
| 207 if options.java_resources: |
| 208 input_paths.extend(options.java_resources) |
| 209 |
208 _assets = _ExpandPaths(options.assets) | 210 _assets = _ExpandPaths(options.assets) |
209 _uncompressed_assets = _ExpandPaths(options.uncompressed_assets) | 211 _uncompressed_assets = _ExpandPaths(options.uncompressed_assets) |
210 | 212 |
211 for src_path, dest_path in itertools.chain(_assets, _uncompressed_assets): | 213 for src_path, dest_path in itertools.chain(_assets, _uncompressed_assets): |
212 input_paths.append(src_path) | 214 input_paths.append(src_path) |
213 input_strings.append(dest_path) | 215 input_strings.append(dest_path) |
214 | 216 |
215 def on_stale_md5(): | 217 def on_stale_md5(): |
216 tmp_apk = options.output_apk + '.tmp' | 218 tmp_apk = options.output_apk + '.tmp' |
217 try: | 219 try: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 for name in sorted(options.native_lib_placeholders): | 269 for name in sorted(options.native_lib_placeholders): |
268 # Empty libs files are ignored by md5check, but rezip requires them | 270 # Empty libs files are ignored by md5check, but rezip requires them |
269 # to be empty in order to identify them as placeholders. | 271 # to be empty in order to identify them as placeholders. |
270 apk_path = 'lib/%s/%s' % (options.android_abi, name) | 272 apk_path = 'lib/%s/%s' % (options.android_abi, name) |
271 build_utils.AddToZipHermetic(out_apk, apk_path, data='') | 273 build_utils.AddToZipHermetic(out_apk, apk_path, data='') |
272 | 274 |
273 # 5. Resources | 275 # 5. Resources |
274 for info in resource_infos[1:]: | 276 for info in resource_infos[1:]: |
275 copy_resource(info) | 277 copy_resource(info) |
276 | 278 |
277 # 6. Java resources. Used only when coverage is enabled, so order | 279 # 6. Java resources that should be accessible via |
278 # doesn't matter). | 280 # Class.getResourceAsStream(), in particular parts of Emma jar. |
279 if options.emma_device_jar: | 281 # Prebuilt jars may contain class files which we shouldn't include. |
280 # Add EMMA Java resources to APK. | 282 for java_resource in options.java_resources: |
281 with zipfile.ZipFile(options.emma_device_jar, 'r') as emma_device_jar: | 283 with zipfile.ZipFile(java_resource, 'r') as java_resource_jar: |
282 for apk_path in emma_device_jar.namelist(): | 284 for apk_path in java_resource_jar.namelist(): |
283 apk_path_lower = apk_path.lower() | 285 apk_path_lower = apk_path.lower() |
| 286 |
284 if apk_path_lower.startswith('meta-inf/'): | 287 if apk_path_lower.startswith('meta-inf/'): |
285 continue | 288 continue |
286 | |
287 if apk_path_lower.endswith('/'): | 289 if apk_path_lower.endswith('/'): |
288 continue | 290 continue |
289 | |
290 if apk_path_lower.endswith('.class'): | 291 if apk_path_lower.endswith('.class'): |
291 continue | 292 continue |
292 | 293 |
293 build_utils.AddToZipHermetic(out_apk, apk_path, | 294 build_utils.AddToZipHermetic( |
294 data=emma_device_jar.read(apk_path)) | 295 out_apk, apk_path, data=java_resource_jar.read(apk_path)) |
295 | 296 |
296 shutil.move(tmp_apk, options.output_apk) | 297 shutil.move(tmp_apk, options.output_apk) |
297 finally: | 298 finally: |
298 if os.path.exists(tmp_apk): | 299 if os.path.exists(tmp_apk): |
299 os.unlink(tmp_apk) | 300 os.unlink(tmp_apk) |
300 | 301 |
301 build_utils.CallAndWriteDepfileIfStale( | 302 build_utils.CallAndWriteDepfileIfStale( |
302 on_stale_md5, | 303 on_stale_md5, |
303 options, | 304 options, |
304 input_paths=input_paths, | 305 input_paths=input_paths, |
305 input_strings=input_strings, | 306 input_strings=input_strings, |
306 output_paths=[options.output_apk], | 307 output_paths=[options.output_apk], |
307 depfile_deps=depfile_deps) | 308 depfile_deps=depfile_deps) |
308 | 309 |
309 | 310 |
310 if __name__ == '__main__': | 311 if __name__ == '__main__': |
311 main(sys.argv[1:]) | 312 main(sys.argv[1:]) |
OLD | NEW |