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