Skip to content

Commit

Permalink
Propage DEFAULT_SYSTEM_JAVABASE via module extension tag
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorcloudy committed Nov 10, 2021
1 parent 4888a6e commit d624bcd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 12 additions & 2 deletions java/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)
9 changes: 5 additions & 4 deletions java/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)

Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions toolchains/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load(
"DEFAULT_TOOLCHAIN_CONFIGURATION",
"JVM8_TOOLCHAIN_CONFIGURATION",
"PREBUILT_TOOLCHAIN_CONFIGURATION",
"bootclasspath",
"default_java_toolchain",
"java_runtime_files",
)
Expand Down

0 comments on commit d624bcd

Please sign in to comment.