Created
January 3, 2024 09:12
-
-
Save recht/79eb122f24067c2cf560e6747c3f9c71 to your computer and use it in GitHub Desktop.
Bazel wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made some improvements/simplifications to this https://gist.github.com/ptxmac/75620c520c75d32e7cc74836f67b863b
command_log
instead of piping (return of the colors!)tools/bazel
pattern so it will automatically replace bazel just by being in the correct path