| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 285 |
| 282 if options.type == 'android_apk': | 286 if options.type == 'android_apk': |
| 283 config['resources']['extra_package_names'] = [ | 287 config['resources']['extra_package_names'] = [ |
| 284 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 288 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
| 285 config['resources']['extra_r_text_files'] = [ | 289 config['resources']['extra_r_text_files'] = [ |
| 286 c['r_text'] for c in all_resources_deps if 'r_text' in c] | 290 c['r_text'] for c in all_resources_deps if 'r_text' in c] |
| 287 | 291 |
| 288 if options.type in ['android_apk', 'deps_dex']: | 292 if options.type in ['android_apk', 'deps_dex']: |
| 289 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 293 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
| 290 | 294 |
| 295 proguard_enabled = options.proguard_enabled |
| 296 if options.type == 'android_apk': |
| 297 deps_info['proguard_enabled'] = proguard_enabled |
| 298 if proguard_enabled: |
| 299 deps_info['proguard_info'] = options.proguard_info |
| 300 config['proguard'] = {} |
| 301 proguard_config = config['proguard'] |
| 302 proguard_config['input_paths'] = [options.jar_path] + java_full_classpath |
| 303 proguard_config['tested_apk_info'] = '' |
| 304 |
| 305 |
| 291 # An instrumentation test apk should exclude the dex files that are in the apk | 306 # An instrumentation test apk should exclude the dex files that are in the apk |
| 292 # under test. | 307 # under test. |
| 293 if options.type == 'android_apk' and options.tested_apk_config: | 308 if options.type == 'android_apk' and options.tested_apk_config: |
| 294 tested_apk_deps = Deps([options.tested_apk_config]) | 309 tested_apk_deps = Deps([options.tested_apk_config]) |
| 295 tested_apk_library_deps = tested_apk_deps.All('java_library') | 310 tested_apk_library_deps = tested_apk_deps.All('java_library') |
| 296 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 311 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
| 297 deps_dex_files = [ | 312 deps_dex_files = [ |
| 298 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 313 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
| 299 | 314 |
| 300 tested_apk_config = GetDepConfig(options.tested_apk_config) | 315 tested_apk_config = GetDepConfig(options.tested_apk_config) |
| 301 expected_tested_package = tested_apk_config['package_name'] | 316 expected_tested_package = tested_apk_config['package_name'] |
| 302 AndroidManifest(options.android_manifest).CheckInstrumentation( | 317 AndroidManifest(options.android_manifest).CheckInstrumentation( |
| 303 expected_tested_package) | 318 expected_tested_package) |
| 319 if tested_apk_config['proguard_enabled']: |
| 320 proguard_config['tested_apk_info'] = tested_apk_config['proguard_info'] |
| 321 assert proguard_enabled, ('proguard must be enabled for instrumentation' |
| 322 ' apks if it\'s enabled for the tested apk') |
| 323 |
| 324 |
| 304 | 325 |
| 305 # Dependencies for the final dex file of an apk or a 'deps_dex'. | 326 # Dependencies for the final dex file of an apk or a 'deps_dex'. |
| 306 if options.type in ['android_apk', 'deps_dex']: | 327 if options.type in ['android_apk', 'deps_dex']: |
| 307 config['final_dex'] = {} | 328 config['final_dex'] = {} |
| 308 dex_config = config['final_dex'] | 329 dex_config = config['final_dex'] |
| 309 # TODO(cjhopman): proguard version | 330 if proguard_enabled: |
| 331 # When proguard is enabled, the proguarded jar contains the code for all |
| 332 # of the dependencies. |
| 333 deps_dex_files = [] |
| 310 dex_config['dependency_dex_files'] = deps_dex_files | 334 dex_config['dependency_dex_files'] = deps_dex_files |
| 311 | 335 |
| 312 if options.type == 'android_apk': | 336 if options.type == 'android_apk': |
| 313 config['dist_jar'] = { | 337 config['dist_jar'] = { |
| 314 'dependency_jars': [ | 338 'dependency_jars': [ |
| 315 c['jar_path'] for c in all_library_deps | 339 c['jar_path'] for c in all_library_deps |
| 316 ] | 340 ] |
| 317 } | 341 } |
| 318 manifest = AndroidManifest(options.android_manifest) | 342 manifest = AndroidManifest(options.android_manifest) |
| 319 deps_info['package_name'] = manifest.GetPackageName() | 343 deps_info['package_name'] = manifest.GetPackageName() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 347 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 371 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 348 | 372 |
| 349 if options.depfile: | 373 if options.depfile: |
| 350 build_utils.WriteDepfile( | 374 build_utils.WriteDepfile( |
| 351 options.depfile, | 375 options.depfile, |
| 352 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) | 376 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) |
| 353 | 377 |
| 354 | 378 |
| 355 if __name__ == '__main__': | 379 if __name__ == '__main__': |
| 356 sys.exit(main(sys.argv[1:])) | 380 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |