Bazel: Bazel fails to recognize valid $JAVA_HOME on macOS Big Sur

Created on 13 Nov 2020  路  8Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

Bazel fails to recognize valid $JAVA_HOME as a JDK on macOS Big Sur

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

After upgrading to macOS Big Sur, all invocations of bazel output the following and immediately exit:

$ export JAVA_HOME=$(/usr/libexec/java_home -v11)
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
$ bazel build <anything>
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
FATAL: Could not find system javabase. Ensure JAVA_HOME is set, or javac is on your PATH.

What operating system are you running Bazel on?

macOS Big Sur

What's the output of bazel info release?

release 3.7.0-homebrew

Have you found anything relevant by searching the web?

If I'm reading it correctly, the relevant code appears to be here: https://github.com/bazelbuild/bazel/blob/910079bef2a64b06cc17dd912f97a87298de0b9b/src/main/cpp/blaze_util_darwin.cc#L168-L199

Based on that code, I'd hazard a guess that the access check is failing. My JDK does contain a bin/javac executable, which otherwise appears to be working fine.

Other notes

There is a workaround, which makes it appear to me as though bazel is just having some issue verifying the JDK pointed to by the environment variable:

bazel --server_javabase=$JAVA_HOME build <anything>
# works fine
area-java-toolchains more data needed apple team-Rules-Java bug untriaged

All 8 comments

@susinmotion looks like this is about core bazel config, not sure it belongs here? not sure how we're treating the issues from this repo though

Thanks for the quick response, I'll bring it back to Bazel core!

Speaking of which, do you have the capability to transfer issues to bazelbuild/bazel too? That seems like a pretty good route if issues incorrectly get sent there.

The working heuristic is for Apple-related Starlark issues to go here, and Apple-related Java issues to stay in Bazel core. I did not follow this heuristic correctly!

Looks like I can only transfer to the repos I have write access to

image

good to know, thanks for checking that out. So, if you encounter another misplaced issue, what you did is great--if you cc a Bazel team member we can transfer it accordingly!

@oquenchil, the team-Apple label is deprecated. I'm going to return this issue to team-Rules-CPP, since issues pertaining to core Bazel cc rules + Mac belong in that component. Please feel free to move it elsewhere if that description doesn't apply.

More data is needed, we can't reproduce the issue.

@philwo Bazel worked fine on Big Sur so far and setting JAVA_HOME to different paths worked fine, too.

Did a little bit more debugging this morning and found some more info that I think is pointing to the source of my problem:

  • I uninstalled the homebrew version of bazel and reinstalled using the binary installer. That installation of bazel worked fine, so that narrowed it down to an issue with the homebrew version.
  • After scratching my head about that for a while, I re-discovered something I had forgotten -- I apparently at one point brew edited the homebrew bazel formula to omit the openjdk11 dependency, since I didn't want homebrew installing a different/additional version of openjdk than the one I already had on my system.
  • I'm not a homebrew expert, but to my eye it seems like the homebrew bazel formula is apparently forcing bazel to use the homebrew-managed openjdk as seen here.

So it seems like my issue is due to the fact that the homebrew version of the bazel installation is being picky about the specific location of the JDK. I'm not sure if this would be considered a bug with the homebrew bazel formula or WAI (also not sure if that is managed by the bazel team or homebrew team), but my issue is resolved by just using the non-homebrew installation. If this is WAI as far as the homebrew installation is concerned, feel free to close, otherwise I can re-file this as a homebrew issue.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ttsugriy picture ttsugriy  路  3Comments

GaofengCheng picture GaofengCheng  路  3Comments

xinxiao picture xinxiao  路  3Comments

ob picture ob  路  3Comments

mdzoba picture mdzoba  路  3Comments