Skip to content

Commit 68f74f7

Browse files
committed
[bazel] Check Bazel version when found in PATH
The `bazelisk.sh` script will try to use a real Bazel from the `PATH` if it can find it, but doesn't check its value against `.bazelversion`. This change checks the version and falls back to downloading `bazelisk` if it doesn't match. Signed-off-by: James Wainwright <[email protected]>
1 parent de8d982 commit 68f74f7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

bazelisk.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ function main() {
110110
local file="${BAZEL_BIN:-${bindir}/bazelisk}"
111111
local lockfile="${bindir}/bazelisk.lock"
112112

113+
# If the user has Bazel in their PATH, check its version.
114+
# Fallback to bazelisk if it doesn't match.
115+
if [ -x "$BAZEL_BIN" ]; then
116+
if [ "$("$BAZEL_BIN" --version)" != "bazel $(cat .bazelversion)" ]; then
117+
file="${bindir}/bazelisk"
118+
fi
119+
fi
120+
113121
# Are we using bazel from the user's PATH or using bazelisk?
114122
if expr match "${file}" ".*bazelisk$" >/dev/null; then
115123
if ! up_to_date "$file"; then

0 commit comments

Comments
 (0)