Add make variables for runfiles location of $(JAVABASE) to support --no_legacy_external_runfiles.#272
Add make variables for runfiles location of $(JAVABASE) to support --no_legacy_external_runfiles.#272thirtyseven wants to merge 6 commits intobazelbuild:masterfrom
Conversation
Add make variables for runfiles locations of $(JAVA) and $(JAVABASE). These are needed to access these paths when passing them to test rules via `env`.
|
@meteorcloudy We might want to cherry-pick this into 8.1.0 as it makes it easier to adopt the We could then also document it on the Make variables page. |
|
@fmeum Do you mean bump the rules_java version in MODULE.tools to include this change? End users can also just depend on a newer rules_java to get this? |
That is correct, but if we don't bump the minimum requirement, we can't document these Make variables on the versioned page for 8.1.0. |
|
OK, let's try to get this reviewed first, then let's see if we can make it for Bazel 8.1 @hvadehra Can you take a look? |
hvadehra
left a comment
There was a problem hiding this comment.
Please also add a test for this. Easiest might be to use this somehow in https://github.com/bazelbuild/rules_java/tree/master/test/repo
toolchains/java_toolchain_alias.bzl
Outdated
| platform_common.TemplateVariableInfo({ | ||
| "JAVA": str(toolchain.java_executable_exec_path), | ||
| "JAVABASE": str(toolchain.java_home), | ||
| "JAVA_RUNFILES": str(toolchain.java_executable_runfiles_path), |
There was a problem hiding this comment.
I think we should instead be adding these to
rules_java/java/common/rules/java_runtime.bzl
Line 152 in af504cf
There was a problem hiding this comment.
In order to make this change, I think I would have to make java_runtime_alias and java_host_runtime_alias identical by adding a dependency on //toolchains:current_java_runtime to java_runtime_alias. I can do this, but wanted to make sure it's your intent first.
There was a problem hiding this comment.
My bad, please ignore the bit about just forwarding the provider. But I do think we need to make the same change also in rules_java/java/common/rules/java_runtime.bzl
There was a problem hiding this comment.
I have made the requested changes, however the test I added is failing due to toolchain.java_executable_runfiles_path appearing not to be a valid path in the context of the test. It's returning a path like:
/private/var/tmp/_bazel_thirtyseven/43339e4e51eaab2f90ecf6c85b4023b4/sandbox/darwin-sandbox/49/execroot/_main/../rules_java++toolchains+local_jdk/bin/java
which does not exist when running the test.
I'm not sure if this is due to something missing from my test or if I'm misusing this field, any help would be appreciated.
There was a problem hiding this comment.
I have removed JAVA_RUNFILES from this PR for now. It seemed unlikely that it was going to work as I intended (making a Java executable easily available to test rules).
There was a problem hiding this comment.
Realized I could do something like:
"JAVA_RUNFILES": toolchain.java_home_runfiles_path + "/bin/java",
it's a little ugly but works. Thoughts?
There was a problem hiding this comment.
Does that work? I would think the issue is that JAVA_RUNFILES is a special env var1 so if we'll want to use a different name.
Footnotes
There was a problem hiding this comment.
Not sure what a better name would be, I'm ok with leaving it out letting the user locate bin/java.
|
Please fix the buidifier failure, the sh rules have been moved out of Bazel, so we'll need to load them from |
Load rules_shell Load rules_shell in WORKSPACE mode Buildify WORKSPACE Fix WORKSPACE
java/common/rules/java_runtime.bzl
Outdated
| platform_common.TemplateVariableInfo({ | ||
| "JAVA": java_binary_exec_path, | ||
| "JAVABASE": java_home, | ||
| "JAVABASE_RUNFILES": java_home_runfiles_path, |
There was a problem hiding this comment.
Not adding an equivalent for the java binary makes this difficult to use cross-platform (think Windows).
I don't think the deprecated env var JAVA_RUNFILES would necessarily conflict with a make var. It's something we could likely just get rid of at this point anyway.
But to avoid confusion, how about calling this JAVA_ROOTPATH or JAVABASE_ROOTPATH to match $(rootpath ...)?
There was a problem hiding this comment.
Sure, I've tried to address this.
java/common/rules/java_runtime.bzl
Outdated
| platform_common.TemplateVariableInfo({ | ||
| "JAVA": java_binary_exec_path, | ||
| "JAVABASE": java_home, | ||
| "JAVA_ROOTPATH": paths.join(java_home_runfiles_path, "bin/java"), |
There was a problem hiding this comment.
This won't work on Windows. Could you use java_binary_runfiles_path instead? If that somehow isn't the right path, you could also reuse the basename of the execpath.
There was a problem hiding this comment.
Done, java_binary_runfiles_path does actually work, the earlier issue I had must have been due to the JAVA_RUNFILES name conflict.
Add make variables for runfiles locations of
$(JAVA)and$(JAVABASE). These are needed to access these paths when passing them to test rules viaenvwhen using--no_legacy_external_runfiles. The original make variables still work in exec contexts such as genrules.