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_assets: Whether to ignore assets found in the .aar. | |
2610 # ignore_manifest: Whether to ignore merging of AndroidManifest.xml. | |
2611 # ignore_resources: Whether to ignore resources found in the .aar. | |
2612 # ignore_native_libraries: Whether to ignore .so files found in the .aar. | |
2609 # TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed. | 2613 # 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. | 2614 # requires_android: Whether this target can only be used for compiling Andro id related targets. |
2611 # | 2615 # |
2612 # Example | 2616 # Example |
2613 # android_aar_prebuilt("foo_java") { | 2617 # android_aar_prebuilt("foo_java") { |
2614 # aar_path = "foo.aar" | 2618 # aar_path = "foo.aar" |
2615 # } | 2619 # } |
2616 template("android_aar_prebuilt") { | 2620 template("android_aar_prebuilt") { |
2617 assert(defined(invoker.aar_path)) | |
2618 _output_path = "${target_gen_dir}/${target_name}" | 2621 _output_path = "${target_gen_dir}/${target_name}" |
2619 _unpack_target_name = "${target_name}__unpack_aar" | 2622 _unpack_target_name = "${target_name}__unpack_aar" |
2623 _ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets | |
2624 _ignore_manifest = | |
2625 defined(invoker.ignore_manifest) && invoker.ignore_manifest | |
2626 _ignore_resources = | |
2627 defined(invoker.ignore_resources) && invoker.ignore_resources | |
2628 _ignore_native_libraries = defined(invoker.ignore_native_libraries) && | |
2629 invoker.ignore_native_libraries | |
2620 | 2630 |
2621 # Scan the AAR file and determine the resources and jar files. | 2631 # Scan the AAR file and determine the resources and jar files. |
2622 # Some libraries might not have resources; others might have two jars. | 2632 # Some libraries might not have resources; others might have two jars. |
2623 _scanned_files = | 2633 _scanned_files = |
2624 exec_script("//build/android/gyp/aar.py", | 2634 exec_script("//build/android/gyp/aar.py", |
2625 [ | 2635 [ |
2626 "--input-file", | 2636 "--input-file", |
2627 rebase_path(invoker.aar_path, root_build_dir), | 2637 rebase_path(invoker.aar_path, root_build_dir), |
2628 "--list", | 2638 "--list", |
2629 ], | 2639 ], |
2630 "scope") | 2640 "scope") |
2631 | 2641 |
2642 assert(_ignore_assets || _scanned_files.assets == [], | |
2643 "android_aar_prebuilt() assets not yet supported." + | |
2644 " Implement or use ignore_assets = true." + | |
2645 " http://crbug.com/643966") | |
2646 assert(_ignore_native_libraries || !_scanned_files.has_native_libraries, | |
2647 "android_aar_prebuilt() with .so files is not supported." + | |
2648 " Use ignore_native_libraries = true to silence this error.") | |
2649 assert(_ignore_manifest || _scanned_files.is_manifest_empty, | |
2650 "android_aar_prebuilt() manifest merging not yet supported and" + | |
2651 " non-trivial AndroidManifest.xml detected." + | |
2652 " Implement or use ignore_manifest = true." + | |
2653 " http://crbug.com/643967") | |
2654 | |
2655 # Create android_java_prebuilt targets for jar files witin jars/. | |
Ian Wen
2016/09/06 19:09:59
s/jars\//libs\/
Also we should move it down to #2
agrieve
2016/09/06 21:00:51
Done.
| |
2656 assert(_scanned_files.has_classes_jar || _scanned_files.subjars == []) | |
2657 | |
2632 action(_unpack_target_name) { | 2658 action(_unpack_target_name) { |
2633 script = "//build/android/gyp/aar.py" # Unzips the AAR | 2659 script = "//build/android/gyp/aar.py" # Unzips the AAR |
2634 args = [ | 2660 args = [ |
2635 "--input-file", | 2661 "--input-file", |
2636 rebase_path(invoker.aar_path, root_build_dir), | 2662 rebase_path(invoker.aar_path, root_build_dir), |
2637 "--output-dir", | 2663 "--output-dir", |
2638 rebase_path(_output_path, root_build_dir), | 2664 rebase_path(_output_path, root_build_dir), |
2639 "--extract", | 2665 "--extract", |
2640 ] | 2666 ] |
2641 inputs = [ | 2667 inputs = [ |
2642 invoker.aar_path, | 2668 invoker.aar_path, |
2643 ] | 2669 ] |
2644 outputs = [ | 2670 outputs = [ |
2645 "${_output_path}/AndroidManifest.xml", | 2671 "${_output_path}/AndroidManifest.xml", |
2646 ] | 2672 ] |
2647 | 2673 |
2648 if (_scanned_files.resources != []) { | 2674 if (_scanned_files.resources != []) { |
2649 outputs += [ "${_output_path}/R.txt" ] | 2675 outputs += [ "${_output_path}/R.txt" ] |
2650 outputs += get_path_info( | 2676 outputs += get_path_info( |
2651 rebase_path(_scanned_files.resources, "", _output_path), | 2677 rebase_path(_scanned_files.resources, "", _output_path), |
2652 "abspath") | 2678 "abspath") |
2653 } | 2679 } |
2654 if (defined(_scanned_files.jars)) { | 2680 if (_scanned_files.has_classes_jar) { |
2655 outputs += | 2681 outputs += [ "${_output_path}/classes.jar" ] |
2656 get_path_info(rebase_path(_scanned_files.jars, "", _output_path), | 2682 } |
2657 "abspath") | 2683 outputs += |
2684 get_path_info(rebase_path(_scanned_files.subjars, "", _output_path), | |
2685 "abspath") | |
2686 if (_scanned_files.has_proguard_flags) { | |
2687 outputs += [ "${_output_path}/proguard.txt" ] | |
2658 } | 2688 } |
2659 } | 2689 } |
2660 | 2690 |
2661 _resource_targets = [] | |
2662 | |
2663 # Create the android_resources target for resources. | 2691 # Create the android_resources target for resources. |
2664 if (_scanned_files.resources != []) { | 2692 if (!_ignore_resources && _scanned_files.resources != []) { |
Ian Wen
2016/09/06 19:09:59
Q: which target do you expect will need to ignore
agrieve
2016/09/06 21:00:51
Just added for completeness. I don't have any targ
| |
2665 _res_target_name = "${target_name}__res" | 2693 _res_target_name = "${target_name}__res" |
2666 _resource_targets += [ ":$_res_target_name" ] | |
2667 android_resources(_res_target_name) { | 2694 android_resources(_res_target_name) { |
2668 forward_variables_from(invoker, [ "deps" ]) | 2695 forward_variables_from(invoker, [ "deps" ]) |
2669 if (!defined(deps)) { | 2696 if (!defined(deps)) { |
2670 deps = [] | 2697 deps = [] |
2671 } | 2698 } |
2672 deps += [ ":$_unpack_target_name" ] | 2699 deps += [ ":$_unpack_target_name" ] |
2673 resource_dirs = [] | 2700 resource_dirs = [] |
2674 generated_resource_dirs = [ "${_output_path}/res" ] | 2701 generated_resource_dirs = [ "${_output_path}/res" ] |
2675 generated_resource_files = | 2702 generated_resource_files = |
2676 rebase_path(_scanned_files.resources, "", _output_path) | 2703 rebase_path(_scanned_files.resources, "", _output_path) |
2677 android_manifest_dep = ":$_unpack_target_name" | 2704 android_manifest_dep = ":$_unpack_target_name" |
2678 android_manifest = "${_output_path}/AndroidManifest.xml" | 2705 android_manifest = "${_output_path}/AndroidManifest.xml" |
2679 v14_skip = true | 2706 v14_skip = true |
2680 } | 2707 } |
2681 } | 2708 } |
2682 | 2709 |
2683 # Create android_java_prebuilt targets for jar files. | 2710 _subjar_targets = [] |
Ian Wen
2016/09/06 19:09:59
Nit: either keep this line or remove #2663 as well
agrieve
2016/09/06 21:00:51
Done.
| |
2684 _jar_targets = [] | 2711 foreach(_jar_subpath, _scanned_files.subjars) { |
2685 _counter = 0 | 2712 if (!defined(_counter)) { |
Ian Wen
2016/09/06 19:09:59
Q: Is this considered as a better practice to guar
agrieve
2016/09/06 21:00:51
No. The reason for this change is a bit confusing.
| |
2686 foreach(jar, _scanned_files.jars) { | 2713 _counter = 0 |
2687 _counter += 1 | 2714 } else { |
2688 _current_target = "${target_name}__jar_$_counter" | 2715 _counter += 1 |
2689 _jar_targets += [ ":$_current_target" ] | 2716 } |
2717 _labels = _scanned_files.subjar_labels | |
2718 _current_target = "${target_name}__subjar_${_labels[_counter]}" | |
2719 _subjar_targets += [ ":$_current_target" ] | |
2690 java_prebuilt(_current_target) { | 2720 java_prebuilt(_current_target) { |
2691 forward_variables_from(invoker, | 2721 forward_variables_from(invoker, |
2692 [ | 2722 [ |
2723 "jar_excluded_patterns", | |
2724 "requires_android", | |
2725 ]) | |
2726 deps = [ | |
2727 ":$_unpack_target_name", | |
2728 ] | |
2729 if (!defined(requires_android)) { | |
2730 requires_android = true | |
2731 } | |
2732 supports_android = true | |
2733 jar_path = "$_output_path/$_jar_subpath" | |
2734 } | |
2735 } | |
2736 | |
2737 if (_scanned_files.has_classes_jar) { | |
2738 _jar_target_name = "${target_name}__classes" | |
2739 java_prebuilt(_jar_target_name) { | |
2740 forward_variables_from(invoker, | |
2741 [ | |
2693 "deps", | 2742 "deps", |
2694 "input_jars_paths", | 2743 "input_jars_paths", |
2695 "jar_excluded_patterns", | 2744 "jar_excluded_patterns", |
2696 "proguard_configs", | 2745 "proguard_configs", |
2697 "requires_android", | 2746 "requires_android", |
2698 ]) | 2747 ]) |
2699 if (!defined(deps)) { | 2748 if (!defined(deps)) { |
2700 deps = [] | 2749 deps = [] |
2701 } | 2750 } |
2702 deps += _resource_targets + [ ":$_unpack_target_name" ] | 2751 deps += _subjar_targets + [ ":$_unpack_target_name" ] |
2752 if (defined(_res_target_name)) { | |
2753 deps += [ ":$_res_target_name" ] | |
2754 } | |
2703 if (!defined(requires_android)) { | 2755 if (!defined(requires_android)) { |
2704 requires_android = true | 2756 requires_android = true |
2705 } | 2757 } |
2706 supports_android = true | 2758 supports_android = true |
2707 jar_path = "${_output_path}/$jar" | 2759 jar_path = "$_output_path/classes.jar" |
2760 | |
2761 if (_scanned_files.has_proguard_flags) { | |
2762 if (!defined(proguard_configs)) { | |
2763 proguard_configs = [] | |
2764 } | |
2765 proguard_configs += [ "$_output_path/proguard.txt" ] | |
2766 } | |
2708 } | 2767 } |
2709 } | 2768 } |
2710 | 2769 |
2711 java_group(target_name) { | 2770 java_group(target_name) { |
2712 deps = _resource_targets + _jar_targets | 2771 deps = [] |
2772 if (defined(_jar_target_name)) { | |
2773 deps += [ ":$_jar_target_name" ] | |
2774 | |
2775 # Although subjars are meant to be private, we add them as deps here | |
2776 # because in practice they seem to contain classes required to be in the | |
2777 # classpath. | |
2778 deps += _subjar_targets | |
2779 } | |
2780 if (defined(_res_target_name)) { | |
2781 deps += [ ":$_res_target_name" ] | |
2782 } | |
2713 } | 2783 } |
2714 } | 2784 } |
2715 } | 2785 } |
OLD | NEW |