• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
22def find_java_toolchain(ctx, target):
23    """
24    Finds the Java toolchain.
25
26    If the Java toolchain is in use, returns it.  Otherwise, returns a Java
27    toolchain derived from legacy toolchain selection.
28
29    Args:
30      ctx: The rule context for which to find a toolchain.
31      target: A java_toolchain target (for legacy toolchain resolution).
32
33    Returns:
34      A JavaToolchainInfo.
35    """
36
37    _ignore = [ctx]  # buildifier: disable=unused-variable
38
39    return target[java_common.JavaToolchainInfo]
40
41def find_java_runtime_toolchain(ctx, target):
42    """
43    Finds the Java runtime.
44
45    If the Java toolchain is in use, returns it.  Otherwise, returns a Java
46    runtime derived from legacy toolchain selection.
47
48    Args:
49      ctx: The rule context for which to find a toolchain.
50      target: A java_runtime target (for legacy toolchain resolution).
51
52    Returns:
53      A JavaRuntimeInfo.
54    """
55
56    _ignore = [ctx]  # buildifier: disable=unused-variable
57
58    return target[java_common.JavaRuntimeInfo]
59