xref: /aosp_15_r20/build/bazel/rules/android/android_binary_aosp_internal/rule.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1"""
2Copyright (C) 2023 The Android Open Source Project
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15"""
16
17load("@rules_android//rules/android_binary_internal:rule.bzl", "make_rule", "sanitize_attrs")
18load("@rules_android//rules:attrs.bzl", _attrs = "attrs")
19load("@rules_android//rules/android_binary_internal:attrs.bzl", _BASE_ATTRS = "ATTRS", _DEPS_ALLOW_RULES = "DEPS_ALLOW_RULES", _DEPS_ASPECTS = "DEPS_ASPECTS", _DEPS_PROVIDERS = "DEPS_PROVIDERS", _make_deps = "make_deps")
20load(":impl.bzl", "collect_cc_stubs_aspect", _impl = "impl")
21
22def _make_aspects_for_deps(default_deps_aspects = [], additional_aspects = []):
23    """Generates a list of aspects to apply to the android_binary deps attribute.
24
25    Args:
26        default_deps_aspects: A list that contains the default list of aspects for deps. Usually loaded from android_binary_internal:attrs.bzl.
27        additional_aspects: A list of additional aspects to append to the aspects list.
28
29    Returns:
30        A list of aspects to apply to android_binary's deps attr.
31    """
32    aspects = []
33    aspects.extend(default_deps_aspects)
34    aspects.extend(additional_aspects)
35    return aspects
36
37DEPS_ASPECTS = _make_aspects_for_deps(default_deps_aspects = _DEPS_ASPECTS, additional_aspects = [collect_cc_stubs_aspect])
38
39_ATTRS = _attrs.add(
40    _attrs.replace(
41        _BASE_ATTRS,
42        deps = _make_deps(_DEPS_ALLOW_RULES, _DEPS_PROVIDERS, DEPS_ASPECTS),
43    ),
44    dict(
45        _product_config_device_abi = attr.label(
46            default = Label("//build/bazel/product_config:device_abi"),
47            doc = "Implicit attr used to extract target device ABI information (for apk lib naming).",
48        ),
49        _platform_sdk_final = attr.label(
50            default = "//build/bazel/product_config:platform_sdk_final",
51            doc = "PlatformSdkFinal product variable",
52        ),
53        _unbundled_build_apps = attr.label(
54            default = "//build/bazel/product_config:unbundled_build_apps",
55            doc = "UnbundledBuildApps product variable",
56        ),
57        _override_apex_manifest_default_version = attr.label(
58            default = "//build/bazel/rules/apex:override_apex_manifest_default_version",
59            doc = "If the app is updatable, and this attribute is specified, and higher than the value specified in manifest_values, will override minSdkVersion in manifest with this value instead of the value in manifest_values.",
60        ),
61        _manifest_fixer = attr.label(
62            cfg = "exec",
63            executable = True,
64            default = "//build/soong/scripts:manifest_fixer",
65        ),
66        sdk_version = attr.string(
67            doc = "The sdk_version this app should build against.",
68        ),
69        # TODO: b/301425155 - Handle all of the ways updatable affects this rule.
70        updatable = attr.bool(
71            default = False,
72            doc = "Whether this app is updatable.",
73        ),
74    ),
75)
76
77android_binary_aosp_internal = make_rule(attrs = _ATTRS, implementation = _impl)
78
79def android_binary_aosp_internal_macro(**attrs):
80    """android_binary_internal rule.
81
82    Args:
83      **attrs: Rule attributes
84    """
85    android_binary_aosp_internal(**sanitize_attrs(attrs, _ATTRS))
86