From 2d1861a4ee792c03a0caf3bae28ff9719d7845c3 Mon Sep 17 00:00:00 2001 From: Romain Jobredeaux Date: Fri, 14 Apr 2023 11:49:32 -0400 Subject: Allow sdk transition wrappers in exports of aar_import. The Bazel Android rules hard-code the names of rule types that can be exported by an aar_import rule, but the AOSP-specific wrappers we've written don't match the names, even though they are equally valid for export. Test: Presubmits Change-Id: I14cf50ec553380d377a685b65e5eac4404c64f9a --- rules/android/aar_import.bzl | 2 +- rules/android/aar_import_aosp_internal/BUILD.bazel | 0 rules/android/aar_import_aosp_internal/attrs.bzl | 40 ++++++++++++++++++++++ rules/android/aar_import_aosp_internal/rule.bzl | 33 ++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 rules/android/aar_import_aosp_internal/BUILD.bazel create mode 100644 rules/android/aar_import_aosp_internal/attrs.bzl create mode 100644 rules/android/aar_import_aosp_internal/rule.bzl diff --git a/rules/android/aar_import.bzl b/rules/android/aar_import.bzl index e93a821f..76abef03 100644 --- a/rules/android/aar_import.bzl +++ b/rules/android/aar_import.bzl @@ -14,7 +14,7 @@ """Macro wrapping the aar_import for bp2build. """ -load("@rules_android//rules:rules.bzl", _aar_import = "aar_import") +load("//build/bazel/rules/android/aar_import_aosp_internal:rule.bzl", _aar_import = "aar_import") load("//build/bazel/rules/java:sdk_transition.bzl", "sdk_transition", "sdk_transition_attrs") # TODO(b/277801336): document these attributes. diff --git a/rules/android/aar_import_aosp_internal/BUILD.bazel b/rules/android/aar_import_aosp_internal/BUILD.bazel new file mode 100644 index 00000000..e69de29b diff --git a/rules/android/aar_import_aosp_internal/attrs.bzl b/rules/android/aar_import_aosp_internal/attrs.bzl new file mode 100644 index 00000000..1b685b3f --- /dev/null +++ b/rules/android/aar_import_aosp_internal/attrs.bzl @@ -0,0 +1,40 @@ +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load( + "@rules_android//rules:attrs.bzl", + _attrs = "attrs", +) +load( + "@rules_android//rules/aar_import:attrs.bzl", + _BASE_ATTRS = "ATTRS", +) + +ATTRS = _attrs.replace( + _BASE_ATTRS, + exports = attr.label_list( + allow_files = False, + allow_rules = [ + "aar_import", + "java_import", + "kt_jvm_import", + "aar_import_sdk_transition", + "java_import_sdk_transition", + "kt_jvm_import_sdk_transition", + ], + doc = "The closure of all rules reached via `exports` attributes are considered " + + "direct dependencies of any rule that directly depends on the target with " + + "`exports`. The `exports` are not direct deps of the rule they belong to.", + ), +) diff --git a/rules/android/aar_import_aosp_internal/rule.bzl b/rules/android/aar_import_aosp_internal/rule.bzl new file mode 100644 index 00000000..79580f2a --- /dev/null +++ b/rules/android/aar_import_aosp_internal/rule.bzl @@ -0,0 +1,33 @@ +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""aar_import rule.""" + +load(":attrs.bzl", _ATTRS = "ATTRS") +load("@rules_android//rules/aar_import:impl.bzl", _impl = "impl") +load("@rules_android//rules/aar_import:rule.bzl", "RULE_DOC") + +aar_import = rule( + attrs = _ATTRS, + fragments = ["android"], + implementation = _impl, + doc = RULE_DOC, + provides = [ + AndroidIdeInfo, + AndroidLibraryResourceClassJarProvider, + AndroidNativeLibsInfo, + JavaInfo, + ], + toolchains = ["@rules_android//toolchains/android:toolchain_type"], +) -- cgit v1.2.3