• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Copyright (C) 2023 The Android Open Source Project
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15"""
16
17load(":merged_txts_test.bzl", "merged_txts_test_suite")
18load(":sdk_library_test.bzl", "java_sdk_library_test_suite")
19load(":java_system_modules_test.bzl", "java_system_modules_test_suite")
20load(":bootclasspath_test.bzl", "bootclasspath_test_suite")
21load(":versions_test.bzl", "versions_test_suite")
22load(":versions.bzl", "java_versions")
23load(":sdk_transition_test.bzl", "sdk_transition_test_suite")
24load(":host_for_device_test.bzl", "host_for_device_test_suite")
25load("@bazel_skylib//rules:common_settings.bzl", "string_setting")
26load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "DEFAULT_JAVACOPTS", "default_java_toolchain")
27load("@soong_injection//java_toolchain:constants.bzl", "constants")
28
29package(
30    default_visibility = ["//visibility:public"],
31)
32
33java_sdk_library_test_suite(name = "java_sdk_library_tests")
34
35merged_txts_test_suite(name = "merged_txts_tests")
36
37java_system_modules_test_suite(name = "java_system_modules_tests")
38
39bootclasspath_test_suite(name = "bootclasspath_tests")
40
41versions_test_suite(name = "versions_tests")
42
43sdk_transition_test_suite(name = "sdk_transition_tests")
44
45host_for_device_test_suite(name = "host_for_device_test_suite")
46
47string_setting(
48    name = "version",
49    build_setting_default = str(java_versions.get_version()),
50    values = [str(v) for v in java_versions.ALL_VERSIONS],
51)
52
53[
54    config_setting(
55        name = setting,
56        flag_values = {
57            "//build/bazel/rules/java:version": str(java_version),
58        },
59    )
60    for java_version, setting in java_versions.VERSION_TO_CONFIG_SETTING.items()
61]
62
63# There is no need for both host and device java version build settings in a
64# world where every java_*/android_*/kt_* target uses the AOSP-specific
65# wrappers. However, there are targets defined by BUILD.tools files within the
66# Bazel binary that do not use the wrapper. These would inherit their java
67# version from their reverse dependency, which can cause build failures (e.g. an
68# android_library_import with java_version=7 has a tools dependency on a
69# non-wrapped Bazel java_library that uses lambdas). By using a separate host
70# version, we can reset it to its default when in the device configuration, so
71# that a subsequent exec transition will use the default java version.
72string_setting(
73    name = "host_version",
74    build_setting_default = str(java_versions.get_version()),
75    values = [str(v) for v in java_versions.ALL_VERSIONS],
76)
77
78[
79    config_setting(
80        name = "host_" + setting,
81        flag_values = {
82            "//build/bazel/rules/java:host_version": str(java_version),
83        },
84    )
85    for java_version, setting in java_versions.VERSION_TO_CONFIG_SETTING.items()
86]
87
88java_version_select_dict = {
89    "host_" + setting: str(version)
90    for version, setting in java_versions.VERSION_TO_CONFIG_SETTING.items()
91} | {
92    "//conditions:default": str(java_versions.get_version()),
93}
94
95default_java_toolchain(
96    name = "jdk17_host_toolchain_java",
97    # TODO(b/218720643): Support switching between multiple JDKs.
98    java_runtime = "//prebuilts/jdk/jdk17:jdk17_runtime",
99    misc = DEFAULT_JAVACOPTS + constants.CommonJdkFlags,
100    source_version = select(java_version_select_dict),
101    target_version = select(java_version_select_dict),
102    toolchain_definition = False,
103)
104
105toolchain(
106    name = "jdk17_host_toolchain_java_definition",
107    exec_compatible_with = ["//build/bazel/platforms/os:linux"],
108    target_compatible_with = ["//build/bazel/platforms/os:linux"],
109    target_settings = [],
110    toolchain = ":jdk17_host_toolchain_java",
111    toolchain_type = "@bazel_tools//tools/jdk:toolchain_type",
112)
113