1# Copyright (C) 2023 The Android Open Source Project 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"""Macro wrapping the aar_import for bp2build. """ 16 17load("//build/bazel/rules/android/aar_import_aosp_internal:rule.bzl", _aar_import = "aar_import") 18load("//build/bazel/rules/java:sdk_transition.bzl", "sdk_transition", "sdk_transition_attrs") 19 20# TODO(b/277801336): document these attributes. 21def aar_import( 22 name = "", 23 aar = [], 24 sdk_version = None, 25 deps = [], 26 tags = [], 27 target_compatible_with = [], 28 visibility = None, 29 **kwargs): 30 lib_name = name + "_private" 31 _aar_import( 32 name = lib_name, 33 aar = aar, 34 deps = deps, 35 tags = tags + ["manual"], 36 target_compatible_with = target_compatible_with, 37 visibility = ["//visibility:private"], 38 **kwargs 39 ) 40 41 aar_import_sdk_transition( 42 name = name, 43 sdk_version = sdk_version, 44 java_version = None, 45 exports = lib_name, 46 tags = tags, 47 target_compatible_with = target_compatible_with, 48 visibility = visibility, 49 ) 50 51# The list of providers to forward was determined using cquery on one 52# of the example targets listed under EXAMPLE_WRAPPER_TARGETS at 53# //build/bazel/ci/target_lists.sh. It may not be exhaustive. A unit 54# test ensures that the wrapper's providers and the wrapped rule's do 55# match. 56def _aar_import_sdk_transition_impl(ctx): 57 return [ 58 ctx.attr.exports[0][AndroidLibraryResourceClassJarProvider], 59 ctx.attr.exports[0][JavaInfo], 60 ctx.attr.exports[0][AndroidNativeLibsInfo], 61 ctx.attr.exports[0][ProguardSpecProvider], 62 ctx.attr.exports[0][AndroidIdeInfo], 63 ctx.attr.exports[0][DefaultInfo], 64 ] 65 66aar_import_sdk_transition = rule( 67 implementation = _aar_import_sdk_transition_impl, 68 attrs = sdk_transition_attrs, 69 provides = [ 70 AndroidIdeInfo, 71 AndroidLibraryResourceClassJarProvider, 72 AndroidNativeLibsInfo, 73 JavaInfo, 74 ], 75) 76