From b31ecf806c73c62fa0a01fb6721be120f650ba0c Mon Sep 17 00:00:00 2001 From: hvd Date: Thu, 16 Nov 2023 15:59:08 +0100 Subject: [PATCH] Update handling of `JavaInfo.compilation_info.javac_opts` In order to use the helper utility method from `@rules_java`, this also needed the following additional changes: - Update rules_java version to 7.2.0 (the first version that has the utility) - Update bazel version(s) (the new rules_java requires a bazel version >= 6.4.0). (in any case, now that bazel 6.4.0 has been released, 6.3.0 is unsupported) - Registering the new java bootstrap toolchains (see https://github.com/bazelbuild/bazel/pull/18262) - rules_java dropped definitions for (non-LTS) jdk 20, replacing it with jdk 21. So used the definitions for jdk21 from rules_java and updated the local jdk21 definitions back to jdk20. Happy to split these changes off into separate PRs if it would make review easier. --- .bazelminversion | 2 +- .bazelversion | 2 +- external.bzl | 38 +++++++++++-------- .../kythe/extractors/java/bazel/BUILD | 1 + .../kythe/extractors/java/bazel/aspect.bzl | 6 ++- .../kythe/extractors/java/standalone/BUILD | 1 + .../extractors/java/standalone/aspect.bzl | 6 ++- setup.bzl | 6 +-- version.bzl | 4 +- 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.bazelminversion b/.bazelminversion index 798e38995c4..19b860c1872 100644 --- a/.bazelminversion +++ b/.bazelminversion @@ -1 +1 @@ -6.3.0 +6.4.0 diff --git a/.bazelversion b/.bazelversion index 798e38995c4..19b860c1872 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.3.0 +6.4.0 diff --git a/external.bzl b/external.bzl index 9fd1a38b0d4..2013837ab0a 100644 --- a/external.bzl +++ b/external.bzl @@ -21,8 +21,9 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende load( "@rules_java//java:repositories.bzl", "remote_jdk17_repos", - "remote_jdk20_repos", + "remote_jdk21_repos", "rules_java_dependencies", + "rules_java_toolchains", ) load("@rules_java//toolchains:remote_java_repository.bzl", "remote_java_repository") load("@rules_jvm_external//:defs.bzl", "maven_install") @@ -43,13 +44,20 @@ def _rule_dependencies(): remote_jdk19_repos() remote_jdk20_repos() remote_jdk21_repos() - native.register_toolchains("@local_jdk//:runtime_toolchain_definition") + native.register_toolchains( + "@local_jdk//:runtime_toolchain_definition", + "@local_jdk//:bootstrap_runtime_toolchain_definition", + ) for version in ("11", "17", "19", "20", "21"): for platform in ("linux", "macos", "win"): - native.register_toolchains("@remotejdk{version}_{platform}_toolchain_config_repo//:toolchain".format( + repo = "@remotejdk{version}_{platform}_toolchain_config_repo".format( version = version, platform = platform, - )) + ) + native.register_toolchains( + repo + "//:toolchain", + repo + "//:bootstrap_runtime_toolchain", + ) native.register_toolchains("//buildenv/java:all") protobuf_deps() @@ -1929,38 +1937,38 @@ def remote_jdk19_repos(): version = "19.32.13-ca-jdk19.0.2", ) -def remote_jdk21_repos(): - """Imports OpenJDK 21 repositories.""" +def remote_jdk20_repos(): + """Imports OpenJDK 20 repositories.""" maybe( _remote_jdk_repository, - name = "remotejdk21_linux", + name = "remotejdk20_linux", os = "linux", cpu = "x86_64", - version = "21.28.85-ca-jdk21.0.0", - sha256 = "0c0eadfbdc47a7ca64aeab51b9c061f71b6e4d25d2d87674512e9b6387e9e3a6", + version = "20.28.85-ca-jdk20.0.0", + sha256 = "0386418db7f23ae677d05045d30224094fc13423593ce9cd087d455069893bac", ) maybe( _remote_jdk_repository, - name = "remotejdk21_macos", + name = "remotejdk20_macos", os = "macos", cpu = "x86_64", - version = "21.28.85-ca-jdk21.0.0", + version = "20.28.85-ca-jdk20.0.0", ) maybe( _remote_jdk_repository, - name = "remotejdk21_macos_aarch64", + name = "remotejdk20_macos_aarch64", os = "macos", cpu = "aarch64", - version = "21.28.85-ca-jdk21.0.0", + version = "20.28.85-ca-jdk20.0.0", ) maybe( _remote_jdk_repository, - name = "remotejdk21_win", + name = "remotejdk20_win", os = "windows", cpu = "x86_64", - version = "21.28.85-ca-jdk21.0.0", + version = "20.28.85-ca-jdk20.0.0", ) diff --git a/kythe/java/com/google/devtools/kythe/extractors/java/bazel/BUILD b/kythe/java/com/google/devtools/kythe/extractors/java/bazel/BUILD index a83437ac4a4..1459c9e4d70 100644 --- a/kythe/java/com/google/devtools/kythe/extractors/java/bazel/BUILD +++ b/kythe/java/com/google/devtools/kythe/extractors/java/bazel/BUILD @@ -33,4 +33,5 @@ java_binary( bzl_library( name = "aspect_bzl", srcs = ["aspect.bzl"], + deps = ["@rules_java//java:utils"], ) diff --git a/kythe/java/com/google/devtools/kythe/extractors/java/bazel/aspect.bzl b/kythe/java/com/google/devtools/kythe/extractors/java/bazel/aspect.bzl index 86bd4320b0f..a3876708949 100644 --- a/kythe/java/com/google/devtools/kythe/extractors/java/bazel/aspect.bzl +++ b/kythe/java/com/google/devtools/kythe/extractors/java/bazel/aspect.bzl @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +load("@rules_java//java:java_utils.bzl", _java_utils = "utils") _mnemonic = "Javac" @@ -34,6 +35,9 @@ def _extract_java(target, ctx): compilation = info.compilation_info annotations = info.annotation_processing + # compilation.javac_options may be a depset + javac_options = _java_utils.tokenize_javacopts(ctx, compilation.javac_options) + source_files = [] for src in ctx.rule.files.srcs: source_files.append(src.path) @@ -61,7 +65,7 @@ def _extract_java(target, ctx): outputjar = output_jar, classpath = classpath, source_file = source_files, - javac_opt = compilation.javac_options, + javac_opt = javac_options, processor = processors, processorpath = processorpath, bootclasspath = bootclasspath, diff --git a/kythe/java/com/google/devtools/kythe/extractors/java/standalone/BUILD b/kythe/java/com/google/devtools/kythe/extractors/java/standalone/BUILD index 0c45427650f..c118ef17abb 100644 --- a/kythe/java/com/google/devtools/kythe/extractors/java/standalone/BUILD +++ b/kythe/java/com/google/devtools/kythe/extractors/java/standalone/BUILD @@ -177,4 +177,5 @@ java_library( bzl_library( name = "aspect_bzl", srcs = ["aspect.bzl"], + deps = ["@rules_java//java:utils"], ) diff --git a/kythe/java/com/google/devtools/kythe/extractors/java/standalone/aspect.bzl b/kythe/java/com/google/devtools/kythe/extractors/java/standalone/aspect.bzl index eebcc1d2f06..e645df65670 100644 --- a/kythe/java/com/google/devtools/kythe/extractors/java/standalone/aspect.bzl +++ b/kythe/java/com/google/devtools/kythe/extractors/java/standalone/aspect.bzl @@ -13,6 +13,7 @@ # limitations under the License. load("//tools/build_rules/verifier_test:verifier_test.bzl", "extract") +load("@rules_java//java:java_utils.bzl", _java_utils = "utils") def _extract_java_aspect(target, ctx): if JavaInfo not in target or not hasattr(ctx.rule.attr, "srcs"): @@ -24,6 +25,9 @@ def _extract_java_aspect(target, ctx): compilation = info.compilation_info annotations = info.annotation_processing + # compilation.javac_options may be a depset + javac_options = _java_utils.tokenize_javacopts(ctx, compilation.javac_options) + classpath = [j.path for j in compilation.compilation_classpath] bootclasspath = [j.path for j in compilation.boot_classpath] @@ -34,7 +38,7 @@ def _extract_java_aspect(target, ctx): processors = annotations.processor_classnames # Skip --release options; -source/-target/-bootclasspath are already set - args = _remove_flags(compilation.javac_options, {"--release": 1}) + [ + args = _remove_flags(javac_options, {"--release": 1}) + [ "-cp", ":".join(classpath), "-bootclasspath", diff --git a/setup.bzl b/setup.bzl index 6f6d63cca43..d163c16a138 100644 --- a/setup.bzl +++ b/setup.bzl @@ -70,10 +70,10 @@ def kythe_rule_repositories(): name = "rules_java", urls = [ # Note: when updating rules_java, please check if the ModuleName check in tools/javacopts.bazelrc can be re-enabled. - "https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/6.5.1/rules_java-6.5.1.tar.gz", - "https://github.com/bazelbuild/rules_java/releases/download/6.5.1/rules_java-6.5.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/7.2.0/rules_java-7.2.0.tar.gz", + "https://github.com/bazelbuild/rules_java/releases/download/7.2.0/rules_java-7.2.0.tar.gz", ], - sha256 = "7b0d9ba216c821ee8697dedc0f9d0a705959ace462a3885fe9ba0347ba950111", + sha256 = "eb7db63ed826567b2ceb1ec53d6b729e01636f72c9f5dfb6d2dfe55ad69d1d2a", ) maybe( diff --git a/version.bzl b/version.bzl index 0559dd548f9..20964554743 100644 --- a/version.bzl +++ b/version.bzl @@ -1,8 +1,8 @@ # Minimum supported Bazel version. Should match .bazelminversion file. -MIN_VERSION = "6.3.0" +MIN_VERSION = "6.4.0" # Maximum supported Bazel version. Should match .bazelversion file. -MAX_VERSION = "6.3.0" +MAX_VERSION = "6.4.0" def _tuplicate(value, delim): rv = ()