aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-01-30 18:11:58 +0000
committerGravatar Yun Peng <pcloudy@google.com>2017-01-31 08:59:15 +0000
commitf5525e8ddb341ddf96feaefb8cba0e95d28f226b (patch)
tree30c0534a2bb5a7167c26fac22b340775e1ba2b45
parent57249c9a88f66d8903fd40bea1b812990194db38 (diff)
Bazel bootstrapping: make it work on Windows again
In this change: (1) add a sanity check to verify that GNU bintools are on the PATH (2) correct the PATH on Windows if (1) failed (3) use "<user>/My Documents/Temp" as the default temp directory instead of "%windir%/Temp", because the latter is non-writable Motivated by: https://github.com/bazelbuild/bazel/issues/2431 https://github.com/bazelbuild/bazel/issues/2449 -- PiperOrigin-RevId: 146006796 MOS_MIGRATED_REVID=146006796
-rwxr-xr-xcompile.sh20
-rwxr-xr-xscripts/bootstrap/buildenv.sh22
2 files changed, 32 insertions, 10 deletions
diff --git a/compile.sh b/compile.sh
index dfc3d71015..67223e6715 100755
--- a/compile.sh
+++ b/compile.sh
@@ -22,6 +22,26 @@
set -o errexit
+# Correct PATH on Windows, to avoid using "FIND.EXE" instead of "/usr/bin/find"
+# etc, leading to confusing errors.
+export BAZEL_OLD_PATH=$PATH
+case "$(uname -s | tr [:upper:] [:lower:])" in
+msys*|mingw*)
+ # Check that the PATH is set up correctly by attempting to locate `[`.
+ # This ensures that `which` is installed correctly and can succeed, while
+ # also avoids accidentally locating a tool that exists in plain Windows too
+ # (like "find" for "FIND.EXE").
+ which [ >&/dev/null || export PATH="/bin:/usr/bin:$PATH"
+esac
+
+# Check that the bintools can be found, otherwise we would see very confusing
+# error messages.
+which [ >&/dev/null || {
+ echo >&2 "ERROR: cannot locate GNU bintools; check your PATH."
+ echo >&2 " (You may need to run 'export PATH=/bin:/usr/bin:\$PATH)'"
+ exit 1
+}
+
cd "$(dirname "$0")"
# Set the default verbose mode in buildenv.sh so that we do not display command
diff --git a/scripts/bootstrap/buildenv.sh b/scripts/bootstrap/buildenv.sh
index 502f2c1690..60a375d05a 100755
--- a/scripts/bootstrap/buildenv.sh
+++ b/scripts/bootstrap/buildenv.sh
@@ -84,20 +84,15 @@ msys*|mingw*)
JAVA_HOME="${JAVA_HOME:-$(ls -d /c/Program\ Files/Java/jdk* | sort | tail -n 1)}"
esac
-# Extension for executables.
EXE_EXT=""
-case "${PLATFORM}" in
-msys*|mingw*)
+if [ "${PLATFORM}" == "mingw" ]; then
+ # Extension for executables.
EXE_EXT=".exe"
-esac
-# Fix TMPDIR on msys
-case "${PLATFORM}" in
-msys*|mingw*)
- default_tmp=${TMP:-$(cygpath -W)/Temp}
+ # Fix TMPDIR on msys
+ default_tmp=${TMP:-$(cygpath -mO)/Temp}
TMPDIR=$(cygpath -ml "${TMPDIR:-$default_tmp}")
-esac
-
+fi
# Whether we display build messages or not. We set this conditionally because
# the file including us or the user may already have defined VERBOSE to their
@@ -118,6 +113,11 @@ function atexit() {
ATEXIT_HANDLERS="${ATEXIT_HANDLERS} ${handler}"
}
+function restore_saved_path() {
+ export PATH=$BAZEL_OLD_PATH
+ export BAZEL_OLD_PATH=
+}
+
# Exit routine to run all registered atexit handlers.
#
# If the program exited with an error, this exit routine will also exit with the
@@ -146,6 +146,7 @@ function run_atexit_handlers() {
function tempdir() {
local tmp=${TMPDIR:-/tmp}
+ mkdir -p ${tmp}
local DIR="$(mktemp -d ${tmp%%/}/bazel_XXXXXXXX)"
mkdir -p "${DIR}"
local DIRBASE=$(basename "${DIR}")
@@ -164,6 +165,7 @@ function cleanup_phasefile() {
}
atexit cleanup_phasefile
+atexit restore_saved_path
# Excutes a command respecting the current verbosity settings.
#