Skip to content

Commit

Permalink
[bazel] Hotswap deprecated sync command in bazelisk.sh
Browse files Browse the repository at this point in the history
This command has been deprecated when using Bzlmod. It only works with
`WORKSPACE` and hybrid mode. For some reason Bazel completely crashes
with a JVM exception when you try to use it rather than printing a nice
warning.

This commit prints a warning that `sync` is deprecated and swaps the
command for `fetch` which has almost identical arguments.

This is a temporary measure to prevent breaking contributors who have
git post-checkout hooks installed which run `bazel sync --configure`.

Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
  • Loading branch information
jwnrt committed Jan 13, 2025
1 parent 532e1a9 commit 09fd344
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bazelisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ function main() {
# We are intentionally using $command_template as a format string.
eval "$(printf "$command_template" "$outfile")"
;;
sync)
# The `sync` command has been disabled when using Bzlmod in favour of
# `fetch`. For some reason Bazel crashes when you try to use `sync`
# rather than printing a helpful error message.
#
# When run interactively, print a deprecation error and exit.
# When run in a script, intercept `sync` commands and forward them
# to `fetch` which is more or less identical. This ensures Git hooks
# will continue working on this branch and older branches which do
# not support `bazel fetch --configure` yet.
if [ -t 0 ]; then
echo 'ERROR: The `bazel sync` command has been deprecated.' >&2
echo ' Use `bazel fetch` instead.' >&2
exit 1
else
shift
exec "$file" "${pre_cmd_args[@]}" fetch "$@"
fi
;;
*)
exec "$file" "${pre_cmd_args[@]}" "$@"
;;
Expand Down

0 comments on commit 09fd344

Please sign in to comment.