xref: /aosp_15_r20/external/bazelbuild-rules_android/mobile_install/adapters_base.bzl (revision 9e965d6fece27a77de5377433c2f7e6999b8cc0b)
1# Copyright 2023 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"""Provides access to the base set of rule adapters with a simple interface."""
15
16load(":adapters/aar_import.bzl", "aar_import")
17load(":adapters/android_binary.bzl", "android_binary")
18load(":adapters/android_library.bzl", "android_library")
19load(":adapters/android_sdk.bzl", "android_sdk")
20load(":adapters/android_instrumentation_test.bzl", "android_instrumentation_test")
21load(":adapters/apk_import.bzl", "apk_import")
22load(":adapters/java_import.bzl", "java_import")
23load(":adapters/java_library.bzl", "java_library")
24load(":adapters/java_lite_proto_library.bzl", "java_lite_proto_library")
25load(":adapters/proto_library.bzl", "proto_library")
26load(":adapters/proto_lang_toolchain.bzl", "proto_lang_toolchain")
27
28# Visible for testing
29ADAPTERS = dict(
30    aar_import = aar_import,
31    android_binary = android_binary,
32    android_library = android_library,
33    android_sdk = android_sdk,
34    android_instrumentation_test = android_instrumentation_test,
35    apk_import = apk_import,
36    java_import = java_import,
37    java_library = java_library,
38    java_lite_proto_library = java_lite_proto_library,
39    proto_lang_toolchain = proto_lang_toolchain,
40    proto_library = proto_library,
41)
42
43def get(kind, adapters = ADAPTERS):
44    return adapters.get(kind, None)
45
46def get_all_aspect_attrs(adapters = ADAPTERS):
47    """The union of all the aspect attrs required by all rule adapters.
48
49    The list is used by the aspect to determine the set of attributes to apply on.
50
51    Args:
52      adapters: The dict of adapters to process. Default value is the base adapter set.
53
54    Returns:
55      A sorted list of strings, containing the union of all attribute names
56      required by the all the rule adapters.
57    """
58    attrs = {}
59    for adapter in adapters.values():
60        for attr in adapter.aspect_attrs():
61            attrs[attr] = True
62    return attrs.keys()
63