Skip to content

Commit

Permalink
Add OS-specific BAZELISK_HOME (#474)
Browse files Browse the repository at this point in the history
* Prefer BAZELISK_HOME with OS postfix

* Fix spelling in README.md

---------

Co-authored-by: Florian Weikert <fwe@google.com>
  • Loading branch information
mzapotoczny and fweikert authored Sep 6, 2024
1 parent 9a2b251 commit 0b27498
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0b27498

Please sign in to comment.