OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 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 """Writes a build_config file. | 7 """Writes a build_config file. |
8 | 8 |
9 The build_config file for a target is a json file containing information about | 9 The build_config file for a target is a json file containing information about |
10 how to build that target based on the target's dependencies. This includes | 10 how to build that target based on the target's dependencies. This includes |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 # android library options | 140 # android library options |
141 parser.add_option('--dex-path', help='Path to target\'s dex output.') | 141 parser.add_option('--dex-path', help='Path to target\'s dex output.') |
142 | 142 |
143 # native library options | 143 # native library options |
144 parser.add_option('--native-libs', help='List of top-level native libs.') | 144 parser.add_option('--native-libs', help='List of top-level native libs.') |
145 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') | 145 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') |
146 | 146 |
147 parser.add_option('--tested-apk-config', | 147 parser.add_option('--tested-apk-config', |
148 help='Path to the build config of the tested apk (for an instrumentation ' | 148 help='Path to the build config of the tested apk (for an instrumentation ' |
149 'test apk).') | 149 'test apk).') |
| 150 parser.add_option('--proguard-enabled', action='store_true', |
| 151 help='Whether proguard is enabled for this apk.') |
| 152 parser.add_option('--proguard-info', |
| 153 help='Path to the proguard .info output for this apk.') |
150 | 154 |
151 options, args = parser.parse_args(argv) | 155 options, args = parser.parse_args(argv) |
152 | 156 |
153 if args: | 157 if args: |
154 parser.error('No positional arguments should be given.') | 158 parser.error('No positional arguments should be given.') |
155 | 159 |
156 | 160 |
157 if not options.type in [ | 161 if not options.type in [ |
158 'java_library', 'android_resources', 'android_apk', 'deps_dex']: | 162 'java_library', 'android_resources', 'android_apk', 'deps_dex']: |
159 raise Exception('Unknown type: <%s>' % options.type) | 163 raise Exception('Unknown type: <%s>' % options.type) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 286 |
283 if options.type == 'android_apk': | 287 if options.type == 'android_apk': |
284 config['resources']['extra_package_names'] = [ | 288 config['resources']['extra_package_names'] = [ |
285 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 289 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
286 config['resources']['extra_r_text_files'] = [ | 290 config['resources']['extra_r_text_files'] = [ |
287 c['r_text'] for c in all_resources_deps if 'r_text' in c] | 291 c['r_text'] for c in all_resources_deps if 'r_text' in c] |
288 | 292 |
289 if options.type in ['android_apk', 'deps_dex']: | 293 if options.type in ['android_apk', 'deps_dex']: |
290 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 294 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
291 | 295 |
| 296 proguard_enabled = options.proguard_enabled |
| 297 if options.type == 'android_apk': |
| 298 deps_info['proguard_enabled'] = proguard_enabled |
| 299 if proguard_enabled: |
| 300 deps_info['proguard_info'] = options.proguard_info |
| 301 config['proguard'] = {} |
| 302 proguard_config = config['proguard'] |
| 303 proguard_config['input_paths'] = [options.jar_path] + java_full_classpath |
| 304 proguard_config['tested_apk_info'] = '' |
| 305 |
| 306 |
292 # An instrumentation test apk should exclude the dex files that are in the apk | 307 # An instrumentation test apk should exclude the dex files that are in the apk |
293 # under test. | 308 # under test. |
294 if options.type == 'android_apk' and options.tested_apk_config: | 309 if options.type == 'android_apk' and options.tested_apk_config: |
295 tested_apk_deps = Deps([options.tested_apk_config]) | 310 tested_apk_deps = Deps([options.tested_apk_config]) |
296 tested_apk_library_deps = tested_apk_deps.All('java_library') | 311 tested_apk_library_deps = tested_apk_deps.All('java_library') |
297 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 312 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
298 deps_dex_files = [ | 313 deps_dex_files = [ |
299 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 314 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
300 | 315 |
301 tested_apk_config = GetDepConfig(options.tested_apk_config) | 316 tested_apk_config = GetDepConfig(options.tested_apk_config) |
302 expected_tested_package = tested_apk_config['package_name'] | 317 expected_tested_package = tested_apk_config['package_name'] |
303 AndroidManifest(options.android_manifest).CheckInstrumentation( | 318 AndroidManifest(options.android_manifest).CheckInstrumentation( |
304 expected_tested_package) | 319 expected_tested_package) |
| 320 if tested_apk_config['proguard_enabled']: |
| 321 proguard_config['tested_apk_info'] = tested_apk_config['proguard_info'] |
| 322 assert proguard_enabled, ('proguard must be enabled for instrumentation' |
| 323 ' apks if it\'s enabled for the tested apk') |
| 324 |
| 325 |
305 | 326 |
306 # Dependencies for the final dex file of an apk or a 'deps_dex'. | 327 # Dependencies for the final dex file of an apk or a 'deps_dex'. |
307 if options.type in ['android_apk', 'deps_dex']: | 328 if options.type in ['android_apk', 'deps_dex']: |
308 config['final_dex'] = {} | 329 config['final_dex'] = {} |
309 dex_config = config['final_dex'] | 330 dex_config = config['final_dex'] |
310 # TODO(cjhopman): proguard version | 331 if proguard_enabled: |
| 332 # When proguard is enabled, the proguarded jar contains the code for all |
| 333 # of the dependencies. |
| 334 deps_dex_files = [] |
311 dex_config['dependency_dex_files'] = deps_dex_files | 335 dex_config['dependency_dex_files'] = deps_dex_files |
312 | 336 |
313 if options.type == 'android_apk': | 337 if options.type == 'android_apk': |
314 config['dist_jar'] = { | 338 config['dist_jar'] = { |
315 'dependency_jars': [ | 339 'dependency_jars': [ |
316 c['jar_path'] for c in all_library_deps | 340 c['jar_path'] for c in all_library_deps |
317 ] | 341 ] |
318 } | 342 } |
319 manifest = AndroidManifest(options.android_manifest) | 343 manifest = AndroidManifest(options.android_manifest) |
320 deps_info['package_name'] = manifest.GetPackageName() | 344 deps_info['package_name'] = manifest.GetPackageName() |
(...skipping 27 matching lines...) Expand all Loading... |
348 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 372 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
349 | 373 |
350 if options.depfile: | 374 if options.depfile: |
351 build_utils.WriteDepfile( | 375 build_utils.WriteDepfile( |
352 options.depfile, | 376 options.depfile, |
353 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) | 377 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) |
354 | 378 |
355 | 379 |
356 if __name__ == '__main__': | 380 if __name__ == '__main__': |
357 sys.exit(main(sys.argv[1:])) | 381 sys.exit(main(sys.argv[1:])) |
OLD | NEW |