bazelbuild / bazelisk

A user-friendly launcher for Bazel.
Apache License 2.0
1.95k stars 300 forks source link

.bazelversion not being read in parent directory outside of WORKSPACE #523

Open cpsauer opened 6 months ago

cpsauer commented 6 months ago

Hi wonderful bazelisk folks,

First and foremost, thanks for a stupendous launcher. Bazelisk is really valuable and I really appreciate all the work you've done here.

I'm writing in to report a bug--or at least an instance where the docs are inconsistent with bazelisk's behavior.

The readme says:

Otherwise, if a .bazelversion file exists in the current directory or recursively any parent directory, it will read the file and use the version specified in it.

but Bazelisk seems to stop that search at a workspace boundary rather than any parent directory.

I think the documented behavior is probably the more desirable one. Projects often have a nested test workspace, and it'd be nice to inherit from the parent workspace. At least that was true of https://github.com/Neargye/magic_enum, where this was causing confusion. And I'd imagine any hardcoding of WORKSPACE files might need updating with the bzlmod changes, where a WORKSPACE file is no longer required. (But there might be other good reasons for the other behavior! In that case, the docs could use a change.)

Thanks so much for all you do, Chris (ex-Googler)

avdv commented 2 months ago

I just stumbled over the same issue, but wanted to add that the file is also not read from the current directory if there is no WORKSPACE file.

In our case we want to check the users Bazel version for a start script and print out a warning if it's outside the expected version range, but on CI we want to use a fixed version so a .bazelversion file is created.

This happens before the start script is called, and causes bazelisk to download the latest Bazel version, which will currently result in a version warning, but the start script goes on to create a Bazel project at which point bazelisk switches to the configured version (downloading that) and uses that.

mering commented 1 month ago

Related: #502