Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions java/rules_java_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ http_jar = _http_jar
""",
)

if hasattr(rctx, "repo_metadata"):
return rctx.repo_metadata(reproducible = True)
return None

_compatibility_proxy_repo_rule = repository_rule(
_compatibility_proxy_repo_impl,
# force reruns on server restarts to use correct native.bazel_version
Expand Down
10 changes: 8 additions & 2 deletions toolchains/local_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def _local_java_repository_impl(repository_ctx):
repository_ctx: repository context
"""

repository_metadata = None
if hasattr(repository_ctx, "repo_metadata"):
repository_metadata = repository_ctx.repo_metadata(reproducible = True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a local java repository necessarily reproducible?

We detect the java_home from environment variables if not explicitly set. Even with an explicit java_home, what if it points to a symlink (that can change under us)?

Does it even make sense to cache a local repo like this remotely?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe a repo that has a symlink to a absolute on-host location will get cached in the local repo contents cache but not the remote one (but @fmeum can confirm!)

I do think it would be safer/more obviously correct not to cache this one, but I'd also hope that it's completely lazy and that we don't force/autoregister the autodetecting toolchain for this language the way rules_cc and others do, though I haven't verified :/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should generally be safe to mark such repos reproducible since there "contents" are just the symlink to an absolute path, where the path is determines by attributes.

Whether both caches behave correctly in this case is not something I have checked yet, but if not, that just means they are buggy.


java_home = _determine_java_home(repository_ctx)

local_java_runtime_name = repository_ctx.attr.runtime_name
Expand All @@ -198,7 +202,7 @@ def _local_java_repository_impl(repository_ctx):
"either correct your JAVA_HOME, PATH or specify Java from " +
"remote repository (e.g. --java_runtime_version=remotejdk_11)",
)
return
return repository_metadata

# Detect version
version = repository_ctx.attr.version if repository_ctx.attr.version != "" else _detect_java_version(repository_ctx, java_bin)
Expand All @@ -211,7 +215,7 @@ def _local_java_repository_impl(repository_ctx):
message = "Cannot detect Java version of {java_binary} in {java_home}; " +
"make sure it points to a valid Java executable",
)
return
return repository_metadata

# Prepare BUILD file using "local_java_runtime" macro
if repository_ctx.attr.build_file_content and repository_ctx.attr.build_file:
Expand Down Expand Up @@ -247,6 +251,8 @@ local_java_runtime(
for file in repository_ctx.path(java_home).readdir():
repository_ctx.symlink(file, file.basename)

return repository_metadata

# Build file template, when JDK could not be detected
_AUTO_CONFIG_ERROR_BUILD_TPL = '''load("@rules_java//toolchains:fail_rule.bzl", "fail_rule")
fail_rule(
Expand Down
3 changes: 3 additions & 0 deletions toolchains/remote_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ load("//toolchains:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE")
def _toolchain_config_impl(ctx):
ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name = ctx.name))
ctx.file("BUILD.bazel", ctx.attr.build_file)
if hasattr(ctx, "repo_metadata"):
return ctx.repo_metadata(reproducible = True)
return None

_toolchain_config = repository_rule(
local = True,
Expand Down