blob: 38b74229c7f6134da331fcbe930d9e230e4ba32c [file] [log] [blame]
#!/usr/bin/env bash
source tools/hscloud/lib.sh || exit 1
function main() {
# If we're not running from `bazel run/buld`, complain and re-execute
# ourselves.
#
# We do the check fairly low level, as //tools/hscloud:lib.sh will just
# fail in this case. We want to be nice.
#
# This is all mostly copied from the runfiles.bash snippet in
# tools/hscloud/lib.sh.
f=bazel_tools/tools/bash/runfiles/runfiles.bash
if [ ! -e "${RUNFILES_DIR:-/dev/null}/$f" ] && \
[ ! -e "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" ] && \
[ ! -e "$0.runfiles/$f" ] && \
[ ! -e "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" ] && \
[ ! -e "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" ]; then
echo "Uh-oh, looks like you didn't run this as 'bazel run //tools:install'.">&2
echo "Let me fix that for you in a few seconds - but work on your muscle memory, as we'll stop supporting this by some point.">&2
sleep 2
bazel run //tools:install -- "$@"
exit $?
fi
cd $(hscloud::workspace_location)
echo "Building hscloud tools and cluster tools..."
bazel build //tools/... //cluster/tools/...
local path_missing=""
local path="$(hscloud::workspace_location)/bazel-bin/tools"
if [[ ":$PATH:" != *":$path:"* ]]; then
path_missing="$path"
fi
local path="$(hscloud::workspace_location)/bazel-bin/cluster/tools"
if [[ ":$PATH:" != *":$path:"* ]]; then
if [ -z "$path_missing" ]; then
path_missing="$path"
else
path_missing="$path_missing:$path"
fi
fi
if [ ! -z "$path_missing" ]; then
echo "Tools built correctly, but your PATH should be updated to access them:">&2
echo ' PATH="$PATH:'$path_missing'"'
echo 'Add the above line to your shell profile, or source env.sh from the root of hscloud.'
else
echo "Tools built correctly and in PATH. Happy hsclouding!"
fi
}
main "$@"