xref: /aosp_15_r20/build/bazel/rules/android/android_library_aosp_internal/attrs.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(
18    "@rules_android//rules:attrs.bzl",
19    _attrs = "attrs",
20)
21load(
22    "@rules_android//rules/android_library:attrs.bzl",
23    _BASE_ATTRS = "ATTRS",
24)
25load("@rules_kotlin//kotlin:compiler_opt.bzl", "kotlincopts_attrs")
26load("@rules_kotlin//kotlin:traverse_exports.bzl", _kt_traverse_exports = "kt_traverse_exports")
27
28_KT_COMPILER_ATTRS = _attrs.add(
29    kotlincopts_attrs(),
30    dict(
31        common_srcs = attr.label_list(
32            allow_files = [".kt"],
33            doc = """The list of common multi-platform source files that are processed to create
34                 the target.""",
35        ),
36        coverage_srcs = attr.label_list(allow_files = True),
37        # Magic attribute name for DexArchiveAspect
38        _toolchain = attr.label(
39            default = Label(
40                "//build/bazel/rules/kotlin:kt_jvm_toolchain_linux_jdk",
41            ),
42        ),
43    ),
44)
45
46ATTRS = _attrs.add(
47    _attrs.replace(
48        _BASE_ATTRS,
49        deps = attr.label_list(
50            allow_rules = [
51                "aar_import",
52                "android_library",
53                "cc_library",
54                "java_import",
55                "java_library",
56                "java_lite_proto_library",
57            ],
58            aspects = [
59                _kt_traverse_exports.aspect,
60            ],
61            providers = [
62                [CcInfo],
63                [JavaInfo],
64            ],
65            doc = (
66                "The list of other libraries to link against. Permitted library types " +
67                "are: `android_library`, `java_library` with `android` constraint and " +
68                "`cc_library` wrapping or producing `.so` native libraries for the " +
69                "Android target platform."
70            ),
71        ),
72        exported_plugins = attr.label_list(
73            allow_rules = [
74                "java_plugin",
75            ],
76            cfg = "exec",
77        ),
78        exports = attr.label_list(
79            allow_rules = [
80                "aar_import",
81                "android_library",
82                "cc_library",
83                "java_import",
84                "java_library",
85                "java_lite_proto_library",
86            ],
87            aspects = [
88                _kt_traverse_exports.aspect,
89            ],
90            providers = [
91                [CcInfo],
92                [JavaInfo],
93            ],
94            doc = (
95                "The closure of all rules reached via `exports` attributes are considered " +
96                "direct dependencies of any rule that directly depends on the target with " +
97                "`exports`. The `exports` are not direct deps of the rule they belong to."
98            ),
99        ),
100        exports_manifest = _attrs.tristate.create(
101            default = _attrs.tristate.no,
102            doc = (
103                "Whether to export manifest entries to `android_binary` targets that " +
104                "depend on this target. `uses-permissions` attributes are never exported."
105            ),
106        ),
107        plugins = attr.label_list(
108            providers = [
109                [JavaPluginInfo],
110            ],
111            cfg = "exec",
112            doc = (
113                "Java compiler plugins to run at compile-time. Every `java_plugin` " +
114                "specified in the plugins attribute will be run whenever this target " +
115                "is built. Resources generated by the plugin will be included in " +
116                "the result jar of the target."
117            ),
118        ),
119        srcs = attr.label_list(
120            allow_files = [
121                ".kt",
122                ".java",
123                ".srcjar",
124            ],
125        ),
126    ),
127    _KT_COMPILER_ATTRS,
128)
129