1*9e965d6fSRomain Jobredeaux# Copyright 2023 The Bazel Authors. All rights reserved. 2*9e965d6fSRomain Jobredeaux# 3*9e965d6fSRomain Jobredeaux# Licensed under the Apache License, Version 2.0 (the "License"); 4*9e965d6fSRomain Jobredeaux# you may not use this file except in compliance with the License. 5*9e965d6fSRomain Jobredeaux# You may obtain a copy of the License at 6*9e965d6fSRomain Jobredeaux# 7*9e965d6fSRomain Jobredeaux# http://www.apache.org/licenses/LICENSE-2.0 8*9e965d6fSRomain Jobredeaux# 9*9e965d6fSRomain Jobredeaux# Unless required by applicable law or agreed to in writing, software 10*9e965d6fSRomain Jobredeaux# distributed under the License is distributed on an "AS IS" BASIS, 11*9e965d6fSRomain Jobredeaux# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9e965d6fSRomain Jobredeaux# See the License for the specific language governing permissions and 13*9e965d6fSRomain Jobredeaux# limitations under the License. 14*9e965d6fSRomain Jobredeaux"""Provides access to the base set of rule adapters with a simple interface.""" 15*9e965d6fSRomain Jobredeaux 16*9e965d6fSRomain Jobredeauxload(":adapters/aar_import.bzl", "aar_import") 17*9e965d6fSRomain Jobredeauxload(":adapters/android_binary.bzl", "android_binary") 18*9e965d6fSRomain Jobredeauxload(":adapters/android_library.bzl", "android_library") 19*9e965d6fSRomain Jobredeauxload(":adapters/android_sdk.bzl", "android_sdk") 20*9e965d6fSRomain Jobredeauxload(":adapters/android_instrumentation_test.bzl", "android_instrumentation_test") 21*9e965d6fSRomain Jobredeauxload(":adapters/apk_import.bzl", "apk_import") 22*9e965d6fSRomain Jobredeauxload(":adapters/java_import.bzl", "java_import") 23*9e965d6fSRomain Jobredeauxload(":adapters/java_library.bzl", "java_library") 24*9e965d6fSRomain Jobredeauxload(":adapters/java_lite_proto_library.bzl", "java_lite_proto_library") 25*9e965d6fSRomain Jobredeauxload(":adapters/proto_library.bzl", "proto_library") 26*9e965d6fSRomain Jobredeauxload(":adapters/proto_lang_toolchain.bzl", "proto_lang_toolchain") 27*9e965d6fSRomain Jobredeaux 28*9e965d6fSRomain Jobredeaux# Visible for testing 29*9e965d6fSRomain JobredeauxADAPTERS = dict( 30*9e965d6fSRomain Jobredeaux aar_import = aar_import, 31*9e965d6fSRomain Jobredeaux android_binary = android_binary, 32*9e965d6fSRomain Jobredeaux android_library = android_library, 33*9e965d6fSRomain Jobredeaux android_sdk = android_sdk, 34*9e965d6fSRomain Jobredeaux android_instrumentation_test = android_instrumentation_test, 35*9e965d6fSRomain Jobredeaux apk_import = apk_import, 36*9e965d6fSRomain Jobredeaux java_import = java_import, 37*9e965d6fSRomain Jobredeaux java_library = java_library, 38*9e965d6fSRomain Jobredeaux java_lite_proto_library = java_lite_proto_library, 39*9e965d6fSRomain Jobredeaux proto_lang_toolchain = proto_lang_toolchain, 40*9e965d6fSRomain Jobredeaux proto_library = proto_library, 41*9e965d6fSRomain Jobredeaux) 42*9e965d6fSRomain Jobredeaux 43*9e965d6fSRomain Jobredeauxdef get(kind, adapters = ADAPTERS): 44*9e965d6fSRomain Jobredeaux return adapters.get(kind, None) 45*9e965d6fSRomain Jobredeaux 46*9e965d6fSRomain Jobredeauxdef get_all_aspect_attrs(adapters = ADAPTERS): 47*9e965d6fSRomain Jobredeaux """The union of all the aspect attrs required by all rule adapters. 48*9e965d6fSRomain Jobredeaux 49*9e965d6fSRomain Jobredeaux The list is used by the aspect to determine the set of attributes to apply on. 50*9e965d6fSRomain Jobredeaux 51*9e965d6fSRomain Jobredeaux Args: 52*9e965d6fSRomain Jobredeaux adapters: The dict of adapters to process. Default value is the base adapter set. 53*9e965d6fSRomain Jobredeaux 54*9e965d6fSRomain Jobredeaux Returns: 55*9e965d6fSRomain Jobredeaux A sorted list of strings, containing the union of all attribute names 56*9e965d6fSRomain Jobredeaux required by the all the rule adapters. 57*9e965d6fSRomain Jobredeaux """ 58*9e965d6fSRomain Jobredeaux attrs = {} 59*9e965d6fSRomain Jobredeaux for adapter in adapters.values(): 60*9e965d6fSRomain Jobredeaux for attr in adapter.aspect_attrs(): 61*9e965d6fSRomain Jobredeaux attrs[attr] = True 62*9e965d6fSRomain Jobredeaux return attrs.keys() 63