Windows: fix bootstrapping bugs with 0.4.4 Fix 3 bugs to get bootstrapping working on Windows after it was broken in bazel-0.4.4: * Move the definition of PATHSEP to before the code that overrides it for Windows * Fix the Java code processing the --javahome flag to recognize absolute Windows paths as absolute. See: https://github.com/bazelbuild/bazel/issues/2520 * Do not propagate the JAVA_HOME value in variables, because it contains spaces on Windows, and when we pass the variable to Bazel, and it's expanded to e.g. ... --foo=C:/Program Files, these are interpreted as two args instead of one. Also fix a bug that is just annoying, not causing any trouble (on Windows): * Silently swallow errors from the "rm -rf" in the atexit functions Also do some refactoring: * Rename a variable (BAZEL_ARGS) and a method to indicate they're private. They are not used from anywhere else as far as I know -- no occurrences in either the bazel or the continuous-integration repos. Fixes: https://github.com/bazelbuild/bazel/issues/2473 -- Change-Id: I309752cd7bbff0b5dd683ddb5573f3061350043c Reviewed-on: https://cr.bazel.build/8797 PiperOrigin-RevId: 147345194 MOS_MIGRATED_REVID=147345194
diff --git a/scripts/bootstrap/bootstrap.sh b/scripts/bootstrap/bootstrap.sh index ee754f7..a9eea83 100755 --- a/scripts/bootstrap/bootstrap.sh +++ b/scripts/bootstrap/bootstrap.sh
@@ -31,51 +31,48 @@ : ${JAVA_VERSION:="1.8"} if [ "${JAVA_VERSION}" = "1.7" ]; then - : ${BAZEL_ARGS:=--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain_jdk7 \ + _BAZEL_ARGS="--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain_jdk7 \ --host_java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain_jdk7 \ - --javabase=$JAVA_HOME \ - --host_javabase=$JAVA_HOME \ --spawn_strategy=standalone \ --nojava_header_compilation \ --define JAVA_VERSION=1.7 --ignore_unsupported_sandboxing \ --compilation_mode=opt \ - "${EXTRA_BAZEL_ARGS:-}"} + ${EXTRA_BAZEL_ARGS:-}" else - : ${BAZEL_ARGS:=--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \ + _BAZEL_ARGS="--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \ --host_java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \ - --javabase=$JAVA_HOME \ - --host_javabase=$JAVA_HOME \ --spawn_strategy=standalone \ --nojava_header_compilation \ --strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \ --compilation_mode=opt \ - "${EXTRA_BAZEL_ARGS:-}"} + ${EXTRA_BAZEL_ARGS:-}" fi if [ -z "${BAZEL-}" ]; then - function run_bootstrapping_bazel() { + function _run_bootstrapping_bazel() { local command=$1 shift run_bazel_jar $command \ - ${BAZEL_ARGS-} --verbose_failures \ + ${_BAZEL_ARGS} --verbose_failures \ + "--javabase=${JAVA_HOME}" "--host_javabase=${JAVA_HOME}" \ --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}" } else - function run_bootstrapping_bazel() { - local command=$1 + function _run_bootstrapping_bazel() { local command=$1 shift ${BAZEL} --bazelrc=${BAZELRC} ${BAZEL_DIR_STARTUP_OPTIONS} $command \ - ${BAZEL_ARGS-} --verbose_failures \ + ${_BAZEL_ARGS} --verbose_failures \ + "--javabase=${JAVA_HOME}" "--host_javabase=${JAVA_HOME}" \ --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}" } fi function bazel_build() { - run_bootstrapping_bazel build "${EMBED_LABEL_ARG[@]}" "$@" + _run_bootstrapping_bazel build "${EMBED_LABEL_ARG[@]}" "$@" } function get_bazel_bin_path() { - run_bootstrapping_bazel info "bazel-bin" || echo "bazel-bin" + _run_bootstrapping_bazel info "bazel-bin" || echo "bazel-bin" } function md5_outputs() {
diff --git a/scripts/bootstrap/buildenv.sh b/scripts/bootstrap/buildenv.sh index 62ebc11..39a15c4 100755 --- a/scripts/bootstrap/buildenv.sh +++ b/scripts/bootstrap/buildenv.sh
@@ -58,6 +58,7 @@ MACHINE_IS_64BIT='yes' fi +PATHSEP=":" case "${PLATFORM}" in linux) # JAVA_HOME must point to a Java installation. @@ -82,6 +83,8 @@ PATHSEP=";" # Find the latest available version of the SDK. JAVA_HOME="${JAVA_HOME:-$(ls -d /c/Program\ Files/Java/jdk* | sort | tail -n 1)}" + # Replace backslashes with forward slashes. + JAVA_HOME="${JAVA_HOME//\\//}" esac EXE_EXT="" @@ -150,7 +153,7 @@ local DIR="$(mktemp -d "${tmp%%/}/bazel_XXXXXXXX")" mkdir -p "${DIR}" local DIRBASE=$(basename "${DIR}") - eval "cleanup_tempdir_${DIRBASE}() { rm -rf '${DIR}'; }" + eval "cleanup_tempdir_${DIRBASE}() { rm -rf '${DIR}' >&/dev/null || true ; }" atexit cleanup_tempdir_${DIRBASE} NEW_TMPDIR="${DIR}" }
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh index 8dfa7c3..cbfb246 100755 --- a/scripts/bootstrap/compile.sh +++ b/scripts/bootstrap/compile.sh
@@ -57,7 +57,6 @@ LDFLAGS=${LDFLAGS:-""} MSYS_DLLS="" -PATHSEP=":" # Check that javac -version returns a upper version than $JAVA_VERSION. get_java_version