Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document precedence of JAVABIN on java_binary rule #18564

Closed
wants to merge 2 commits into from

Conversation

samshadwell
Copy link
Contributor

@samshadwell samshadwell commented Jun 2, 2023

Ran into some confusion around this at work. We recently changed our Bazel repo so that everything was compiling/running with Java 17, but some folks would get issues when bazel runing java_binary targets. Error messages indicated they were still running on a Java 8 VM despite the --java_runtime_version flag.

Looking at where the stub template is filled in, I noticed that JAVABIN environment variable takes precedence over the java_executable: https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary.bzl;l=183?q=javabin&ss=bazel%2Fbazel&start=11

The folks running into issues set their JAVABIN in .zshrc files, so that was taking precedence over the Bazel flags and incorrectly running the Java 17 compiled code on a Java 8 VM. Seems reasonable that JAVABIN take precedence, but I figure this should probably be documented somewhere to save other folks the trouble of digging into the guts to figure out what was going on.

Expand on the precedence of JAVABIN over the runfiles version
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Jun 2, 2023
@fmeum
Copy link
Collaborator

fmeum commented Jun 2, 2023

Good catch. To me this looks like a bug as it is a very unexpected source of non-hermeticity. A wrapper script flag could serve as a less surprising knob for this.

@sgowroji sgowroji added the team-Rules-Java Issues for Java rules label Jun 3, 2023
@samshadwell
Copy link
Contributor Author

Agreed, it was surprising @fmeum! Though I guess the hermiticity expectations of run are maybe a little lower than for build. It might be useful to disable via a flag, but I figured a doc-only change might be the least objectionable way to act on the learning

@fmeum
Copy link
Collaborator

fmeum commented Jun 6, 2023

Yes, thank you very much for fixing the docs!

Looking into https://cs.opensource.google/bazel/bazel/+/b3602eb14cf27494a0a754bc215ec2b94d13d89b:src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java;l=441, this does seem to be intentional.

@samshadwell
Copy link
Contributor Author

@fmeum what's the process for getting this merged? This is my first PR to bazel 😅

@fmeum
Copy link
Collaborator

fmeum commented Jun 9, 2023

I am not a Bazel team member and thus can't review PRs. Your PR got assigned to the Java team for review. Just sit back and wait for someone from that team to review the PR, feel free to ping the PR if that doesn't happen within a reasonable amount of time (say two weeks).

@fmeum
Copy link
Collaborator

fmeum commented Jun 26, 2023

@cushon Could you take a look? This is a docs-only change.

@katre katre added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Jun 27, 2023
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants