1# Copyright 2019 The Bazel Authors. All rights reserved. 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""" 16Finds the Java toolchain. 17 18Returns the toolchain if enabled, and falls back to a toolchain constructed from 19legacy toolchain selection. 20""" 21 22load("//java/common:java_common.bzl", "java_common") 23 24def find_java_toolchain(ctx, target): 25 """ 26 Finds the Java toolchain. 27 28 If the Java toolchain is in use, returns it. Otherwise, returns a Java 29 toolchain derived from legacy toolchain selection. 30 31 Args: 32 ctx: The rule context for which to find a toolchain. 33 target: A java_toolchain target (for legacy toolchain resolution). 34 35 Returns: 36 A JavaToolchainInfo. 37 """ 38 39 _ignore = [ctx] # buildifier: disable=unused-variable 40 41 return target[java_common.JavaToolchainInfo] 42 43def find_java_runtime_toolchain(ctx, target): 44 """ 45 Finds the Java runtime. 46 47 If the Java toolchain is in use, returns it. Otherwise, returns a Java 48 runtime derived from legacy toolchain selection. 49 50 Args: 51 ctx: The rule context for which to find a toolchain. 52 target: A java_runtime target (for legacy toolchain resolution). 53 54 Returns: 55 A JavaRuntimeInfo. 56 """ 57 58 _ignore = [ctx] # buildifier: disable=unused-variable 59 60 return target[java_common.JavaRuntimeInfo] 61