aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/packages
diff options
context:
space:
mode:
authorGravatar Dan Fabulich <DanFabulich@gmail.com>2016-12-02 16:23:06 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-12-02 19:08:58 +0000
commitccaee70c246f836549aac3a66747e9777c83d83f (patch)
tree3336c3be7ed09297d41c8029db312668c2a8f59d /scripts/packages
parent4d6bb5bf55920dc95b27a4f5c265d3292592f737 (diff)
Make it easier for tools/bazel wrapper script to find bazel-real
The launcher script uses "exec -a" to launch the wrapper, but if the wrapper script is itself a Bash script, Bash will set "$0" to be the path to the wrapper script, not the path to the launcher script. To work around this, we've been having our wrapper script search the user's PATH environment variable for bazel-real, but that doesn't work well with the IntelliJ plugin for Bazel, which may not use the expected PATH environment. -- Change-Id: I402ad29d5b809be8e687e217e19c03e7ac3eb972 Reviewed-on: https://cr.bazel.build/7550 PiperOrigin-RevId: 140851992 MOS_MIGRATED_REVID=140851992
Diffstat (limited to 'scripts/packages')
-rwxr-xr-xscripts/packages/bazel.sh36
1 files changed, 18 insertions, 18 deletions
diff --git a/scripts/packages/bazel.sh b/scripts/packages/bazel.sh
index b9ad1d7849..43bc593f85 100755
--- a/scripts/packages/bazel.sh
+++ b/scripts/packages/bazel.sh
@@ -21,23 +21,6 @@ set -eu
# file and runs that. If that's not found, it runs the real Bazel binary which
# is installed next to this script as bazel-real.
-WORKSPACE_DIR="${PWD}"
-while [[ "${WORKSPACE_DIR}" != / ]]; do
- if [[ -e "${WORKSPACE_DIR}/WORKSPACE" ]]; then
- break;
- fi
- WORKSPACE_DIR="$(dirname "${WORKSPACE_DIR}")"
-done
-readonly WORKSPACE_DIR
-
-if [[ -e "${WORKSPACE_DIR}/WORKSPACE" ]]; then
- readonly WRAPPER="${WORKSPACE_DIR}/tools/bazel"
-
- if [[ -x "${WRAPPER}" ]]; then
- exec -a "$0" "${WRAPPER}" "$@"
- fi
-fi
-
# `readlink -f` that works on OSX too.
function get_realpath() {
if [ "$(uname -s)" == "Darwin" ]; then
@@ -78,7 +61,24 @@ function get_realpath() {
fi
}
-BAZEL_REAL="$(dirname "$(get_realpath "${BASH_SOURCE[0]}")")/bazel-real"
+export BAZEL_REAL="$(dirname "$(get_realpath "${BASH_SOURCE[0]}")")/bazel-real"
+
+WORKSPACE_DIR="${PWD}"
+while [[ "${WORKSPACE_DIR}" != / ]]; do
+ if [[ -e "${WORKSPACE_DIR}/WORKSPACE" ]]; then
+ break;
+ fi
+ WORKSPACE_DIR="$(dirname "${WORKSPACE_DIR}")"
+done
+readonly WORKSPACE_DIR
+
+if [[ -e "${WORKSPACE_DIR}/WORKSPACE" ]]; then
+ readonly WRAPPER="${WORKSPACE_DIR}/tools/bazel"
+
+ if [[ -x "${WRAPPER}" ]]; then
+ exec -a "$0" "${WRAPPER}" "$@"
+ fi
+fi
if [[ ! -x "${BAZEL_REAL}" ]]; then
echo "Failed to find underlying Bazel executable at ${BAZEL_REAL}" >&2