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 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.') | |
| 195 | 199 |
| 196 options, args = parser.parse_args(argv) | 200 options, args = parser.parse_args(argv) |
| 197 | 201 |
| 198 if args: | 202 if args: |
| 199 parser.error('No positional arguments should be given.') | 203 parser.error('No positional arguments should be given.') |
| 200 | 204 |
| 201 required_options_map = { | 205 required_options_map = { |
| 202 'java_library': ['build_config', 'jar_path'], | 206 'java_library': ['build_config', 'jar_path'], |
| 203 'android_assets': ['build_config'], | 207 'android_assets': ['build_config'], |
| 204 'android_resources': ['build_config', 'resources_zip'], | 208 'android_resources': ['build_config', 'resources_zip'], |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 | 348 |
| 345 if options.type == 'android_apk' or options.type == 'resource_rewriter': | 349 if options.type == 'android_apk' or options.type == 'resource_rewriter': |
| 346 config['resources']['extra_package_names'] = [ | 350 config['resources']['extra_package_names'] = [ |
| 347 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 351 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
| 348 config['resources']['extra_r_text_files'] = [ | 352 config['resources']['extra_r_text_files'] = [ |
| 349 c['r_text'] for c in all_resources_deps if 'r_text' in c] | 353 c['r_text'] for c in all_resources_deps if 'r_text' in c] |
| 350 | 354 |
| 351 if options.type in ['android_apk', 'deps_dex']: | 355 if options.type in ['android_apk', 'deps_dex']: |
| 352 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 356 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
| 353 | 357 |
| 358 proguard_enabled = options.proguard_enabled | |
| 359 if options.type == 'android_apk': | |
| 360 deps_info['proguard_enabled'] = proguard_enabled | |
| 361 if proguard_enabled: | |
| 362 deps_info['proguard_info'] = options.proguard_info | |
| 363 config['proguard'] = {} | |
| 364 proguard_config = config['proguard'] | |
| 365 proguard_config['input_paths'] = [options.jar_path] + java_full_classpath | |
| 366 proguard_config['tested_apk_info'] = '' | |
| 367 | |
| 368 | |
| 354 # An instrumentation test apk should exclude the dex files that are in the apk | 369 # An instrumentation test apk should exclude the dex files that are in the apk |
| 355 # under test. | 370 # under test. |
| 356 if options.type == 'android_apk' and options.tested_apk_config: | 371 if options.type == 'android_apk' and options.tested_apk_config: |
| 357 tested_apk_deps = Deps([options.tested_apk_config]) | 372 tested_apk_deps = Deps([options.tested_apk_config]) |
| 358 tested_apk_library_deps = tested_apk_deps.All('java_library') | 373 tested_apk_library_deps = tested_apk_deps.All('java_library') |
| 359 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 374 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
| 360 deps_dex_files = [ | 375 deps_dex_files = [ |
| 361 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 376 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
| 362 | 377 |
| 363 tested_apk_config = GetDepConfig(options.tested_apk_config) | 378 tested_apk_config = GetDepConfig(options.tested_apk_config) |
| 364 expected_tested_package = tested_apk_config['package_name'] | 379 expected_tested_package = tested_apk_config['package_name'] |
| 365 AndroidManifest(options.android_manifest).CheckInstrumentation( | 380 AndroidManifest(options.android_manifest).CheckInstrumentation( |
| 366 expected_tested_package) | 381 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 | |
|
newt (away)
2015/11/11 18:21:33
too many newlines
agrieve
2015/11/11 18:53:45
Done.
| |
| 387 | |
| 367 | 388 |
| 368 # Dependencies for the final dex file of an apk or a 'deps_dex'. | 389 # Dependencies for the final dex file of an apk or a 'deps_dex'. |
| 369 if options.type in ['android_apk', 'deps_dex']: | 390 if options.type in ['android_apk', 'deps_dex']: |
| 370 config['final_dex'] = {} | 391 config['final_dex'] = {} |
| 371 dex_config = config['final_dex'] | 392 dex_config = config['final_dex'] |
| 372 # TODO(cjhopman): proguard version | 393 if proguard_enabled: |
| 394 # When proguard is enabled, the proguarded jar contains the code for all | |
| 395 # of the dependencies. | |
| 396 deps_dex_files = [] | |
| 373 dex_config['dependency_dex_files'] = deps_dex_files | 397 dex_config['dependency_dex_files'] = deps_dex_files |
| 374 | 398 |
| 375 if options.type == 'android_apk': | 399 if options.type == 'android_apk': |
| 376 config['dist_jar'] = { | 400 config['dist_jar'] = { |
| 377 'dependency_jars': [ | 401 'dependency_jars': [ |
| 378 c['jar_path'] for c in all_library_deps | 402 c['jar_path'] for c in all_library_deps |
| 379 ] | 403 ] |
| 380 } | 404 } |
| 381 manifest = AndroidManifest(options.android_manifest) | 405 manifest = AndroidManifest(options.android_manifest) |
| 382 deps_info['package_name'] = manifest.GetPackageName() | 406 deps_info['package_name'] = manifest.GetPackageName() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 449 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 426 | 450 |
| 427 if options.depfile: | 451 if options.depfile: |
| 428 build_utils.WriteDepfile( | 452 build_utils.WriteDepfile( |
| 429 options.depfile, | 453 options.depfile, |
| 430 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) | 454 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) |
| 431 | 455 |
| 432 | 456 |
| 433 if __name__ == '__main__': | 457 if __name__ == '__main__': |
| 434 sys.exit(main(sys.argv[1:])) | 458 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |