diff --git a/README.md b/README.md index 2771d1a4..8eba4040 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,9 @@ The following variables can be set: - `BAZELISK_NOJDK` - `BAZELISK_CLEAN` - `BAZELISK_GITHUB_TOKEN` +- `BAZELISK_HOME_DARWIN` +- `BAZELISK_HOME_LINUX` +- `BAZELISK_HOME_WINDOWS` - `BAZELISK_HOME` - `BAZELISK_INCOMPATIBLE_FLAGS` - `BAZELISK_SHOW_PROGRESS` @@ -198,6 +201,8 @@ Configuration variables are evaluated with precedence order. The preferred value * Variables defined in the workspace root `.bazeliskrc` * Variables defined in the user home `.bazeliskrc` +Additionally, the Bazelisk home directory is also evaluated in precedence order. The preferred value is OS-specific e.g. `BAZELISK_HOME_LINUX`, then we fall back to `BAZELISK_HOME`. + ## Requirements For ease of use, the Python version of Bazelisk is written to work with Python 2.7 and 3.x and only uses modules provided by the standard library. diff --git a/core/core.go b/core/core.go index be99e56c..7a8cf220 100644 --- a/core/core.go +++ b/core/core.go @@ -214,7 +214,11 @@ func getBazelCommand(args []string) (string, error) { // getBazeliskHome returns the path to the Bazelisk home directory. func getBazeliskHome(config config.Config) (string, error) { - bazeliskHome := config.Get("BAZELISK_HOME") + bazeliskHome := config.Get("BAZELISK_HOME_" + strings.ToUpper(runtime.GOOS)) + if len(bazeliskHome) == 0 { + bazeliskHome = config.Get("BAZELISK_HOME") + } + if len(bazeliskHome) == 0 { userCacheDir, err := os.UserCacheDir() if err != nil {