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