Skip to content

Instantly share code, notes, and snippets.

@recht
Created January 3, 2024 09:12
Show Gist options
  • Save recht/79eb122f24067c2cf560e6747c3f9c71 to your computer and use it in GitHub Desktop.
Save recht/79eb122f24067c2cf560e6747c3f9c71 to your computer and use it in GitHub Desktop.
Bazel wrapper
#!/bin/bash
OUT=$HOME/.cache/bazelisk/bazel-bin
if [ ! -f $OUT ]; then
mkdir -p $(dirname $OUT)
OS=linux
if [ "$(uname -s)" != "Linux" ]; then
OS=darwin
fi
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
ARCH=amd64
fi
if command -v curl &> /dev/null; then
curl -L -o $OUT https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-${OS}-${ARCH} -s
else
wget -O $OUT https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-${OS}-${ARCH}
fi
chmod +x $OUT
fi
tempfile=$(mktemp)
trap "rm -f $tempfile" EXIT
$OUT $@ 2> >(tee $tempfile >&2)
res=$?
if [[ $res -gt 0 ]]; then
if grep "missing strict dependencies" $tempfile; then
echo "Bazel failed with missing strict dependencies. Running gazelle, then rerunning."
gazelle
$OUT $@
res=$?
fi
exit $res
else
exit $res
fi
@ptxmac
Copy link

ptxmac commented Feb 24, 2024

I made some improvements/simplifications to this https://gist.github.com/ptxmac/75620c520c75d32e7cc74836f67b863b

  • Uses command_log instead of piping (return of the colors!)
  • Uses the tools/bazel pattern so it will automatically replace bazel just by being in the correct path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment