Chromium Code Reviews| 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 import("//build/config/android/internal_rules.gni") | 6 import("//build/config/android/internal_rules.gni") |
| 7 import("//build/config/dcheck_always_on.gni") | 7 import("//build/config/dcheck_always_on.gni") |
| 8 import("//build/toolchain/toolchain.gni") | 8 import("//build/toolchain/toolchain.gni") |
| 9 | 9 |
| 10 assert(is_android) | 10 assert(is_android) |
| (...skipping 2588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2599 # Declare an Android library target for a prebuilt AAR. | 2599 # Declare an Android library target for a prebuilt AAR. |
| 2600 # | 2600 # |
| 2601 # This target creates an Android library containing java code and Android | 2601 # This target creates an Android library containing java code and Android |
| 2602 # resources. For libraries without resources, it will not generate | 2602 # resources. For libraries without resources, it will not generate |
| 2603 # corresponding android_resources targets. | 2603 # corresponding android_resources targets. |
| 2604 # | 2604 # |
| 2605 # Variables | 2605 # Variables |
| 2606 # aar_path: Path to the AAR. | 2606 # aar_path: Path to the AAR. |
| 2607 # proguard_configs: List of proguard configs to use in final apk step for | 2607 # proguard_configs: List of proguard configs to use in final apk step for |
| 2608 # any apk that depends on this library. | 2608 # any apk that depends on this library. |
| 2609 # ignore_aidl: Whether to ignore .aidl files found with the .aar. | |
|
Ian Wen
2016/09/06 21:38:34
I feel like once we include an AAR file, we should
agrieve
2016/09/07 02:19:31
That's a fair point. I've removed "ignore_resource
| |
| 2610 # ignore_assets: Whether to ignore assets found in the .aar. | |
| 2611 # ignore_manifest: Whether to ignore merging of AndroidManifest.xml. | |
| 2612 # ignore_resources: Whether to ignore resources found in the .aar. | |
| 2613 # ignore_native_libraries: Whether to ignore .so files found in the .aar. | |
| 2609 # TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed. | 2614 # TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed. |
| 2610 # requires_android: Whether this target can only be used for compiling Andro id related targets. | 2615 # requires_android: Whether this target can only be used for compiling Andro id related targets. |
| 2611 # | 2616 # |
| 2612 # Example | 2617 # Example |
| 2613 # android_aar_prebuilt("foo_java") { | 2618 # android_aar_prebuilt("foo_java") { |
| 2614 # aar_path = "foo.aar" | 2619 # aar_path = "foo.aar" |
| 2615 # } | 2620 # } |
| 2616 template("android_aar_prebuilt") { | 2621 template("android_aar_prebuilt") { |
| 2617 assert(defined(invoker.aar_path)) | |
| 2618 _output_path = "${target_gen_dir}/${target_name}" | 2622 _output_path = "${target_gen_dir}/${target_name}" |
| 2619 _unpack_target_name = "${target_name}__unpack_aar" | 2623 _unpack_target_name = "${target_name}__unpack_aar" |
| 2624 _ignore_aidl = defined(invoker.ignore_aidl) && invoker.ignore_aidl | |
| 2625 _ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets | |
| 2626 _ignore_manifest = | |
| 2627 defined(invoker.ignore_manifest) && invoker.ignore_manifest | |
| 2628 _ignore_resources = | |
| 2629 defined(invoker.ignore_resources) && invoker.ignore_resources | |
| 2630 _ignore_native_libraries = defined(invoker.ignore_native_libraries) && | |
| 2631 invoker.ignore_native_libraries | |
| 2620 | 2632 |
| 2621 # Scan the AAR file and determine the resources and jar files. | 2633 # Scan the AAR file and determine the resources and jar files. |
| 2622 # Some libraries might not have resources; others might have two jars. | 2634 # Some libraries might not have resources; others might have two jars. |
| 2623 _scanned_files = | 2635 _scanned_files = |
| 2624 exec_script("//build/android/gyp/aar.py", | 2636 exec_script("//build/android/gyp/aar.py", |
| 2625 [ | 2637 [ |
| 2626 "--input-file", | 2638 "--input-file", |
| 2627 rebase_path(invoker.aar_path, root_build_dir), | 2639 rebase_path(invoker.aar_path, root_build_dir), |
| 2628 "--list", | 2640 "--list", |
| 2629 ], | 2641 ], |
| 2630 "scope") | 2642 "scope") |
| 2631 | 2643 |
| 2644 assert(_ignore_aidl || _scanned_files.aidl == [], | |
| 2645 "android_aar_prebuilt() aidl not yet supported." + | |
| 2646 " Implement or use ignore_aidl = true." + | |
| 2647 " http://crbug.com/644439") | |
| 2648 assert(_ignore_assets || _scanned_files.assets == [], | |
| 2649 "android_aar_prebuilt() assets not yet supported." + | |
| 2650 " Implement or use ignore_assets = true." + | |
| 2651 " http://crbug.com/643966") | |
| 2652 assert(_ignore_native_libraries || !_scanned_files.has_native_libraries, | |
| 2653 "android_aar_prebuilt() with .so files is not supported." + | |
| 2654 " Use ignore_native_libraries = true to silence this error.") | |
| 2655 assert(_ignore_manifest || _scanned_files.is_manifest_empty, | |
| 2656 "android_aar_prebuilt() manifest merging not yet supported and" + | |
| 2657 " non-trivial AndroidManifest.xml detected." + | |
| 2658 " Implement or use ignore_manifest = true." + | |
| 2659 " http://crbug.com/643967") | |
| 2660 assert(_scanned_files.has_classes_jar || _scanned_files.subjars == []) | |
| 2661 | |
| 2632 action(_unpack_target_name) { | 2662 action(_unpack_target_name) { |
| 2633 script = "//build/android/gyp/aar.py" # Unzips the AAR | 2663 script = "//build/android/gyp/aar.py" # Unzips the AAR |
| 2634 args = [ | 2664 args = [ |
| 2635 "--input-file", | 2665 "--input-file", |
| 2636 rebase_path(invoker.aar_path, root_build_dir), | 2666 rebase_path(invoker.aar_path, root_build_dir), |
| 2637 "--output-dir", | 2667 "--output-dir", |
| 2638 rebase_path(_output_path, root_build_dir), | 2668 rebase_path(_output_path, root_build_dir), |
| 2639 "--extract", | 2669 "--extract", |
| 2640 ] | 2670 ] |
| 2641 inputs = [ | 2671 inputs = [ |
| 2642 invoker.aar_path, | 2672 invoker.aar_path, |
| 2643 ] | 2673 ] |
| 2644 outputs = [ | 2674 outputs = [ |
| 2645 "${_output_path}/AndroidManifest.xml", | 2675 "${_output_path}/AndroidManifest.xml", |
| 2646 ] | 2676 ] |
| 2647 | 2677 |
| 2648 if (_scanned_files.resources != []) { | 2678 if (_scanned_files.resources != []) { |
| 2649 outputs += [ "${_output_path}/R.txt" ] | 2679 outputs += [ "${_output_path}/R.txt" ] |
| 2650 outputs += get_path_info( | 2680 outputs += get_path_info( |
| 2651 rebase_path(_scanned_files.resources, "", _output_path), | 2681 rebase_path(_scanned_files.resources, "", _output_path), |
| 2652 "abspath") | 2682 "abspath") |
| 2653 } | 2683 } |
| 2654 if (defined(_scanned_files.jars)) { | 2684 if (_scanned_files.has_classes_jar) { |
| 2655 outputs += | 2685 outputs += [ "${_output_path}/classes.jar" ] |
| 2656 get_path_info(rebase_path(_scanned_files.jars, "", _output_path), | 2686 } |
| 2657 "abspath") | 2687 outputs += |
| 2688 get_path_info(rebase_path(_scanned_files.subjars, "", _output_path), | |
| 2689 "abspath") | |
| 2690 if (_scanned_files.has_proguard_flags) { | |
| 2691 outputs += [ "${_output_path}/proguard.txt" ] | |
| 2658 } | 2692 } |
| 2659 } | 2693 } |
| 2660 | 2694 |
| 2661 _resource_targets = [] | |
| 2662 | |
| 2663 # Create the android_resources target for resources. | 2695 # Create the android_resources target for resources. |
| 2664 if (_scanned_files.resources != []) { | 2696 if (!_ignore_resources && _scanned_files.resources != []) { |
| 2665 _res_target_name = "${target_name}__res" | 2697 _res_target_name = "${target_name}__res" |
| 2666 _resource_targets += [ ":$_res_target_name" ] | |
| 2667 android_resources(_res_target_name) { | 2698 android_resources(_res_target_name) { |
| 2668 forward_variables_from(invoker, [ "deps" ]) | 2699 forward_variables_from(invoker, [ "deps" ]) |
| 2669 if (!defined(deps)) { | 2700 if (!defined(deps)) { |
| 2670 deps = [] | 2701 deps = [] |
| 2671 } | 2702 } |
| 2672 deps += [ ":$_unpack_target_name" ] | 2703 deps += [ ":$_unpack_target_name" ] |
| 2673 resource_dirs = [] | 2704 resource_dirs = [] |
| 2674 generated_resource_dirs = [ "${_output_path}/res" ] | 2705 generated_resource_dirs = [ "${_output_path}/res" ] |
| 2675 generated_resource_files = | 2706 generated_resource_files = |
| 2676 rebase_path(_scanned_files.resources, "", _output_path) | 2707 rebase_path(_scanned_files.resources, "", _output_path) |
| 2677 android_manifest_dep = ":$_unpack_target_name" | 2708 android_manifest_dep = ":$_unpack_target_name" |
| 2678 android_manifest = "${_output_path}/AndroidManifest.xml" | 2709 android_manifest = "${_output_path}/AndroidManifest.xml" |
| 2679 v14_skip = true | 2710 v14_skip = true |
| 2680 } | 2711 } |
| 2681 } | 2712 } |
| 2682 | 2713 |
| 2683 # Create android_java_prebuilt targets for jar files. | 2714 # Create android_java_prebuilt target for extra jars within jars/. |
| 2684 _jar_targets = [] | 2715 _subjar_targets = [] |
| 2685 _counter = 0 | 2716 foreach(_jar_subpath, _scanned_files.subjars) { |
| 2686 foreach(jar, _scanned_files.jars) { | 2717 if (!defined(_counter)) { |
| 2687 _counter += 1 | 2718 _counter = 0 |
| 2688 _current_target = "${target_name}__jar_$_counter" | 2719 } else { |
| 2689 _jar_targets += [ ":$_current_target" ] | 2720 _counter += 1 |
| 2721 } | |
| 2722 _labels = _scanned_files.subjar_labels | |
| 2723 _current_target = "${target_name}__subjar_${_labels[_counter]}" | |
| 2724 _subjar_targets += [ ":$_current_target" ] | |
| 2690 java_prebuilt(_current_target) { | 2725 java_prebuilt(_current_target) { |
| 2691 forward_variables_from(invoker, | 2726 forward_variables_from(invoker, |
| 2692 [ | 2727 [ |
| 2728 "jar_excluded_patterns", | |
| 2729 "requires_android", | |
| 2730 ]) | |
| 2731 deps = [ | |
| 2732 ":$_unpack_target_name", | |
| 2733 ] | |
| 2734 if (!defined(requires_android)) { | |
| 2735 requires_android = true | |
| 2736 } | |
| 2737 supports_android = true | |
| 2738 jar_path = "$_output_path/$_jar_subpath" | |
| 2739 } | |
| 2740 } | |
| 2741 | |
| 2742 # Create android_java_prebuilt target for classes.jar. | |
| 2743 if (_scanned_files.has_classes_jar) { | |
| 2744 _jar_target_name = "${target_name}__classes" | |
| 2745 java_prebuilt(_jar_target_name) { | |
| 2746 forward_variables_from(invoker, | |
| 2747 [ | |
| 2693 "deps", | 2748 "deps", |
| 2694 "input_jars_paths", | 2749 "input_jars_paths", |
| 2695 "jar_excluded_patterns", | 2750 "jar_excluded_patterns", |
| 2696 "proguard_configs", | 2751 "proguard_configs", |
| 2697 "requires_android", | 2752 "requires_android", |
| 2698 ]) | 2753 ]) |
| 2699 if (!defined(deps)) { | 2754 if (!defined(deps)) { |
| 2700 deps = [] | 2755 deps = [] |
| 2701 } | 2756 } |
| 2702 deps += _resource_targets + [ ":$_unpack_target_name" ] | 2757 deps += _subjar_targets + [ ":$_unpack_target_name" ] |
| 2758 if (defined(_res_target_name)) { | |
| 2759 deps += [ ":$_res_target_name" ] | |
| 2760 } | |
| 2703 if (!defined(requires_android)) { | 2761 if (!defined(requires_android)) { |
| 2704 requires_android = true | 2762 requires_android = true |
| 2705 } | 2763 } |
| 2706 supports_android = true | 2764 supports_android = true |
| 2707 jar_path = "${_output_path}/$jar" | 2765 jar_path = "$_output_path/classes.jar" |
| 2766 | |
| 2767 if (_scanned_files.has_proguard_flags) { | |
| 2768 if (!defined(proguard_configs)) { | |
| 2769 proguard_configs = [] | |
| 2770 } | |
| 2771 proguard_configs += [ "$_output_path/proguard.txt" ] | |
| 2772 } | |
| 2708 } | 2773 } |
| 2709 } | 2774 } |
| 2710 | 2775 |
| 2711 java_group(target_name) { | 2776 java_group(target_name) { |
| 2712 deps = _resource_targets + _jar_targets | 2777 deps = [] |
| 2778 if (defined(_jar_target_name)) { | |
| 2779 deps += [ ":$_jar_target_name" ] | |
| 2780 | |
| 2781 # Although subjars are meant to be private, we add them as deps here | |
| 2782 # because in practice they seem to contain classes required to be in the | |
| 2783 # classpath. | |
| 2784 deps += _subjar_targets | |
| 2785 } | |
| 2786 if (defined(_res_target_name)) { | |
| 2787 deps += [ ":$_res_target_name" ] | |
| 2788 } | |
| 2713 } | 2789 } |
| 2714 } | 2790 } |
| 2715 } | 2791 } |
| OLD | NEW |