blob: 38b74229c7f6134da331fcbe930d9e230e4ba32c [file] [log] [blame]
Sergiusz Bazanskide061802019-01-13 21:14:02 +01001#!/usr/bin/env bash
Serge Bazanski0f8e5a22021-10-16 20:53:51 +00002source tools/hscloud/lib.sh || exit 1
Sergiusz Bazanskide061802019-01-13 21:14:02 +01003
Serge Bazanski0f8e5a22021-10-16 20:53:51 +00004function main() {
5 # If we're not running from `bazel run/buld`, complain and re-execute
6 # ourselves.
7 #
8 # We do the check fairly low level, as //tools/hscloud:lib.sh will just
9 # fail in this case. We want to be nice.
10 #
11 # This is all mostly copied from the runfiles.bash snippet in
12 # tools/hscloud/lib.sh.
13 f=bazel_tools/tools/bash/runfiles/runfiles.bash
14 if [ ! -e "${RUNFILES_DIR:-/dev/null}/$f" ] && \
15 [ ! -e "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" ] && \
16 [ ! -e "$0.runfiles/$f" ] && \
17 [ ! -e "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" ] && \
18 [ ! -e "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" ]; then
19 echo "Uh-oh, looks like you didn't run this as 'bazel run //tools:install'.">&2
20 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
21 sleep 2
22 bazel run //tools:install -- "$@"
23 exit $?
24 fi
Sergiusz Bazanski1663e0e2019-07-21 16:25:07 +020025
Serge Bazanski0f8e5a22021-10-16 20:53:51 +000026 cd $(hscloud::workspace_location)
27 echo "Building hscloud tools and cluster tools..."
28 bazel build //tools/... //cluster/tools/...
Sergiusz Bazanskide061802019-01-13 21:14:02 +010029
Serge Bazanski0f8e5a22021-10-16 20:53:51 +000030 local path_missing=""
31 local path="$(hscloud::workspace_location)/bazel-bin/tools"
Dariusz Niemczykb19e8122023-07-13 23:20:10 +020032 if [[ ":$PATH:" != *":$path:"* ]]; then
Serge Bazanski0f8e5a22021-10-16 20:53:51 +000033 path_missing="$path"
34 fi
35 local path="$(hscloud::workspace_location)/bazel-bin/cluster/tools"
Dariusz Niemczykb19e8122023-07-13 23:20:10 +020036 if [[ ":$PATH:" != *":$path:"* ]]; then
Serge Bazanski0f8e5a22021-10-16 20:53:51 +000037 if [ -z "$path_missing" ]; then
38 path_missing="$path"
39 else
40 path_missing="$path_missing:$path"
41 fi
42 fi
Dariusz Niemczykb19e8122023-07-13 23:20:10 +020043 if [ ! -z "$path_missing" ]; then
Serge Bazanski0f8e5a22021-10-16 20:53:51 +000044 echo "Tools built correctly, but your PATH should be updated to access them:">&2
45 echo ' PATH="$PATH:'$path_missing'"'
46 echo 'Add the above line to your shell profile, or source env.sh from the root of hscloud.'
47 else
48 echo "Tools built correctly and in PATH. Happy hsclouding!"
49 fi
50}
Sergiusz Bazanskide061802019-01-13 21:14:02 +010051
Serge Bazanski0f8e5a22021-10-16 20:53:51 +000052main "$@"