1# Copyright (C) 2022 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. 14load(":java_system_modules.bzl", "SystemInfo") 15 16def _bootclasspath_impl(ctx): 17 infos = [b[JavaInfo] for b in ctx.attr.bootclasspath] 18 java_info = java_common.merge(infos) 19 20 # TODO: b/304657641 - system modules propagate java_info, including compile jars, we could consider consolidating bootclasspaths from system modules for the toolchains 21 bootclasspath_jars = java_info.compile_jars.to_list() 22 23 return java_common.BootClassPathInfo( 24 bootclasspath = bootclasspath_jars, 25 system = ctx.attr.system[SystemInfo].system if ctx.attr.system else None, 26 auxiliary = [jar for b in ctx.attr.auxiliary for jar in b[JavaInfo].compile_jars.to_list()], 27 ) 28 29bootclasspath = rule( 30 implementation = _bootclasspath_impl, 31 attrs = { 32 "bootclasspath": attr.label_list( 33 providers = [JavaInfo], 34 doc = "The list of libraries to use as javac's --bootclasspath argument.", 35 ), 36 "system": attr.label( 37 providers = [SystemInfo], 38 doc = "The java_system_modules target to use as javac's --system argument.", 39 ), 40 "auxiliary": attr.label_list( 41 providers = [JavaInfo], 42 doc = "The list of libraries to include first in javac's --classpath.", 43 ), 44 }, 45 provides = [java_common.BootClassPathInfo], 46 doc = """Provides BootClassPathInfo to a Java toolchain. 47 48the java_common.BootClassPathInfo provider is used by a Java toolchain to 49set javac's --bootclasspath and --system arguments. It can also optionally add 50to the classpath before anything else gets added to it. This rule generates this 51provider from a list of JavaInfo-providing targets for --bootclasspath and 52--classpath, and from a single SystemInfo-providing target for --system. 53""", 54) 55