Sergiusz Bazanski | de06180 | 2019-01-13 21:14:02 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 2 | source tools/hscloud/lib.sh || exit 1 |
Sergiusz Bazanski | de06180 | 2019-01-13 21:14:02 +0100 | [diff] [blame] | 3 | |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 4 | function 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 Bazanski | 1663e0e | 2019-07-21 16:25:07 +0200 | [diff] [blame] | 25 | |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 26 | cd $(hscloud::workspace_location) |
| 27 | echo "Building hscloud tools and cluster tools..." |
| 28 | bazel build //tools/... //cluster/tools/... |
Sergiusz Bazanski | de06180 | 2019-01-13 21:14:02 +0100 | [diff] [blame] | 29 | |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 30 | local path_missing="" |
| 31 | local path="$(hscloud::workspace_location)/bazel-bin/tools" |
Dariusz Niemczyk | b19e812 | 2023-07-13 23:20:10 +0200 | [diff] [blame] | 32 | if [[ ":$PATH:" != *":$path:"* ]]; then |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 33 | path_missing="$path" |
| 34 | fi |
| 35 | local path="$(hscloud::workspace_location)/bazel-bin/cluster/tools" |
Dariusz Niemczyk | b19e812 | 2023-07-13 23:20:10 +0200 | [diff] [blame] | 36 | if [[ ":$PATH:" != *":$path:"* ]]; then |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 37 | if [ -z "$path_missing" ]; then |
| 38 | path_missing="$path" |
| 39 | else |
| 40 | path_missing="$path_missing:$path" |
| 41 | fi |
| 42 | fi |
Dariusz Niemczyk | b19e812 | 2023-07-13 23:20:10 +0200 | [diff] [blame] | 43 | if [ ! -z "$path_missing" ]; then |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 44 | 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 Bazanski | de06180 | 2019-01-13 21:14:02 +0100 | [diff] [blame] | 51 | |
Serge Bazanski | 0f8e5a2 | 2021-10-16 20:53:51 +0000 | [diff] [blame] | 52 | main "$@" |