| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 # android library options | 185 # android library options |
| 186 parser.add_option('--dex-path', help='Path to target\'s dex output.') | 186 parser.add_option('--dex-path', help='Path to target\'s dex output.') |
| 187 | 187 |
| 188 # native library options | 188 # native library options |
| 189 parser.add_option('--native-libs', help='List of top-level native libs.') | 189 parser.add_option('--native-libs', help='List of top-level native libs.') |
| 190 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') | 190 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') |
| 191 | 191 |
| 192 parser.add_option('--tested-apk-config', | 192 parser.add_option('--tested-apk-config', |
| 193 help='Path to the build config of the tested apk (for an instrumentation ' | 193 help='Path to the build config of the tested apk (for an instrumentation ' |
| 194 'test apk).') | 194 'test apk).') |
| 195 parser.add_option('--proguard-enabled', action='store_true', | |
| 196 help='Whether proguard is enabled for this apk.') | |
| 197 parser.add_option('--proguard-info', | |
| 198 help='Path to the proguard .info output for this apk.') | |
| 199 | 195 |
| 200 options, args = parser.parse_args(argv) | 196 options, args = parser.parse_args(argv) |
| 201 | 197 |
| 202 if args: | 198 if args: |
| 203 parser.error('No positional arguments should be given.') | 199 parser.error('No positional arguments should be given.') |
| 204 | 200 |
| 205 required_options_map = { | 201 required_options_map = { |
| 206 'java_library': ['build_config', 'jar_path'], | 202 'java_library': ['build_config', 'jar_path'], |
| 207 'android_assets': ['build_config'], | 203 'android_assets': ['build_config'], |
| 208 'android_resources': ['build_config', 'resources_zip'], | 204 'android_resources': ['build_config', 'resources_zip'], |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 344 |
| 349 if options.type == 'android_apk' or options.type == 'resource_rewriter': | 345 if options.type == 'android_apk' or options.type == 'resource_rewriter': |
| 350 config['resources']['extra_package_names'] = [ | 346 config['resources']['extra_package_names'] = [ |
| 351 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 347 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
| 352 config['resources']['extra_r_text_files'] = [ | 348 config['resources']['extra_r_text_files'] = [ |
| 353 c['r_text'] for c in all_resources_deps if 'r_text' in c] | 349 c['r_text'] for c in all_resources_deps if 'r_text' in c] |
| 354 | 350 |
| 355 if options.type in ['android_apk', 'deps_dex']: | 351 if options.type in ['android_apk', 'deps_dex']: |
| 356 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 352 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
| 357 | 353 |
| 358 proguard_enabled = options.proguard_enabled | |
| 359 if options.type == 'android_apk': | |
| 360 deps_info['proguard_enabled'] = proguard_enabled | |
| 361 | |
| 362 if proguard_enabled: | |
| 363 deps_info['proguard_info'] = options.proguard_info | |
| 364 config['proguard'] = {} | |
| 365 proguard_config = config['proguard'] | |
| 366 proguard_config['input_paths'] = [options.jar_path] + java_full_classpath | |
| 367 proguard_config['tested_apk_info'] = '' | |
| 368 | |
| 369 # An instrumentation test apk should exclude the dex files that are in the apk | 354 # An instrumentation test apk should exclude the dex files that are in the apk |
| 370 # under test. | 355 # under test. |
| 371 if options.type == 'android_apk' and options.tested_apk_config: | 356 if options.type == 'android_apk' and options.tested_apk_config: |
| 372 tested_apk_deps = Deps([options.tested_apk_config]) | 357 tested_apk_deps = Deps([options.tested_apk_config]) |
| 373 tested_apk_library_deps = tested_apk_deps.All('java_library') | 358 tested_apk_library_deps = tested_apk_deps.All('java_library') |
| 374 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 359 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
| 375 deps_dex_files = [ | 360 deps_dex_files = [ |
| 376 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 361 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
| 377 | 362 |
| 378 tested_apk_config = GetDepConfig(options.tested_apk_config) | 363 tested_apk_config = GetDepConfig(options.tested_apk_config) |
| 379 expected_tested_package = tested_apk_config['package_name'] | 364 expected_tested_package = tested_apk_config['package_name'] |
| 380 AndroidManifest(options.android_manifest).CheckInstrumentation( | 365 AndroidManifest(options.android_manifest).CheckInstrumentation( |
| 381 expected_tested_package) | 366 expected_tested_package) |
| 382 if tested_apk_config['proguard_enabled']: | |
| 383 proguard_config['tested_apk_info'] = tested_apk_config['proguard_info'] | |
| 384 assert proguard_enabled, ('proguard must be enabled for instrumentation' | |
| 385 ' apks if it\'s enabled for the tested apk') | |
| 386 | 367 |
| 387 # Dependencies for the final dex file of an apk or a 'deps_dex'. | 368 # Dependencies for the final dex file of an apk or a 'deps_dex'. |
| 388 if options.type in ['android_apk', 'deps_dex']: | 369 if options.type in ['android_apk', 'deps_dex']: |
| 389 config['final_dex'] = {} | 370 config['final_dex'] = {} |
| 390 dex_config = config['final_dex'] | 371 dex_config = config['final_dex'] |
| 391 if proguard_enabled: | 372 # TODO(cjhopman): proguard version |
| 392 # When proguard is enabled, the proguarded jar contains the code for all | |
| 393 # of the dependencies. | |
| 394 deps_dex_files = [] | |
| 395 dex_config['dependency_dex_files'] = deps_dex_files | 373 dex_config['dependency_dex_files'] = deps_dex_files |
| 396 | 374 |
| 397 if options.type == 'android_apk': | 375 if options.type == 'android_apk': |
| 398 config['dist_jar'] = { | 376 config['dist_jar'] = { |
| 399 'dependency_jars': [ | 377 'dependency_jars': [ |
| 400 c['jar_path'] for c in all_library_deps | 378 c['jar_path'] for c in all_library_deps |
| 401 ] | 379 ] |
| 402 } | 380 } |
| 403 manifest = AndroidManifest(options.android_manifest) | 381 manifest = AndroidManifest(options.android_manifest) |
| 404 deps_info['package_name'] = manifest.GetPackageName() | 382 deps_info['package_name'] = manifest.GetPackageName() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 425 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 448 | 426 |
| 449 if options.depfile: | 427 if options.depfile: |
| 450 build_utils.WriteDepfile( | 428 build_utils.WriteDepfile( |
| 451 options.depfile, | 429 options.depfile, |
| 452 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) | 430 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) |
| 453 | 431 |
| 454 | 432 |
| 455 if __name__ == '__main__': | 433 if __name__ == '__main__': |
| 456 sys.exit(main(sys.argv[1:])) | 434 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |