Windows,bootstrapping: respect TMPDIR
Respect the user-defined TMPDIR, or use TMP or
TEMP on Windows. Since MSYS sets TMP and TEMP to
"/tmp" which is actually "<msysroot>/tmp" (e.g.
"c:\tools\msys64\tmp"), it is shorter than the
Windows-default TEMP directory.
This buys us a bit of headroom to not hit path
length limits while bootstrapping.
Fixes https://github.com/bazelbuild/bazel/issues/4536
Change-Id: I2ab04e3c1c96bc306ef54348cc0c0c2f3fda13ee
PiperOrigin-RevId: 183826475
diff --git a/compile.sh b/compile.sh
index 2341273..31bb9c4 100755
--- a/compile.sh
+++ b/compile.sh
@@ -35,8 +35,9 @@
# Ensure Python is on the PATH on Windows,otherwise we would see
# "LAUNCHER ERROR" messages from py_binary exe launchers.
-case "$(uname -s | tr [:upper:] [:lower:])" in
+case "$(uname -s | tr "[:upper:]" "[:lower:]")" in
msys*|mingw*|cygwin*)
+ # Ensure Python is on the PATH, otherwise the bootstrapping fails later.
which python.exe >&/dev/null || {
echo >&2 "ERROR: cannot locate python.exe; check your PATH."
echo >&2 " You may need to run the following command, or something"
@@ -44,6 +45,10 @@
echo >&2 " export PATH=\"/c/Python27:\$PATH\""
exit 1
}
+ # Ensure TMPDIR uses the user-specified TMPDIR or TMP or TEMP.
+ # This is necessary to avoid overly longs paths during bootstrapping, see for
+ # example https://github.com/bazelbuild/bazel/issues/4536
+ export TMPDIR="${TMPDIR:-${TMP:-${TEMP:-}}}"
esac
cd "$(dirname "$0")"