OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//build/config/android/config.gni") | 5 import("//build/config/android/config.gni") |
6 | 6 |
7 assert(is_android) | 7 assert(is_android) |
8 | 8 |
9 rebased_android_sdk = rebase_path(android_sdk, root_build_dir) | 9 rebased_android_sdk = rebase_path(android_sdk, root_build_dir) |
10 rebased_android_sdk_root = rebase_path(android_sdk_root, root_build_dir) | 10 rebased_android_sdk_root = rebase_path(android_sdk_root, root_build_dir) |
11 rebased_android_sdk_build_tools = | 11 rebased_android_sdk_build_tools = |
12 rebase_path(android_sdk_build_tools, root_build_dir) | 12 rebase_path(android_sdk_build_tools, root_build_dir) |
13 | 13 |
14 android_sdk_jar = "$android_sdk/android.jar" | 14 android_sdk_jar = "$android_sdk/android.jar" |
15 rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir) | 15 rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir) |
16 android_aapt_path = "$rebased_android_sdk_build_tools/aapt" | 16 android_aapt_path = "$rebased_android_sdk_build_tools/aapt" |
17 | 17 |
| 18 android_configuration_name = "Release" |
| 19 if (is_debug) { |
| 20 android_configuration_name = "Debug" |
| 21 } |
| 22 |
18 template("android_lint") { | 23 template("android_lint") { |
19 set_sources_assignment_filter([]) | 24 set_sources_assignment_filter([]) |
20 | 25 |
21 jar_path = invoker.jar_path | 26 jar_path = invoker.jar_path |
22 android_manifest = invoker.android_manifest | 27 android_manifest = invoker.android_manifest |
23 java_files = invoker.java_files | 28 java_files = invoker.java_files |
24 base_path = "$target_gen_dir/$target_name" | 29 base_path = "$target_gen_dir/$target_name" |
25 | 30 |
26 action(target_name) { | 31 action(target_name) { |
27 forward_variables_from(invoker, | 32 forward_variables_from(invoker, |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 465 |
461 group(target_name) { | 466 group(target_name) { |
462 forward_variables_from(invoker, [ "visibility" ]) | 467 forward_variables_from(invoker, [ "visibility" ]) |
463 public_deps = [ | 468 public_deps = [ |
464 ":${target_name}__jar_toc", | 469 ":${target_name}__jar_toc", |
465 ":$_output_jar_target", | 470 ":$_output_jar_target", |
466 ] | 471 ] |
467 } | 472 } |
468 } | 473 } |
469 | 474 |
470 template("finalize_apk") { | 475 # Creates an unsigned .apk. |
| 476 # |
| 477 # Variables |
| 478 # deps: Specifies the dependencies of this target. |
| 479 # dex_path: Path to classes.dex file to include (optional). |
| 480 # resource_packaged_apk_path: Path to .ap_ to use. |
| 481 # output_apk_path: Output path for the generated .apk. |
| 482 # native_libs_dir: Directory containing native libraries. |
| 483 template("package_apk") { |
471 action(target_name) { | 484 action(target_name) { |
472 forward_variables_from(invoker, | 485 forward_variables_from(invoker, |
473 [ | 486 [ |
| 487 "deps", |
474 "data_deps", | 488 "data_deps", |
475 "deps", | |
476 "public_deps", | 489 "public_deps", |
477 "testonly", | 490 "testonly", |
478 ]) | 491 ]) |
| 492 script = "//build/android/gyp/ant.py" |
| 493 _ant_script = "//build/android/ant/apk-package.xml" |
| 494 |
| 495 depfile = "$target_gen_dir/$target_name.d" |
| 496 |
| 497 inputs = [ |
| 498 invoker.resource_packaged_apk_path, |
| 499 _ant_script, |
| 500 ] |
| 501 if (defined(invoker.dex_path)) { |
| 502 inputs += [ invoker.dex_path ] |
| 503 } |
| 504 |
| 505 outputs = [ |
| 506 depfile, |
| 507 invoker.output_apk_path, |
| 508 ] |
| 509 |
| 510 _rebased_emma_jar = "" |
| 511 _rebased_resource_packaged_apk_path = |
| 512 rebase_path(invoker.resource_packaged_apk_path, root_build_dir) |
| 513 _rebased_packaged_apk_path = |
| 514 rebase_path(invoker.output_apk_path, root_build_dir) |
| 515 _rebased_native_libs_dir = |
| 516 rebase_path(invoker.native_libs_dir, root_build_dir) |
| 517 args = [ |
| 518 "--depfile", |
| 519 rebase_path(depfile, root_build_dir), |
| 520 "--", |
| 521 "-quiet", |
| 522 "-DANDROID_SDK_ROOT=$rebased_android_sdk_root", |
| 523 "-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools", |
| 524 "-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path", |
| 525 "-DCONFIGURATION_NAME=$android_configuration_name", |
| 526 "-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir", |
| 527 "-DOUT_DIR=", |
| 528 "-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path", |
| 529 "-DEMMA_INSTRUMENT=0", |
| 530 "-DEMMA_DEVICE_JAR=$_rebased_emma_jar", |
| 531 "-Dbasedir=.", |
| 532 "-buildfile", |
| 533 rebase_path(_ant_script, root_build_dir), |
| 534 ] |
| 535 if (defined(invoker.dex_path)) { |
| 536 _rebased_dex_path = rebase_path(invoker.dex_path, root_build_dir) |
| 537 args += [ |
| 538 "-DDEX_FILE_PATH=$_rebased_dex_path", |
| 539 "-DHAS_CODE=true", |
| 540 ] |
| 541 } else { |
| 542 args += [ "-DHAS_CODE=false" ] |
| 543 } |
| 544 } |
| 545 } |
| 546 |
| 547 # Signs & zipaligns an apk. |
| 548 # |
| 549 # Variables |
| 550 # input_apk_path: Path of the .apk to be finalized. |
| 551 # output_apk_path: Output path for the generated .apk. |
| 552 # keystore_path: Path to keystore to use for signing. |
| 553 # keystore_name: Key alias to use. |
| 554 # keystore_password: Keystore password. |
| 555 # rezip_apk: Whether to add crazy-linker alignment. |
| 556 template("finalize_apk") { |
| 557 action(target_name) { |
479 script = "//build/android/gyp/finalize_apk.py" | 558 script = "//build/android/gyp/finalize_apk.py" |
480 depfile = "$target_gen_dir/$target_name.d" | 559 depfile = "$target_gen_dir/$target_name.d" |
| 560 forward_variables_from(invoker, |
| 561 [ |
| 562 "deps", |
| 563 "data_deps", |
| 564 "public_deps", |
| 565 "testonly", |
| 566 ]) |
481 | 567 |
482 sources = [ | 568 sources = [ |
483 invoker.input_apk_path, | 569 invoker.input_apk_path, |
484 ] | 570 ] |
485 inputs = [ | 571 inputs = [ |
486 invoker.keystore_path, | 572 invoker.keystore_path, |
487 ] | 573 ] |
488 outputs = [ | 574 outputs = [ |
489 depfile, | 575 depfile, |
490 invoker.output_apk_path, | 576 invoker.output_apk_path, |
(...skipping 29 matching lines...) Expand all Loading... |
520 | 606 |
521 # Packages resources, assets, dex, and native libraries into an apk. Signs and | 607 # Packages resources, assets, dex, and native libraries into an apk. Signs and |
522 # zipaligns the apk. | 608 # zipaligns the apk. |
523 template("create_apk") { | 609 template("create_apk") { |
524 set_sources_assignment_filter([]) | 610 set_sources_assignment_filter([]) |
525 forward_variables_from(invoker, [ "testonly" ]) | 611 forward_variables_from(invoker, [ "testonly" ]) |
526 | 612 |
527 _android_manifest = invoker.android_manifest | 613 _android_manifest = invoker.android_manifest |
528 _base_path = invoker.base_path | 614 _base_path = invoker.base_path |
529 _final_apk_path = invoker.apk_path | 615 _final_apk_path = invoker.apk_path |
| 616 _incremental_final_apk_path_helper = |
| 617 process_file_template( |
| 618 [ _final_apk_path ], |
| 619 "{{source_dir}}/{{source_name_part}}_incremental.apk") |
| 620 _incremental_final_apk_path = _incremental_final_apk_path_helper[0] |
530 | 621 |
531 if (defined(invoker.resources_zip)) { | 622 if (defined(invoker.resources_zip)) { |
532 _resources_zip = invoker.resources_zip | 623 _resources_zip = invoker.resources_zip |
533 } | 624 } |
534 if (defined(invoker.dex_path)) { | 625 if (defined(invoker.dex_path)) { |
535 _dex_path = invoker.dex_path | 626 _dex_path = invoker.dex_path |
536 } | 627 } |
537 _load_library_from_apk = invoker.load_library_from_apk | 628 _load_library_from_apk = invoker.load_library_from_apk |
538 | 629 |
539 _package_deps = [] | 630 _package_deps = [] |
(...skipping 10 matching lines...) Expand all Loading... |
550 _asset_location = invoker.asset_location | 641 _asset_location = invoker.asset_location |
551 } | 642 } |
552 | 643 |
553 _version_code = invoker.version_code | 644 _version_code = invoker.version_code |
554 _version_name = invoker.version_name | 645 _version_name = invoker.version_name |
555 | 646 |
556 _base_apk_path = _base_path + ".apk_intermediates" | 647 _base_apk_path = _base_path + ".apk_intermediates" |
557 | 648 |
558 _resource_packaged_apk_path = _base_apk_path + ".ap_" | 649 _resource_packaged_apk_path = _base_apk_path + ".ap_" |
559 _packaged_apk_path = _base_apk_path + ".unfinished.apk" | 650 _packaged_apk_path = _base_apk_path + ".unfinished.apk" |
| 651 _incremental_packaged_apk_path = |
| 652 _base_apk_path + "_incremental.unfinished.apk" |
560 _shared_resources = | 653 _shared_resources = |
561 defined(invoker.shared_resources) && invoker.shared_resources | 654 defined(invoker.shared_resources) && invoker.shared_resources |
562 | 655 |
563 _configuration_name = "Release" | |
564 if (is_debug) { | |
565 _configuration_name = "Debug" | |
566 } | |
567 | |
568 _keystore_path = invoker.keystore_path | 656 _keystore_path = invoker.keystore_path |
569 _keystore_name = invoker.keystore_name | 657 _keystore_name = invoker.keystore_name |
570 _keystore_password = invoker.keystore_password | 658 _keystore_password = invoker.keystore_password |
571 | 659 |
572 _split_densities = [] | 660 _split_densities = [] |
573 if (defined(invoker.create_density_splits) && invoker.create_density_splits) { | 661 if (defined(invoker.create_density_splits) && invoker.create_density_splits) { |
574 _split_densities = [ | 662 _split_densities = [ |
575 "hdpi", | 663 "hdpi", |
576 "xhdpi", | 664 "xhdpi", |
577 "xxhdpi", | 665 "xxhdpi", |
(...skipping 24 matching lines...) Expand all Loading... |
602 _resource_packaged_apk_path, | 690 _resource_packaged_apk_path, |
603 ] | 691 ] |
604 | 692 |
605 args = [ | 693 args = [ |
606 "--depfile", | 694 "--depfile", |
607 rebase_path(depfile, root_build_dir), | 695 rebase_path(depfile, root_build_dir), |
608 "--android-sdk", | 696 "--android-sdk", |
609 rebased_android_sdk, | 697 rebased_android_sdk, |
610 "--aapt-path", | 698 "--aapt-path", |
611 android_aapt_path, | 699 android_aapt_path, |
612 "--configuration-name=$_configuration_name", | 700 "--configuration-name=$android_configuration_name", |
613 "--android-manifest", | 701 "--android-manifest", |
614 rebase_path(_android_manifest, root_build_dir), | 702 rebase_path(_android_manifest, root_build_dir), |
615 "--version-code", | 703 "--version-code", |
616 _version_code, | 704 _version_code, |
617 "--version-name", | 705 "--version-name", |
618 _version_name, | 706 _version_name, |
619 "--apk-path", | 707 "--apk-path", |
620 rebase_path(_resource_packaged_apk_path, root_build_dir), | 708 rebase_path(_resource_packaged_apk_path, root_build_dir), |
621 ] | 709 ] |
622 | 710 |
(...skipping 26 matching lines...) Expand all Loading... |
649 } | 737 } |
650 if (defined(invoker.extensions_to_not_compress)) { | 738 if (defined(invoker.extensions_to_not_compress)) { |
651 args += [ | 739 args += [ |
652 "--no-compress", | 740 "--no-compress", |
653 invoker.extensions_to_not_compress, | 741 invoker.extensions_to_not_compress, |
654 ] | 742 ] |
655 } | 743 } |
656 } | 744 } |
657 | 745 |
658 package_target = "${target_name}__package" | 746 package_target = "${target_name}__package" |
659 action(package_target) { | 747 package_apk(package_target) { |
660 script = "//build/android/gyp/ant.py" | 748 deps = [] |
661 _ant_script = "//build/android/ant/apk-package.xml" | 749 forward_variables_from(invoker, [ "deps" ]) |
| 750 deps += [ ":${_package_resources_target_name}" ] |
662 | 751 |
663 deps = [ | 752 if (defined(_dex_path)) { |
664 ":${_package_resources_target_name}", | 753 dex_path = _dex_path |
665 ] | |
666 if (defined(invoker.deps)) { | |
667 deps += invoker.deps | |
668 } | 754 } |
669 depfile = "$target_gen_dir/$target_name.d" | 755 native_libs_dir = _native_libs_dir |
| 756 output_apk_path = _packaged_apk_path |
| 757 resource_packaged_apk_path = _resource_packaged_apk_path |
| 758 } |
670 | 759 |
671 inputs = [ | 760 _incremental_package_target = "${target_name}_incremental__package" |
672 _resource_packaged_apk_path, | 761 package_apk(_incremental_package_target) { |
673 _ant_script, | 762 deps = [] |
674 ] | 763 forward_variables_from(invoker, [ "deps" ]) |
| 764 deps += [ ":${_package_resources_target_name}" ] |
| 765 |
| 766 # TODO(agrieve): Multidex |
675 if (defined(_dex_path)) { | 767 if (defined(_dex_path)) { |
676 inputs += [ _dex_path ] | 768 dex_path = _dex_path |
677 } | 769 } |
678 | 770 |
679 outputs = [ | 771 # TODO(agrieve): Add a placeholder .so for http://crbug.com/384638 |
680 depfile, | 772 native_libs_dir = "//build/android/empty/res" |
681 _packaged_apk_path, | 773 output_apk_path = _incremental_packaged_apk_path |
682 ] | 774 resource_packaged_apk_path = _resource_packaged_apk_path |
683 | |
684 _rebased_emma_jar = "" | |
685 _rebased_resource_packaged_apk_path = | |
686 rebase_path(_resource_packaged_apk_path, root_build_dir) | |
687 _rebased_packaged_apk_path = rebase_path(_packaged_apk_path, root_build_dir) | |
688 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir) | |
689 args = [ | |
690 "--depfile", | |
691 rebase_path(depfile, root_build_dir), | |
692 "--", | |
693 "-quiet", | |
694 "-DANDROID_SDK_ROOT=$rebased_android_sdk_root", | |
695 "-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools", | |
696 "-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path", | |
697 "-DCONFIGURATION_NAME=$_configuration_name", | |
698 "-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir", | |
699 "-DOUT_DIR=", | |
700 "-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path", | |
701 "-DEMMA_INSTRUMENT=0", | |
702 "-DEMMA_DEVICE_JAR=$_rebased_emma_jar", | |
703 "-Dbasedir=.", | |
704 "-buildfile", | |
705 rebase_path(_ant_script, root_build_dir), | |
706 ] | |
707 if (defined(_dex_path)) { | |
708 _rebased_dex_path = rebase_path(_dex_path, root_build_dir) | |
709 args += [ | |
710 "-DDEX_FILE_PATH=$_rebased_dex_path", | |
711 "-DHAS_CODE=true", | |
712 ] | |
713 } else { | |
714 args += [ "-DHAS_CODE=false" ] | |
715 } | |
716 } | 775 } |
717 | 776 |
718 _finalize_apk_rule_name = "${target_name}__finalize" | 777 _finalize_apk_rule_name = "${target_name}__finalize" |
719 finalize_apk(_finalize_apk_rule_name) { | 778 finalize_apk(_finalize_apk_rule_name) { |
720 input_apk_path = _packaged_apk_path | 779 input_apk_path = _packaged_apk_path |
721 output_apk_path = _final_apk_path | 780 output_apk_path = _final_apk_path |
722 keystore_path = _keystore_path | 781 keystore_path = _keystore_path |
723 keystore_name = _keystore_name | 782 keystore_name = _keystore_name |
724 keystore_password = _keystore_password | 783 keystore_password = _keystore_password |
725 rezip_apk = _load_library_from_apk | 784 rezip_apk = _load_library_from_apk |
726 | 785 |
727 public_deps = [ | 786 public_deps = [ |
728 # Generator of the _packaged_apk_path this target takes as input. | 787 # Generator of the _packaged_apk_path this target takes as input. |
729 ":$package_target", | 788 ":$package_target", |
730 ] | 789 ] |
731 } | 790 } |
732 | 791 |
733 _final_deps = [ ":${_finalize_apk_rule_name}" ] | 792 _incremental_finalize_apk_rule_name = "${target_name}_incremental__finalize" |
| 793 finalize_apk(_incremental_finalize_apk_rule_name) { |
| 794 input_apk_path = _incremental_packaged_apk_path |
| 795 output_apk_path = _incremental_final_apk_path |
| 796 keystore_path = _keystore_path |
| 797 keystore_name = _keystore_name |
| 798 keystore_password = _keystore_password |
| 799 |
| 800 public_deps = [ |
| 801 ":$_incremental_package_target", |
| 802 ] |
| 803 } |
| 804 |
| 805 _split_deps = [] |
734 | 806 |
735 template("finalize_split") { | 807 template("finalize_split") { |
736 finalize_apk(target_name) { | 808 finalize_apk(target_name) { |
737 _config = invoker.split_config | 809 _config = invoker.split_config |
738 _type = invoker.split_type | 810 _type = invoker.split_type |
739 input_apk_path = "${_resource_packaged_apk_path}_${_config}" | 811 input_apk_path = "${_resource_packaged_apk_path}_${_config}" |
740 _output_paths = process_file_template( | 812 _output_paths = process_file_template( |
741 [ _final_apk_path ], | 813 [ _final_apk_path ], |
742 "{{source_dir}}/{{source_name_part}}-${_type}-${_config}.apk") | 814 "{{source_dir}}/{{source_name_part}}-${_type}-${_config}.apk") |
743 output_apk_path = _output_paths[0] | 815 output_apk_path = _output_paths[0] |
744 keystore_path = _keystore_path | 816 keystore_path = _keystore_path |
745 keystore_name = _keystore_name | 817 keystore_name = _keystore_name |
746 keystore_password = _keystore_password | 818 keystore_password = _keystore_password |
747 deps = [ | 819 deps = [ |
748 ":${_package_resources_target_name}", | 820 ":${_package_resources_target_name}", |
749 ] | 821 ] |
750 } | 822 } |
751 } | 823 } |
752 | 824 |
753 foreach(_split, _split_densities) { | 825 foreach(_split, _split_densities) { |
754 _split_rule = "${target_name}__finalize_${_split}_split" | 826 _split_rule = "${target_name}__finalize_${_split}_split" |
755 finalize_split(_split_rule) { | 827 finalize_split(_split_rule) { |
756 split_type = "density" | 828 split_type = "density" |
757 split_config = _split | 829 split_config = _split |
758 } | 830 } |
759 _final_deps += [ ":$_split_rule" ] | 831 _split_deps += [ ":$_split_rule" ] |
760 } | 832 } |
761 foreach(_split, _split_languages) { | 833 foreach(_split, _split_languages) { |
762 _split_rule = "${target_name}__finalize_${_split}_split" | 834 _split_rule = "${target_name}__finalize_${_split}_split" |
763 finalize_split(_split_rule) { | 835 finalize_split(_split_rule) { |
764 split_type = "lang" | 836 split_type = "lang" |
765 split_config = _split | 837 split_config = _split |
766 } | 838 } |
767 _final_deps += [ ":$_split_rule" ] | 839 _split_deps += [ ":$_split_rule" ] |
768 } | 840 } |
769 | 841 |
770 group(target_name) { | 842 group(target_name) { |
771 public_deps = _final_deps | 843 public_deps = [ ":${_finalize_apk_rule_name}" ] + _split_deps |
| 844 } |
| 845 group("${target_name}_incremental") { |
| 846 public_deps = [ ":${_incremental_finalize_apk_rule_name}" ] + _split_deps |
772 } | 847 } |
773 } | 848 } |
774 | 849 |
775 template("java_prebuilt_impl") { | 850 template("java_prebuilt_impl") { |
776 set_sources_assignment_filter([]) | 851 set_sources_assignment_filter([]) |
777 forward_variables_from(invoker, [ "testonly" ]) | 852 forward_variables_from(invoker, [ "testonly" ]) |
778 _supports_android = | 853 _supports_android = |
779 defined(invoker.supports_android) && invoker.supports_android | 854 defined(invoker.supports_android) && invoker.supports_android |
780 | 855 |
781 assert(defined(invoker.jar_path)) | 856 assert(defined(invoker.jar_path)) |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 ] | 1577 ] |
1503 args = [ | 1578 args = [ |
1504 "--depfile", | 1579 "--depfile", |
1505 rebase_path(depfile, root_build_dir), | 1580 rebase_path(depfile, root_build_dir), |
1506 "--script-output-path", | 1581 "--script-output-path", |
1507 rebase_path(generated_script, root_build_dir), | 1582 rebase_path(generated_script, root_build_dir), |
1508 ] | 1583 ] |
1509 args += test_runner_args | 1584 args += test_runner_args |
1510 } | 1585 } |
1511 } | 1586 } |
OLD | NEW |