Chromium Code Reviews| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 return self.manifest.getAttribute('package') | 74 return self.manifest.getAttribute('package') |
| 75 | 75 |
| 76 | 76 |
| 77 dep_config_cache = {} | 77 dep_config_cache = {} |
| 78 def GetDepConfig(path): | 78 def GetDepConfig(path): |
| 79 if not path in dep_config_cache: | 79 if not path in dep_config_cache: |
| 80 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] | 80 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] |
| 81 return dep_config_cache[path] | 81 return dep_config_cache[path] |
| 82 | 82 |
| 83 | 83 |
| 84 config_cache = {} | |
| 85 def GetConfig(path): | |
| 86 if not path in config_cache: | |
| 87 config_cache[path] = build_utils.ReadJson(path) | |
| 88 return config_cache[path] | |
| 89 | |
| 90 | |
| 84 def DepsOfType(wanted_type, configs): | 91 def DepsOfType(wanted_type, configs): |
| 85 return [c for c in configs if c['type'] == wanted_type] | 92 return [c for c in configs if c['type'] == wanted_type] |
| 86 | 93 |
| 87 | 94 |
| 88 def GetAllDepsConfigsInOrder(deps_config_paths): | 95 def GetAllDepsConfigsInOrder(deps_config_paths): |
| 89 def GetDeps(path): | 96 def GetDeps(path): |
| 90 return set(GetDepConfig(path)['deps_configs']) | 97 return set(GetDepConfig(path)['deps_configs']) |
| 91 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, GetDeps) | 98 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, GetDeps) |
| 92 | 99 |
| 93 | 100 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 parser.add_option('--apk-path', help='Path to the target\'s apk output.') | 273 parser.add_option('--apk-path', help='Path to the target\'s apk output.') |
| 267 parser.add_option('--incremental-apk-path', | 274 parser.add_option('--incremental-apk-path', |
| 268 help="Path to the target's incremental apk output.") | 275 help="Path to the target's incremental apk output.") |
| 269 parser.add_option('--incremental-install-script-path', | 276 parser.add_option('--incremental-install-script-path', |
| 270 help="Path to the target's generated incremental install " | 277 help="Path to the target's generated incremental install " |
| 271 "script.") | 278 "script.") |
| 272 | 279 |
| 273 parser.add_option('--tested-apk-config', | 280 parser.add_option('--tested-apk-config', |
| 274 help='Path to the build config of the tested apk (for an instrumentation ' | 281 help='Path to the build config of the tested apk (for an instrumentation ' |
| 275 'test apk).') | 282 'test apk).') |
| 283 parser.add_option('--merge-tested-apk', action='store_true', | |
| 284 help='Whether to merge the test apk and tested apk into one.') | |
|
agrieve
2016/07/28 01:30:57
nit: "Whether to add all jars from test-apk-config
smaier
2016/07/28 15:27:18
Done.
| |
| 276 parser.add_option('--proguard-enabled', action='store_true', | 285 parser.add_option('--proguard-enabled', action='store_true', |
| 277 help='Whether proguard is enabled for this apk.') | 286 help='Whether proguard is enabled for this apk.') |
| 278 parser.add_option('--proguard-info', | 287 parser.add_option('--proguard-info', |
| 279 help='Path to the proguard .info output for this apk.') | 288 help='Path to the proguard .info output for this apk.') |
| 280 parser.add_option('--has-alternative-locale-resource', action='store_true', | 289 parser.add_option('--has-alternative-locale-resource', action='store_true', |
| 281 help='Whether there is alternative-locale-resource in direct deps') | 290 help='Whether there is alternative-locale-resource in direct deps') |
| 282 | 291 |
| 283 options, args = parser.parse_args(argv) | 292 options, args = parser.parse_args(argv) |
| 284 | 293 |
| 285 if args: | 294 if args: |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 if options.type in ['android_apk', 'deps_dex']: | 523 if options.type in ['android_apk', 'deps_dex']: |
| 515 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 524 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
| 516 | 525 |
| 517 if options.type in ('java_binary', 'java_library', 'android_apk'): | 526 if options.type in ('java_binary', 'java_library', 'android_apk'): |
| 518 javac_classpath = [c['jar_path'] for c in direct_library_deps] | 527 javac_classpath = [c['jar_path'] for c in direct_library_deps] |
| 519 java_full_classpath = [c['jar_path'] for c in all_library_deps] | 528 java_full_classpath = [c['jar_path'] for c in all_library_deps] |
| 520 | 529 |
| 521 # An instrumentation test apk should exclude the dex files that are in the apk | 530 # An instrumentation test apk should exclude the dex files that are in the apk |
| 522 # under test. | 531 # under test. |
| 523 if options.type == 'android_apk' and options.tested_apk_config: | 532 if options.type == 'android_apk' and options.tested_apk_config: |
| 524 tested_apk_config = GetDepConfig(options.tested_apk_config) | 533 tested_apk_config = GetConfig(options.tested_apk_config) |
|
agrieve
2016/07/28 01:30:57
rather than expose the top-level config, we should
smaier
2016/07/28 15:27:18
Done.
| |
| 534 tested_apk_dep_config = GetDepConfig(options.tested_apk_config) | |
| 525 | 535 |
| 526 expected_tested_package = tested_apk_config['package_name'] | 536 expected_tested_package = tested_apk_dep_config['package_name'] |
| 527 AndroidManifest(options.android_manifest).CheckInstrumentation( | 537 AndroidManifest(options.android_manifest).CheckInstrumentation( |
| 528 expected_tested_package) | 538 expected_tested_package) |
| 529 if tested_apk_config['proguard_enabled']: | 539 if options.merge_tested_apk: |
| 540 # Add all tested classes to the test's classpath to ensure that the test's | |
| 541 # java code is a superset of the tested apk's java code | |
| 542 java_full_classpath += [ | |
| 543 jar for jar in tested_apk_config['java']['full_classpath'] | |
| 544 if jar not in java_full_classpath] | |
| 545 | |
| 546 # Include in the classpath classes that are added directly to the apk under | |
| 547 # test (those that are not a part of a java_library). | |
| 548 javac_classpath.append(tested_apk_dep_config['jar_path']) | |
| 549 java_full_classpath.append(tested_apk_dep_config['jar_path']) | |
| 550 | |
| 551 if tested_apk_dep_config['proguard_enabled']: | |
| 530 assert options.proguard_enabled, ('proguard must be enabled for ' | 552 assert options.proguard_enabled, ('proguard must be enabled for ' |
| 531 'instrumentation apks if it\'s enabled for the tested apk.') | 553 'instrumentation apks if it\'s enabled for the tested apk.') |
| 532 | 554 |
| 533 # Include in the classpath classes that are added directly to the apk under | |
| 534 # test (those that are not a part of a java_library). | |
| 535 javac_classpath.append(tested_apk_config['jar_path']) | |
| 536 java_full_classpath.append(tested_apk_config['jar_path']) | |
| 537 | 555 |
| 538 # Exclude dex files from the test apk that exist within the apk under test. | 556 # Exclude dex files from the test apk that exist within the apk under test. |
| 539 # TODO(agrieve): When proguard is enabled, this filtering logic happens | 557 # TODO(agrieve): When proguard is enabled, this filtering logic happens |
| 540 # within proguard_util.py. Move the logic for the proguard case into | 558 # within proguard_util.py. Move the logic for the proguard case into |
| 541 # here as well. | 559 # here as well. |
| 542 tested_apk_library_deps = tested_apk_deps.All('java_library') | 560 tested_apk_library_deps = tested_apk_deps.All('java_library') |
| 543 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 561 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
| 544 deps_dex_files = [ | 562 deps_dex_files = [ |
| 545 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 563 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
| 546 | 564 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 _MergeAssets(deps.All('android_assets'))) | 617 _MergeAssets(deps.All('android_assets'))) |
| 600 | 618 |
| 601 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 619 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 602 | 620 |
| 603 if options.depfile: | 621 if options.depfile: |
| 604 build_utils.WriteDepfile(options.depfile, all_inputs) | 622 build_utils.WriteDepfile(options.depfile, all_inputs) |
| 605 | 623 |
| 606 | 624 |
| 607 if __name__ == '__main__': | 625 if __name__ == '__main__': |
| 608 sys.exit(main(sys.argv[1:])) | 626 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |