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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 parser.add_option('--has-alternative-locale-resource', action='store_true', | 283 parser.add_option('--has-alternative-locale-resource', action='store_true', |
284 help='Whether there is alternative-locale-resource in direct deps') | 284 help='Whether there is alternative-locale-resource in direct deps') |
285 parser.add_option('--fail', | 285 parser.add_option('--fail', |
286 help='GYP-list of error message lines to fail with.') | 286 help='GYP-list of error message lines to fail with.') |
287 | 287 |
288 options, args = parser.parse_args(argv) | 288 options, args = parser.parse_args(argv) |
289 | 289 |
290 if args: | 290 if args: |
291 parser.error('No positional arguments should be given.') | 291 parser.error('No positional arguments should be given.') |
292 if options.fail: | 292 if options.fail: |
293 parser.error('\n'.join(build_utils.ParseGypList(options.fail))) | 293 parser.error('\n'.join(build_utils.ParseGnList(options.fail))) |
294 | 294 |
295 required_options_map = { | 295 required_options_map = { |
296 'java_binary': ['build_config', 'jar_path'], | 296 'java_binary': ['build_config', 'jar_path'], |
297 'java_library': ['build_config', 'jar_path'], | 297 'java_library': ['build_config', 'jar_path'], |
298 'java_prebuilt': ['build_config', 'jar_path'], | 298 'java_prebuilt': ['build_config', 'jar_path'], |
299 'android_assets': ['build_config'], | 299 'android_assets': ['build_config'], |
300 'android_resources': ['build_config', 'resources_zip'], | 300 'android_resources': ['build_config', 'resources_zip'], |
301 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], | 301 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], |
302 'deps_dex': ['build_config', 'dex_path'], | 302 'deps_dex': ['build_config', 'dex_path'], |
303 'resource_rewriter': ['build_config'], | 303 'resource_rewriter': ['build_config'], |
(...skipping 11 matching lines...) Expand all Loading... |
315 options.type = 'java_library' | 315 options.type = 'java_library' |
316 | 316 |
317 if options.type == 'java_library': | 317 if options.type == 'java_library': |
318 if options.supports_android and not options.dex_path: | 318 if options.supports_android and not options.dex_path: |
319 raise Exception('java_library that supports Android requires a dex path.') | 319 raise Exception('java_library that supports Android requires a dex path.') |
320 | 320 |
321 if options.requires_android and not options.supports_android: | 321 if options.requires_android and not options.supports_android: |
322 raise Exception( | 322 raise Exception( |
323 '--supports-android is required when using --requires-android') | 323 '--supports-android is required when using --requires-android') |
324 | 324 |
325 direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs) | 325 direct_deps_config_paths = build_utils.ParseGnList(options.deps_configs) |
326 direct_deps_config_paths = _FilterDepsPaths(direct_deps_config_paths, | 326 direct_deps_config_paths = _FilterDepsPaths(direct_deps_config_paths, |
327 options.type) | 327 options.type) |
328 | 328 |
329 deps = Deps(direct_deps_config_paths) | 329 deps = Deps(direct_deps_config_paths) |
330 all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies() | 330 all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies() |
331 | 331 |
332 # Remove other locale resources if there is alternative_locale_resource in | 332 # Remove other locale resources if there is alternative_locale_resource in |
333 # direct deps. | 333 # direct deps. |
334 if options.has_alternative_locale_resource: | 334 if options.has_alternative_locale_resource: |
335 alternative = [r['path'] for r in deps.Direct('android_resources') | 335 alternative = [r['path'] for r in deps.Direct('android_resources') |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 if options.type == 'java_library': | 377 if options.type == 'java_library': |
378 deps_info['is_prebuilt'] = is_java_prebuilt | 378 deps_info['is_prebuilt'] = is_java_prebuilt |
379 | 379 |
380 if options.android_manifest: | 380 if options.android_manifest: |
381 gradle['android_manifest'] = options.android_manifest | 381 gradle['android_manifest'] = options.android_manifest |
382 if options.type in ('java_binary', 'java_library', 'android_apk'): | 382 if options.type in ('java_binary', 'java_library', 'android_apk'): |
383 if options.java_sources_file: | 383 if options.java_sources_file: |
384 gradle['java_sources_file'] = options.java_sources_file | 384 gradle['java_sources_file'] = options.java_sources_file |
385 if options.bundled_srcjars: | 385 if options.bundled_srcjars: |
386 gradle['bundled_srcjars'] = ( | 386 gradle['bundled_srcjars'] = ( |
387 build_utils.ParseGypList(options.bundled_srcjars)) | 387 build_utils.ParseGnList(options.bundled_srcjars)) |
388 | 388 |
389 gradle['dependent_prebuilt_jars'] = deps.PrebuiltJarPaths() | 389 gradle['dependent_prebuilt_jars'] = deps.PrebuiltJarPaths() |
390 | 390 |
391 gradle['dependent_android_projects'] = [] | 391 gradle['dependent_android_projects'] = [] |
392 gradle['dependent_java_projects'] = [] | 392 gradle['dependent_java_projects'] = [] |
393 for c in direct_library_deps: | 393 for c in direct_library_deps: |
394 if not c['is_prebuilt']: | 394 if not c['is_prebuilt']: |
395 if c['requires_android']: | 395 if c['requires_android']: |
396 gradle['dependent_android_projects'].append(c['path']) | 396 gradle['dependent_android_projects'].append(c['path']) |
397 else: | 397 else: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 444 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
445 | 445 |
446 if options.type == 'android_apk': | 446 if options.type == 'android_apk': |
447 # Apks will get their resources srcjar explicitly passed to the java step. | 447 # Apks will get their resources srcjar explicitly passed to the java step. |
448 config['javac']['srcjars'] = [] | 448 config['javac']['srcjars'] = [] |
449 | 449 |
450 if options.type == 'android_assets': | 450 if options.type == 'android_assets': |
451 all_asset_sources = [] | 451 all_asset_sources = [] |
452 if options.asset_renaming_sources: | 452 if options.asset_renaming_sources: |
453 all_asset_sources.extend( | 453 all_asset_sources.extend( |
454 build_utils.ParseGypList(options.asset_renaming_sources)) | 454 build_utils.ParseGnList(options.asset_renaming_sources)) |
455 if options.asset_sources: | 455 if options.asset_sources: |
456 all_asset_sources.extend(build_utils.ParseGypList(options.asset_sources)) | 456 all_asset_sources.extend(build_utils.ParseGnList(options.asset_sources)) |
457 | 457 |
458 deps_info['assets'] = { | 458 deps_info['assets'] = { |
459 'sources': all_asset_sources | 459 'sources': all_asset_sources |
460 } | 460 } |
461 if options.asset_renaming_destinations: | 461 if options.asset_renaming_destinations: |
462 deps_info['assets']['outputs'] = ( | 462 deps_info['assets']['outputs'] = ( |
463 build_utils.ParseGypList(options.asset_renaming_destinations)) | 463 build_utils.ParseGnList(options.asset_renaming_destinations)) |
464 if options.disable_asset_compression: | 464 if options.disable_asset_compression: |
465 deps_info['assets']['disable_compression'] = True | 465 deps_info['assets']['disable_compression'] = True |
466 | 466 |
467 if options.type == 'android_resources': | 467 if options.type == 'android_resources': |
468 deps_info['resources_zip'] = options.resources_zip | 468 deps_info['resources_zip'] = options.resources_zip |
469 if options.srcjar: | 469 if options.srcjar: |
470 deps_info['srcjar'] = options.srcjar | 470 deps_info['srcjar'] = options.srcjar |
471 if options.android_manifest: | 471 if options.android_manifest: |
472 manifest = AndroidManifest(options.android_manifest) | 472 manifest = AndroidManifest(options.android_manifest) |
473 deps_info['package_name'] = manifest.GetPackageName() | 473 deps_info['package_name'] = manifest.GetPackageName() |
474 if options.package_name: | 474 if options.package_name: |
475 deps_info['package_name'] = options.package_name | 475 deps_info['package_name'] = options.package_name |
476 if options.r_text: | 476 if options.r_text: |
477 deps_info['r_text'] = options.r_text | 477 deps_info['r_text'] = options.r_text |
478 if options.is_locale_resource: | 478 if options.is_locale_resource: |
479 deps_info['is_locale_resource'] = True | 479 deps_info['is_locale_resource'] = True |
480 | 480 |
481 deps_info['resources_dirs'] = [] | 481 deps_info['resources_dirs'] = [] |
482 if options.resource_dirs: | 482 if options.resource_dirs: |
483 for gyp_list in options.resource_dirs: | 483 for gyp_list in options.resource_dirs: |
484 deps_info['resources_dirs'].extend(build_utils.ParseGypList(gyp_list)) | 484 deps_info['resources_dirs'].extend(build_utils.ParseGnList(gyp_list)) |
485 | 485 |
486 if options.supports_android and options.type in ('android_apk', | 486 if options.supports_android and options.type in ('android_apk', |
487 'java_library'): | 487 'java_library'): |
488 # Lint all resources that are not already linted by a dependent library. | 488 # Lint all resources that are not already linted by a dependent library. |
489 owned_resource_dirs = set() | 489 owned_resource_dirs = set() |
490 owned_resource_zips = set() | 490 owned_resource_zips = set() |
491 for c in all_resources_deps: | 491 for c in all_resources_deps: |
492 # Always use resources_dirs in favour of resources_zips so that lint error | 492 # Always use resources_dirs in favour of resources_zips so that lint error |
493 # messages have paths that are closer to reality (and to avoid needing to | 493 # messages have paths that are closer to reality (and to avoid needing to |
494 # extract during lint). | 494 # extract during lint). |
(...skipping 23 matching lines...) Expand all Loading... |
518 c['r_text'] for c in all_resources_deps if 'r_text' in c] | 518 c['r_text'] for c in all_resources_deps if 'r_text' in c] |
519 | 519 |
520 if options.type in ['android_apk', 'deps_dex']: | 520 if options.type in ['android_apk', 'deps_dex']: |
521 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 521 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
522 | 522 |
523 if options.type in ('java_binary', 'java_library', 'android_apk'): | 523 if options.type in ('java_binary', 'java_library', 'android_apk'): |
524 javac_classpath = [c['jar_path'] for c in direct_library_deps] | 524 javac_classpath = [c['jar_path'] for c in direct_library_deps] |
525 java_full_classpath = [c['jar_path'] for c in all_library_deps] | 525 java_full_classpath = [c['jar_path'] for c in all_library_deps] |
526 | 526 |
527 if options.extra_classpath_jars: | 527 if options.extra_classpath_jars: |
528 extra_jars = build_utils.ParseGypList(options.extra_classpath_jars) | 528 extra_jars = build_utils.ParseGnList(options.extra_classpath_jars) |
529 deps_info['extra_classpath_jars'] = extra_jars | 529 deps_info['extra_classpath_jars'] = extra_jars |
530 javac_classpath += extra_jars | 530 javac_classpath += extra_jars |
531 | 531 |
532 # The java code for an instrumentation test apk is assembled differently for | 532 # The java code for an instrumentation test apk is assembled differently for |
533 # ProGuard vs. non-ProGuard. | 533 # ProGuard vs. non-ProGuard. |
534 # | 534 # |
535 # Without ProGuard: Each library's jar is dexed separately and then combined | 535 # Without ProGuard: Each library's jar is dexed separately and then combined |
536 # into a single classes.dex. A test apk will include all dex files not already | 536 # into a single classes.dex. A test apk will include all dex files not already |
537 # present in the apk-under-test. At runtime all test code lives in the test | 537 # present in the apk-under-test. At runtime all test code lives in the test |
538 # apk, and the program code lives in the apk-under-test. | 538 # apk, and the program code lives in the apk-under-test. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 'all_interface_jars': all_interface_jars, | 608 'all_interface_jars': all_interface_jars, |
609 } | 609 } |
610 manifest = AndroidManifest(options.android_manifest) | 610 manifest = AndroidManifest(options.android_manifest) |
611 deps_info['package_name'] = manifest.GetPackageName() | 611 deps_info['package_name'] = manifest.GetPackageName() |
612 if not options.tested_apk_config and manifest.GetInstrumentation(): | 612 if not options.tested_apk_config and manifest.GetInstrumentation(): |
613 # This must then have instrumentation only for itself. | 613 # This must then have instrumentation only for itself. |
614 manifest.CheckInstrumentation(manifest.GetPackageName()) | 614 manifest.CheckInstrumentation(manifest.GetPackageName()) |
615 | 615 |
616 library_paths = [] | 616 library_paths = [] |
617 java_libraries_list = None | 617 java_libraries_list = None |
618 runtime_deps_files = build_utils.ParseGypList( | 618 runtime_deps_files = build_utils.ParseGnList( |
619 options.shared_libraries_runtime_deps or '[]') | 619 options.shared_libraries_runtime_deps or '[]') |
620 if runtime_deps_files: | 620 if runtime_deps_files: |
621 library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files) | 621 library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files) |
622 # Create a java literal array with the "base" library names: | 622 # Create a java literal array with the "base" library names: |
623 # e.g. libfoo.so -> foo | 623 # e.g. libfoo.so -> foo |
624 java_libraries_list = ('{%s}' % ','.join( | 624 java_libraries_list = ('{%s}' % ','.join( |
625 ['"%s"' % s[3:-3] for s in library_paths])) | 625 ['"%s"' % s[3:-3] for s in library_paths])) |
626 | 626 |
627 all_inputs.extend(runtime_deps_files) | 627 all_inputs.extend(runtime_deps_files) |
628 config['native'] = { | 628 config['native'] = { |
629 'libraries': library_paths, | 629 'libraries': library_paths, |
630 'java_libraries_list': java_libraries_list, | 630 'java_libraries_list': java_libraries_list, |
631 } | 631 } |
632 config['assets'], config['uncompressed_assets'] = ( | 632 config['assets'], config['uncompressed_assets'] = ( |
633 _MergeAssets(deps.All('android_assets'))) | 633 _MergeAssets(deps.All('android_assets'))) |
634 | 634 |
635 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 635 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
636 | 636 |
637 if options.depfile: | 637 if options.depfile: |
638 build_utils.WriteDepfile(options.depfile, all_inputs) | 638 build_utils.WriteDepfile(options.depfile, all_inputs) |
639 | 639 |
640 | 640 |
641 if __name__ == '__main__': | 641 if __name__ == '__main__': |
642 sys.exit(main(sys.argv[1:])) | 642 sys.exit(main(sys.argv[1:])) |
OLD | NEW |