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 21 matching lines...) Expand all Loading... | |
| 32 import sys | 32 import sys |
| 33 import xml.dom.minidom | 33 import xml.dom.minidom |
| 34 | 34 |
| 35 from util import build_utils | 35 from util import build_utils |
| 36 from util import md5_check | 36 from util import md5_check |
| 37 | 37 |
| 38 import write_ordered_libraries | 38 import write_ordered_libraries |
| 39 | 39 |
| 40 | 40 |
| 41 # Types that should never be used as a dependency of another build config. | 41 # Types that should never be used as a dependency of another build config. |
| 42 _ROOT_TYPES = ('android_apk', 'deps_dex', 'java_binary', 'resource_rewriter') | 42 _ROOT_TYPES = ('android_apk', 'deps_dex', 'java_binary', 'resource_rewriter', |
| 43 'android_aar') | |
| 43 # Types that should not allow code deps to pass through. | 44 # Types that should not allow code deps to pass through. |
| 44 _RESOURCE_TYPES = ('android_assets', 'android_resources') | 45 _RESOURCE_TYPES = ('android_assets', 'android_resources', 'android_aar') |
|
agrieve
2016/06/16 02:00:04
aar matches the name here, but not the comment. Th
| |
| 45 | 46 |
| 46 | 47 |
| 47 class AndroidManifest(object): | 48 class AndroidManifest(object): |
| 48 def __init__(self, path): | 49 def __init__(self, path): |
| 49 self.path = path | 50 self.path = path |
| 50 dom = xml.dom.minidom.parse(path) | 51 dom = xml.dom.minidom.parse(path) |
| 51 manifests = dom.getElementsByTagName('manifest') | 52 manifests = dom.getElementsByTagName('manifest') |
| 52 assert len(manifests) == 1 | 53 assert len(manifests) == 1 |
| 53 self.manifest = manifests[0] | 54 self.manifest = manifests[0] |
| 54 | 55 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 self.all_deps_configs = [ | 114 self.all_deps_configs = [ |
| 114 GetDepConfig(p) for p in self.all_deps_config_paths] | 115 GetDepConfig(p) for p in self.all_deps_config_paths] |
| 115 self.direct_deps_config_paths = direct_deps_config_paths | 116 self.direct_deps_config_paths = direct_deps_config_paths |
| 116 | 117 |
| 117 def All(self, wanted_type=None): | 118 def All(self, wanted_type=None): |
| 118 if type is None: | 119 if type is None: |
| 119 return self.all_deps_configs | 120 return self.all_deps_configs |
| 120 return DepsOfType(wanted_type, self.all_deps_configs) | 121 return DepsOfType(wanted_type, self.all_deps_configs) |
| 121 | 122 |
| 122 def Direct(self, wanted_type=None): | 123 def Direct(self, wanted_type=None): |
| 124 additional_deps = [] | |
| 123 if wanted_type is None: | 125 if wanted_type is None: |
| 124 return self.direct_deps_configs | 126 return self.direct_deps_configs |
| 125 return DepsOfType(wanted_type, self.direct_deps_configs) | 127 if wanted_type in ['java_library', 'android_resources']: |
|
agrieve
2016/06/16 02:00:03
an android_aar may or may not have resources / ass
| |
| 128 additional_deps = DepsOfType('android_aar', self.direct_deps_configs) | |
| 129 return additional_deps + DepsOfType(wanted_type, self.direct_deps_configs) | |
| 126 | 130 |
| 127 def AllConfigPaths(self): | 131 def AllConfigPaths(self): |
| 128 return self.all_deps_config_paths | 132 return self.all_deps_config_paths |
| 129 | 133 |
| 130 def RemoveNonDirectDep(self, path): | 134 def RemoveNonDirectDep(self, path): |
| 131 if path in self.direct_deps_config_paths: | 135 if path in self.direct_deps_config_paths: |
| 132 raise Exception('Cannot remove direct dep.') | 136 raise Exception('Cannot remove direct dep.') |
| 133 self.all_deps_config_paths.remove(path) | 137 self.all_deps_config_paths.remove(path) |
| 134 self.all_deps_configs.remove(GetDepConfig(path)) | 138 self.all_deps_configs.remove(GetDepConfig(path)) |
| 135 | 139 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 | 255 |
| 252 if args: | 256 if args: |
| 253 parser.error('No positional arguments should be given.') | 257 parser.error('No positional arguments should be given.') |
| 254 | 258 |
| 255 required_options_map = { | 259 required_options_map = { |
| 256 'java_binary': ['build_config', 'jar_path'], | 260 'java_binary': ['build_config', 'jar_path'], |
| 257 'java_library': ['build_config', 'jar_path'], | 261 'java_library': ['build_config', 'jar_path'], |
| 258 'android_assets': ['build_config'], | 262 'android_assets': ['build_config'], |
| 259 'android_resources': ['build_config', 'resources_zip'], | 263 'android_resources': ['build_config', 'resources_zip'], |
| 260 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], | 264 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], |
| 265 'android_aar': ['build_config', 'jar_path', 'resources_zip'], | |
| 261 'deps_dex': ['build_config', 'dex_path'], | 266 'deps_dex': ['build_config', 'dex_path'], |
| 262 'resource_rewriter': ['build_config'], | 267 'resource_rewriter': ['build_config'], |
| 263 'group': ['build_config'], | 268 'group': ['build_config'], |
| 264 } | 269 } |
| 265 required_options = required_options_map.get(options.type) | 270 required_options = required_options_map.get(options.type) |
| 266 if not required_options: | 271 if not required_options: |
| 267 raise Exception('Unknown type: <%s>' % options.type) | 272 raise Exception('Unknown type: <%s>' % options.type) |
| 268 | 273 |
| 269 if options.native_libs: | 274 if options.native_libs: |
| 270 required_options.append('readelf_path') | 275 required_options.append('readelf_path') |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 config = { | 332 config = { |
| 328 'deps_info': { | 333 'deps_info': { |
| 329 'name': os.path.basename(options.build_config), | 334 'name': os.path.basename(options.build_config), |
| 330 'path': options.build_config, | 335 'path': options.build_config, |
| 331 'type': options.type, | 336 'type': options.type, |
| 332 'deps_configs': direct_deps_config_paths | 337 'deps_configs': direct_deps_config_paths |
| 333 } | 338 } |
| 334 } | 339 } |
| 335 deps_info = config['deps_info'] | 340 deps_info = config['deps_info'] |
| 336 | 341 |
| 337 if (options.type in ('java_binary', 'java_library') and | 342 if (options.type in ('java_binary', 'java_library', 'android_aar') and |
| 338 not options.bypass_platform_checks): | 343 not options.bypass_platform_checks): |
| 339 deps_info['requires_android'] = options.requires_android | 344 deps_info['requires_android'] = options.requires_android |
| 340 deps_info['supports_android'] = options.supports_android | 345 deps_info['supports_android'] = options.supports_android |
| 341 | 346 |
| 342 deps_require_android = (all_resources_deps + | 347 deps_require_android = (all_resources_deps + |
| 343 [d['name'] for d in all_library_deps if d['requires_android']]) | 348 [d['name'] for d in all_library_deps if d['requires_android']]) |
| 344 deps_not_support_android = ( | 349 deps_not_support_android = ( |
| 345 [d['name'] for d in all_library_deps if not d['supports_android']]) | 350 [d['name'] for d in all_library_deps if not d['supports_android']]) |
| 346 | 351 |
| 347 if deps_require_android and not options.requires_android: | 352 if deps_require_android and not options.requires_android: |
| 348 raise Exception('Some deps require building for the Android platform: ' + | 353 raise Exception('Some deps require building for the Android platform: ' + |
| 349 str(deps_require_android)) | 354 str(deps_require_android)) |
| 350 | 355 |
| 351 if deps_not_support_android and options.supports_android: | 356 if deps_not_support_android and options.supports_android: |
| 352 raise Exception('Not all deps support the Android platform: ' + | 357 raise Exception('Not all deps support the Android platform: ' + |
| 353 str(deps_not_support_android)) | 358 str(deps_not_support_android)) |
| 354 | 359 |
| 355 if options.type in ('java_binary', 'java_library', 'android_apk'): | 360 if options.type in ('java_binary', 'java_library', 'android_apk', |
| 361 'android_aar'): | |
| 356 javac_classpath = [c['jar_path'] for c in direct_library_deps] | 362 javac_classpath = [c['jar_path'] for c in direct_library_deps] |
| 357 java_full_classpath = [c['jar_path'] for c in all_library_deps] | 363 java_full_classpath = [c['jar_path'] for c in all_library_deps] |
| 358 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] | 364 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] |
| 359 deps_info['jar_path'] = options.jar_path | 365 deps_info['jar_path'] = options.jar_path |
| 360 if options.type == 'android_apk' or options.supports_android: | 366 if options.type == 'android_apk' or options.supports_android: |
| 361 deps_info['dex_path'] = options.dex_path | 367 deps_info['dex_path'] = options.dex_path |
| 362 if options.type == 'android_apk': | 368 if options.type == 'android_apk': |
| 363 deps_info['apk_path'] = options.apk_path | 369 deps_info['apk_path'] = options.apk_path |
| 364 deps_info['incremental_apk_path'] = options.incremental_apk_path | 370 deps_info['incremental_apk_path'] = options.incremental_apk_path |
| 365 deps_info['incremental_install_script_path'] = ( | 371 deps_info['incremental_install_script_path'] = ( |
| 366 options.incremental_install_script_path) | 372 options.incremental_install_script_path) |
| 367 | 373 |
| 368 # Classpath values filled in below (after applying tested_apk_config). | 374 # Classpath values filled in below (after applying tested_apk_config). |
| 369 config['javac'] = {} | 375 config['javac'] = {} |
| 370 | 376 |
| 371 if options.type in ('java_binary', 'java_library'): | 377 if options.type in ('java_binary', 'java_library', 'android_aar'): |
| 372 # Only resources might have srcjars (normal srcjar targets are listed in | 378 # Only resources might have srcjars (normal srcjar targets are listed in |
| 373 # srcjar_deps). A resource's srcjar contains the R.java file for those | 379 # srcjar_deps). A resource's srcjar contains the R.java file for those |
| 374 # resources, and (like Android's default build system) we allow a library to | 380 # resources, and (like Android's default build system) we allow a library to |
| 375 # refer to the resources in any of its dependents. | 381 # refer to the resources in any of its dependents. |
| 376 config['javac']['srcjars'] = [ | 382 config['javac']['srcjars'] = [ |
| 377 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c] | 383 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c] |
| 378 | 384 |
| 379 # Used to strip out R.class for android_prebuilt()s. | 385 # Used to strip out R.class for android_prebuilt()s. |
| 380 if options.type == 'java_library': | 386 if options.type in ('java_library', 'android_aar'): |
| 381 config['javac']['resource_packages'] = [ | 387 config['javac']['resource_packages'] = [ |
| 382 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 388 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
| 383 | 389 |
| 384 if options.type == 'android_apk': | 390 if options.type == 'android_apk': |
| 385 # Apks will get their resources srcjar explicitly passed to the java step. | 391 # Apks will get their resources srcjar explicitly passed to the java step. |
| 386 config['javac']['srcjars'] = [] | 392 config['javac']['srcjars'] = [] |
| 387 | 393 |
| 388 if options.type == 'android_assets': | 394 if options.type == 'android_assets': |
|
agrieve
2016/06/16 02:00:03
might want to add a TODO for allowing aars with as
| |
| 389 all_asset_sources = [] | 395 all_asset_sources = [] |
| 390 if options.asset_renaming_sources: | 396 if options.asset_renaming_sources: |
| 391 all_asset_sources.extend( | 397 all_asset_sources.extend( |
| 392 build_utils.ParseGypList(options.asset_renaming_sources)) | 398 build_utils.ParseGypList(options.asset_renaming_sources)) |
| 393 if options.asset_sources: | 399 if options.asset_sources: |
| 394 all_asset_sources.extend(build_utils.ParseGypList(options.asset_sources)) | 400 all_asset_sources.extend(build_utils.ParseGypList(options.asset_sources)) |
| 395 | 401 |
| 396 deps_info['assets'] = { | 402 deps_info['assets'] = { |
| 397 'sources': all_asset_sources | 403 'sources': all_asset_sources |
| 398 } | 404 } |
| 399 if options.asset_renaming_destinations: | 405 if options.asset_renaming_destinations: |
| 400 deps_info['assets']['outputs'] = ( | 406 deps_info['assets']['outputs'] = ( |
| 401 build_utils.ParseGypList(options.asset_renaming_destinations)) | 407 build_utils.ParseGypList(options.asset_renaming_destinations)) |
| 402 if options.disable_asset_compression: | 408 if options.disable_asset_compression: |
| 403 deps_info['assets']['disable_compression'] = True | 409 deps_info['assets']['disable_compression'] = True |
| 404 | 410 |
| 405 if options.type == 'android_resources': | 411 if options.type in ('android_resources', 'android_aar'): |
|
agrieve
2016/06/16 02:00:03
Should probably update package_resources.py to not
| |
| 406 deps_info['resources_zip'] = options.resources_zip | 412 deps_info['resources_zip'] = options.resources_zip |
| 407 if options.srcjar: | 413 if options.srcjar: |
| 408 deps_info['srcjar'] = options.srcjar | 414 deps_info['srcjar'] = options.srcjar |
| 409 if options.android_manifest: | 415 if options.android_manifest: |
|
agrieve
2016/06/16 02:00:03
I think you want to pass this flag as well from th
| |
| 410 manifest = AndroidManifest(options.android_manifest) | 416 manifest = AndroidManifest(options.android_manifest) |
| 411 deps_info['package_name'] = manifest.GetPackageName() | 417 deps_info['package_name'] = manifest.GetPackageName() |
| 412 if options.package_name: | 418 if options.package_name: |
| 413 deps_info['package_name'] = options.package_name | 419 deps_info['package_name'] = options.package_name |
| 414 if options.r_text: | 420 if options.r_text: |
|
agrieve
2016/06/16 02:00:03
Is this being set for aar?
| |
| 415 deps_info['r_text'] = options.r_text | 421 deps_info['r_text'] = options.r_text |
| 416 if options.is_locale_resource: | 422 if options.is_locale_resource: |
| 417 deps_info['is_locale_resource'] = True | 423 deps_info['is_locale_resource'] = True |
| 418 | 424 |
| 419 if options.type in ('android_resources','android_apk', 'resource_rewriter'): | 425 if options.type in ('android_resources', 'android_apk', 'resource_rewriter', |
| 426 'android_aar'): | |
| 420 config['resources'] = {} | 427 config['resources'] = {} |
| 421 config['resources']['dependency_zips'] = [ | 428 config['resources']['dependency_zips'] = [ |
| 422 c['resources_zip'] for c in all_resources_deps] | 429 c['resources_zip'] for c in all_resources_deps] |
| 423 config['resources']['extra_package_names'] = [] | 430 config['resources']['extra_package_names'] = [] |
| 424 config['resources']['extra_r_text_files'] = [] | 431 config['resources']['extra_r_text_files'] = [] |
| 425 | 432 |
| 426 if options.type == 'android_apk' or options.type == 'resource_rewriter': | 433 if options.type == 'android_apk' or options.type == 'resource_rewriter': |
| 427 config['resources']['extra_package_names'] = [ | 434 config['resources']['extra_package_names'] = [ |
| 428 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 435 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
| 429 config['resources']['extra_r_text_files'] = [ | 436 config['resources']['extra_r_text_files'] = [ |
| 430 c['r_text'] for c in all_resources_deps if 'r_text' in c] | 437 c['r_text'] for c in all_resources_deps if 'r_text' in c] |
| 431 | 438 |
| 432 if options.type in ['android_apk', 'deps_dex']: | 439 if options.type in ['android_apk', 'deps_dex']: |
| 433 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 440 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
| 434 | 441 |
| 435 proguard_enabled = options.proguard_enabled | 442 proguard_enabled = options.proguard_enabled |
| 436 if options.type == 'android_apk': | 443 if options.type == 'android_apk': |
| 437 deps_info['proguard_enabled'] = proguard_enabled | 444 deps_info['proguard_enabled'] = proguard_enabled |
| 438 | 445 |
| 439 if proguard_enabled: | 446 if proguard_enabled: |
| 440 deps_info['proguard_info'] = options.proguard_info | 447 deps_info['proguard_info'] = options.proguard_info |
| 441 config['proguard'] = {} | 448 config['proguard'] = {} |
| 442 proguard_config = config['proguard'] | 449 proguard_config = config['proguard'] |
| 443 proguard_config['input_paths'] = [options.jar_path] + java_full_classpath | 450 proguard_config['input_paths'] = [options.jar_path] + java_full_classpath |
|
agrieve
2016/06/16 02:00:03
Might want to add a TODO here to support adding th
| |
| 444 | 451 |
| 445 # An instrumentation test apk should exclude the dex files that are in the apk | 452 # An instrumentation test apk should exclude the dex files that are in the apk |
| 446 # under test. | 453 # under test. |
| 447 if options.type == 'android_apk' and options.tested_apk_config: | 454 if options.type == 'android_apk' and options.tested_apk_config: |
| 448 tested_apk_library_deps = tested_apk_deps.All('java_library') | 455 tested_apk_library_deps = tested_apk_deps.All('java_library') |
| 449 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 456 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
| 450 # Include in the classpath classes that are added directly to the apk under | 457 # Include in the classpath classes that are added directly to the apk under |
| 451 # test (those that are not a part of a java_library). | 458 # test (those that are not a part of a java_library). |
| 452 tested_apk_config = GetDepConfig(options.tested_apk_config) | 459 tested_apk_config = GetDepConfig(options.tested_apk_config) |
| 453 javac_classpath.append(tested_apk_config['jar_path']) | 460 javac_classpath.append(tested_apk_config['jar_path']) |
| 454 # Exclude dex files from the test apk that exist within the apk under test. | 461 # Exclude dex files from the test apk that exist within the apk under test. |
| 455 deps_dex_files = [ | 462 deps_dex_files = [ |
| 456 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 463 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
| 457 | 464 |
| 458 expected_tested_package = tested_apk_config['package_name'] | 465 expected_tested_package = tested_apk_config['package_name'] |
| 459 AndroidManifest(options.android_manifest).CheckInstrumentation( | 466 AndroidManifest(options.android_manifest).CheckInstrumentation( |
| 460 expected_tested_package) | 467 expected_tested_package) |
| 461 if tested_apk_config['proguard_enabled']: | 468 if tested_apk_config['proguard_enabled']: |
| 462 assert proguard_enabled, ('proguard must be enabled for instrumentation' | 469 assert proguard_enabled, ('proguard must be enabled for instrumentation' |
| 463 ' apks if it\'s enabled for the tested apk') | 470 ' apks if it\'s enabled for the tested apk') |
| 464 | 471 |
| 465 # Dependencies for the final dex file of an apk or a 'deps_dex'. | 472 # Dependencies for the final dex file of an apk or a 'deps_dex'. |
| 466 if options.type in ['android_apk', 'deps_dex']: | 473 if options.type in ['android_apk', 'deps_dex']: |
| 467 config['final_dex'] = {} | 474 config['final_dex'] = {} |
| 468 dex_config = config['final_dex'] | 475 dex_config = config['final_dex'] |
| 469 dex_config['dependency_dex_files'] = deps_dex_files | 476 dex_config['dependency_dex_files'] = deps_dex_files |
| 470 | 477 |
| 471 if options.type in ('java_binary', 'java_library', 'android_apk'): | 478 if options.type in ('java_binary', 'java_library', 'android_apk', |
| 479 'android_aar'): | |
| 472 config['javac']['classpath'] = javac_classpath | 480 config['javac']['classpath'] = javac_classpath |
| 473 config['javac']['interface_classpath'] = [ | 481 config['javac']['interface_classpath'] = [ |
| 474 _AsInterfaceJar(p) for p in javac_classpath] | 482 _AsInterfaceJar(p) for p in javac_classpath] |
| 475 config['java'] = { | 483 config['java'] = { |
| 476 'full_classpath': java_full_classpath | 484 'full_classpath': java_full_classpath |
| 477 } | 485 } |
| 478 | 486 |
| 479 if options.type == 'android_apk': | 487 if options.type == 'android_apk': |
| 480 dependency_jars = [c['jar_path'] for c in all_library_deps] | 488 dependency_jars = [c['jar_path'] for c in all_library_deps] |
| 481 all_interface_jars = [ | 489 all_interface_jars = [ |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 _MergeAssets(deps.All('android_assets'))) | 538 _MergeAssets(deps.All('android_assets'))) |
| 531 | 539 |
| 532 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 540 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 533 | 541 |
| 534 if options.depfile: | 542 if options.depfile: |
| 535 build_utils.WriteDepfile(options.depfile, all_inputs) | 543 build_utils.WriteDepfile(options.depfile, all_inputs) |
| 536 | 544 |
| 537 | 545 |
| 538 if __name__ == '__main__': | 546 if __name__ == '__main__': |
| 539 sys.exit(main(sys.argv[1:])) | 547 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |