xref: /aosp_15_r20/external/bazelbuild-rules_android/toolchains/android/toolchain.bzl (revision 9e965d6fece27a77de5377433c2f7e6999b8cc0b)
1# Copyright 2019 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Android toolchain."""
16
17_ATTRS = dict(
18    aapt2 = attr.label(
19        allow_files = True,
20        cfg = "exec",
21        default = "@androidsdk//:aapt2_binary",
22    ),
23    aar_import_checks = attr.label(
24        allow_single_file = True,
25        cfg = "exec",
26        default = "//src/validations/aar_import_checks",
27        executable = True,
28    ),
29    aar_embedded_jars_extractor = attr.label(
30        allow_files = True,
31        cfg = "exec",
32        default = "@bazel_tools//tools/android:aar_embedded_jars_extractor",
33        executable = True,
34    ),
35    aar_embedded_proguard_extractor = attr.label(
36        allow_files = True,
37        cfg = "exec",
38        default = "@bazel_tools//tools/android:aar_embedded_proguard_extractor",
39        executable = True,
40    ),
41    aar_native_libs_zip_creator = attr.label(
42        allow_files = True,
43        cfg = "exec",
44        default = "@bazel_tools//tools/android:aar_native_libs_zip_creator",
45        executable = True,
46    ),
47    aar_resources_extractor = attr.label(
48        allow_files = True,
49        cfg = "exec",
50        default = "@bazel_tools//tools/android:aar_resources_extractor",
51        executable = True,
52    ),
53    adb = attr.label(
54        allow_files = True,
55        cfg = "exec",
56        default = "@androidsdk//:platform-tools/adb",
57        executable = True,
58    ),
59    add_g3itr_xslt = attr.label(
60        cfg = "exec",
61        default = Label("//tools/android/xslt:add_g3itr.xslt"),
62        allow_files = True,
63    ),
64    android_archive_jar_optimization_inputs_validator = attr.label(
65        allow_files = True,
66        default = "@androidsdk//:fail",
67        cfg = "exec",
68        executable = True,
69    ),
70    android_archive_packages_validator = attr.label(
71        allow_files = True,
72        default = "@androidsdk//:fail",
73        cfg = "exec",
74        executable = True,
75    ),
76    android_kit = attr.label(
77        allow_files = True,
78        cfg = "exec",
79        default = "@androidsdk//:fail",  # TODO: "//src/tools/ak", needs Go
80        executable = True,
81    ),
82    android_resources_busybox = attr.label(
83        allow_files = True,
84        cfg = "exec",
85        default = "@bazel_tools//src/tools/android/java/com/google/devtools/build/android:ResourceProcessorBusyBox_deploy.jar",
86        executable = True,
87    ),
88    apk_to_bundle_tool = attr.label(
89        allow_files = True,
90        cfg = "exec",
91        default = "@androidsdk//:fail",
92        executable = True,
93    ),
94    bundletool = attr.label(
95        allow_files = True,
96        cfg = "exec",
97        default = "//tools/android:bundletool_deploy.jar",
98        executable = True,
99    ),
100    bundletool_module_builder = attr.label(
101        allow_single_file = True,
102        cfg = "exec",
103        default = "//src/tools/bundletool_module_builder",
104        executable = True,
105    ),
106    centralize_r_class_tool = attr.label(
107        allow_files = True,
108        cfg = "exec",
109        default = "@androidsdk//:fail",
110        executable = True,
111    ),
112    data_binding_annotation_processor = attr.label(
113        cfg = "exec",
114        default = "//tools/android:compiler_annotation_processor",
115    ),
116    data_binding_annotation_template = attr.label(
117        default = "//rules:data_binding_annotation_template.txt",
118        allow_files = True,
119    ),
120    data_binding_exec = attr.label(
121        cfg = "exec",
122        default = "@bazel_tools//tools/android:databinding_exec",
123        executable = True,
124    ),
125    desugar = attr.label(
126        cfg = "exec",
127        default = Label("@bazel_tools//tools/android:desugar_java8"),
128        executable = True,
129    ),
130    desugar_java8_extra_bootclasspath = attr.label(
131        allow_files = True,
132        cfg = "exec",
133        default = "@bazel_tools//tools/android:desugar_java8_extra_bootclasspath",
134        executable = True,
135    ),
136    dexbuilder = attr.label(
137        cfg = "exec",
138        default = Label("@bazel_tools//tools/android:dexbuilder"),
139        executable = True,
140    ),
141    dexbuilder_after_proguard = attr.label(
142        cfg = "exec",
143        default = Label("@bazel_tools//tools/android:dexbuilder_after_proguard"),
144        executable = True,
145    ),
146    dexmerger = attr.label(
147        cfg = "exec",
148        default = Label("@bazel_tools//tools/android:dexmerger"),
149        executable = True,
150    ),
151    dexsharder = attr.label(
152        cfg = "exec",
153        default = Label("@bazel_tools//tools/android:dexsharder"),
154        executable = True,
155    ),
156    enforce_min_sdk_floor_tool = attr.label(
157        allow_files = True,
158        cfg = "exec",
159        default = "//src/tools/enforce_min_sdk_floor",
160        executable = True,
161    ),
162    idlclass = attr.label(
163        allow_files = True,
164        cfg = "exec",
165        default = "@bazel_tools//src/tools/android/java/com/google/devtools/build/android/idlclass:IdlClass_deploy.jar",
166        executable = True,
167    ),
168    import_deps_checker = attr.label(
169        allow_files = True,
170        cfg = "exec",
171        default = "@android_tools//:ImportDepsChecker_deploy.jar",
172        executable = True,
173    ),
174    jacocorunner = attr.label(
175        default = "@androidsdk//:fail",
176    ),
177    java_stub = attr.label(
178        allow_files = True,
179        # used in android_local_test
180        default = "@bazel_tools//tools/java:java_stub_template.txt",
181    ),
182    jdeps_tool = attr.label(
183        allow_files = True,
184        cfg = "exec",
185        # used in android_local_test
186        default = "//src/tools/jdeps",
187        executable = True,
188    ),
189    merge_baseline_profiles_tool = attr.label(
190        default = "@androidsdk//:fail",
191        cfg = "exec",
192        executable = True,
193    ),
194    object_method_rewriter = attr.label(
195        allow_files = True,
196        cfg = "exec",
197        default = "@androidsdk//:fail",
198        executable = True,
199    ),
200    proguard_allowlister = attr.label(
201        cfg = "exec",
202        default = "@bazel_tools//tools/jdk:proguard_whitelister",
203        executable = True,
204    ),
205    profgen = attr.label(
206        default = "@androidsdk//:fail",
207        cfg = "exec",
208        executable = True,
209    ),
210    proto_map_generator = attr.label(
211        cfg = "exec",
212        default = "@androidsdk//:fail",
213        allow_files = True,
214        executable = True,
215    ),
216    r8 = attr.label(
217        cfg = "exec",
218        default = "//tools/android:r8_deploy.jar",
219        executable = True,
220        allow_files = True,
221    ),
222    resource_shrinker = attr.label(
223        cfg = "exec",
224        default = "//tools/android:resource_shrinker_deploy.jar",
225        executable = True,
226        allow_files = True,
227    ),
228    res_v3_dummy_manifest = attr.label(
229        allow_files = True,
230        default = "//rules:res_v3_dummy_AndroidManifest.xml",
231    ),
232    res_v3_dummy_r_txt = attr.label(
233        allow_files = True,
234        default = "//rules:res_v3_dummy_R.txt",
235    ),
236    robolectric_template = attr.label(
237        allow_files = True,
238        default = "//rules:robolectric_properties_template.txt",
239    ),
240    sandboxed_sdk_toolbox = attr.label(
241        allow_single_file = True,
242        cfg = "exec",
243        default = "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox:sandboxed_sdk_toolbox_deploy.jar",
244        executable = True,
245    ),
246    shuffle_jars = attr.label(
247        cfg = "exec",
248        default = Label("@bazel_tools//tools/android:shuffle_jars"),
249        executable = True,
250    ),
251    testsupport = attr.label(
252        default = "@bazel_tools//tools/jdk:TestRunner",
253    ),
254    unzip_tool = attr.label(
255        cfg = "exec",
256        default = "//toolchains/android:unzip",
257        executable = True,
258    ),
259    xsltproc_tool = attr.label(
260        cfg = "exec",
261        default = Label("//tools/android/xslt:xslt"),
262        allow_files = True,
263        executable = True,
264    ),
265    zip_tool = attr.label(
266        cfg = "exec",
267        default = "//toolchains/android:zip",
268        executable = True,
269    ),
270    zip_filter = attr.label(
271        cfg = "exec",
272        default = "@bazel_tools//tools/android:zip_filter",
273        executable = True,
274    ),
275    zipper = attr.label(
276        allow_single_file = True,
277        cfg = "exec",
278        default = "@bazel_tools//tools/zip:zipper",
279        executable = True,
280    ),
281    dex_zips_merger = attr.label(
282        cfg = "exec",
283        default = "@bazel_tools//tools/android:merge_dexzips",
284        executable = True,
285    ),
286    java8_legacy_dex = attr.label(
287        allow_single_file = True,
288        cfg = "exec",
289        default = "@bazel_tools//tools/android:java8_legacy_dex",
290    ),
291    build_java8_legacy_dex = attr.label(
292        cfg = "exec",
293        default = "@bazel_tools//tools/android:build_java8_legacy_dex",
294        executable = True,
295    ),
296    dex_list_obfuscator = attr.label(
297        cfg = "exec",
298        default = "@bazel_tools//tools/android:dex_list_obfuscator",
299        executable = True,
300    ),
301)
302
303def _impl(ctx):
304    return [platform_common.ToolchainInfo(
305        **{name: getattr(ctx.attr, name) for name in _ATTRS.keys()}
306    )]
307
308android_toolchain = rule(
309    implementation = _impl,
310    attrs = _ATTRS,
311)
312