Windows, bootstrapping: fix bootstrap_test

Compute the --host_jvm_args for the
bazel.windows_unix_root JVM flag on Windows.
After commit
9c54e2a764f0ddd2d3787aade1c530c5f43bd26c it's the
Bazel client's job to compute this JVM flag and
pass to the server, but during bootstrapping we
run Bazel in a client-less mode.

Fixes https://github.com/bazelbuild/bazel/issues/3186

Change-Id: I2facfdef7d301d8a96213b488728e3ae6aec1c33
PiperOrigin-RevId: 158972256
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index 74b6e85..3fcffba 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -302,6 +302,31 @@
   fi
 }
 
+# Computes the value of the bazel.windows_unix_root JVM flag.
+# Prints the JVM flag verbatim on Windows, ready to be passed to the JVM.
+# Prints an empty string on other platforms.
+function windows_unix_root_jvm_flag() {
+  if [ "${PLATFORM}" != "windows" ]; then
+    echo ""
+    return
+  fi
+  [ -n "${BAZEL_SH}" ] || fail "\$BAZEL_SH is not defined"
+  if [ "$(basename "$BAZEL_SH")" = "bash.exe" ]; then
+    local result="$(dirname "$BAZEL_SH")"
+    if [ "$(basename "$result")" = "bin" ]; then
+      result="$(dirname "$result")"
+      if [ "$(basename "$result")" = "usr" ]; then
+        result="$(dirname "$result")"
+      fi
+      # Print the JVM flag. Replace backslashes with forward slashes so the JVM
+      # and the shell won't believe that backslashes are escaping characters.
+      echo "-Dbazel.windows_unix_root=${result//\\//}"
+      return
+    fi
+  fi
+  fail "\$BAZEL_SH=${BAZEL_SH}, must end with \"bin\\bash.exe\" or \"usr\\bin\\bash.exe\""
+}
+
 build_jni "${ARCHIVE_DIR}/_embedded_binaries"
 
 cp src/main/tools/jdk.BUILD ${ARCHIVE_DIR}/_embedded_binaries/jdk.BUILD
@@ -341,6 +366,7 @@
   "${JAVA_HOME}/bin/java" \
       -XX:+HeapDumpOnOutOfMemoryError -Xverify:none -Dfile.encoding=ISO-8859-1 \
       -XX:HeapDumpPath=${OUTPUT_DIR} \
+      $(windows_unix_root_jvm_flag) \
       -Djava.util.logging.config.file=${OUTPUT_DIR}/javalog.properties \
       ${JNI_FLAGS} \
       -jar ${ARCHIVE_DIR}/libblaze.jar \