From d624bcd206e886a11b8d48dc58bf88346a1a776d Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Wed, 10 Nov 2021 16:08:34 +0100 Subject: [PATCH] Propage DEFAULT_SYSTEM_JAVABASE via module extension tag --- MODULE.bazel | 1 + java/extensions.bzl | 14 ++++++++++++-- java/repositories.bzl | 9 +++++---- toolchains/BUILD | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 45fd05d5..5025fae4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -29,6 +29,7 @@ bazel_dep(name = "rules_proto", version = "4.0.0") bazel_dep(name = "rules_python", version = "0.4.0") toolchains = use_extension("//java:extensions.bzl", "toolchains") +toolchains.system_javabase(path=DEFAULT_SYSTEM_JAVABASE) # Declare remote java tools repos use_repo(toolchains, "remote_java_tools") diff --git a/java/extensions.bzl b/java/extensions.bzl index fc04283e..468207fd 100644 --- a/java/extensions.bzl +++ b/java/extensions.bzl @@ -15,12 +15,22 @@ load("//java:repositories.bzl", "java_tools_javac11_repos", "local_jdk_repo", "remote_jdk11_repos", "remote_jdk15_repos", "remote_jdk16_repos", "remote_jdk17_repos") +system_javabase = tag_class(attrs = {"path": attr.string()}) + def _toolchains_impl(ctx): - local_jdk_repo() + default_system_javabase = None + for mod in ctx.modules: + if mod.tags.system_javabase: + default_system_javabase = mod.tags.system_javabase[0].path + break + local_jdk_repo(default_system_javabase) java_tools_javac11_repos() remote_jdk11_repos() remote_jdk15_repos() remote_jdk16_repos() remote_jdk17_repos() -toolchains = module_extension(implementation = _toolchains_impl) +toolchains = module_extension( + implementation = _toolchains_impl, + tag_classes = {"system_javabase": system_javabase}, +) diff --git a/java/repositories.bzl b/java/repositories.bzl index fdd60277..bdc5326f 100644 --- a/java/repositories.bzl +++ b/java/repositories.bzl @@ -65,11 +65,10 @@ def java_tools_javac11_repos(): ], ) -def local_jdk_repo(): +def local_jdk_repo(default_system_javabase): local_java_repository( name = "local_jdk", - # TODO: Need to export DEFAULT_SYSTEM_JAVABASE for module extension environment - java_home = DEFAULT_SYSTEM_JAVABASE, + java_home = default_system_javabase, build_file = Label("//toolchains:jdk.BUILD"), ) @@ -376,7 +375,9 @@ def rules_java_dependencies(): Loads the remote repositories used by default in Bazel. """ - local_jdk_repo() + + # TODO: pass DEFAULT_SYSTEM_JAVABASE to local_jdk_repo + # local_jdk_repo() remote_jdk11_repos() remote_jdk15_repos() remote_jdk16_repos() diff --git a/toolchains/BUILD b/toolchains/BUILD index 4f21cbe8..e5f76a8e 100644 --- a/toolchains/BUILD +++ b/toolchains/BUILD @@ -6,6 +6,7 @@ load( "DEFAULT_TOOLCHAIN_CONFIGURATION", "JVM8_TOOLCHAIN_CONFIGURATION", "PREBUILT_TOOLCHAIN_CONFIGURATION", + "bootclasspath", "default_java_toolchain", "java_runtime_files", )