Windows, JNI: use native isJunction method.
Fixes https://github.com/bazelbuild/bazel/issues/1680
--
MOS_MIGRATED_REVID=132051176
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index 1948943..03064e7 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -251,6 +251,45 @@
EOF
chmod 0755 ${ARCHIVE_DIR}/_embedded_binaries/process-wrapper${EXE_EXT}
+function build_jni() {
+ local output_dir=$1
+ local jni_lib_name="windows_jni.dll"
+ local output="${output_dir}/${jni_lib_name}"
+ local tmp_output="${NEW_TMPDIR}/jni/${jni_lib_name}"
+ mkdir -p "$(dirname "$tmp_output")"
+
+ case "${PLATFORM}" in
+ msys*|mingw*)
+ log "Building Windows JNI library..."
+
+ # We have to enable JNI on Windows because some filesystem operations are
+ # not (and cannot be) implemented in Java.
+ ENABLE_JNI=1
+
+ # Let the JVM know where to find the JNI library. This flag overrides the
+ # default value for java.library.path, but since JNI is disabled by default,
+ # that path would be ignored anyway.
+ JNI_PATH="$output_dir"
+
+ # Keep this `find` command in sync with the `srcs` of
+ # //src/main/native:windows_jni
+ local srcs=$(find src/main/native \
+ -name 'windows_*.cc' -o -name 'windows_*.h')
+ [ -n "$srcs" ] || fail "Could not find sources for Windows JNI library"
+
+ # do not quote $srcs because we need to expand it to multiple args
+ src/main/native/build_windows_jni.sh "$tmp_output" ${srcs}
+
+ cp "$tmp_output" "$output"
+ chmod 0755 "$output"
+ ;;
+ esac
+}
+
+ENABLE_JNI=0
+JNI_PATH=""
+build_jni "${ARCHIVE_DIR}/_embedded_binaries"
+
cp src/main/tools/build_interface_so ${ARCHIVE_DIR}/_embedded_binaries/build_interface_so
cp src/main/tools/jdk.BUILD ${ARCHIVE_DIR}/_embedded_binaries/jdk.BUILD
cp $OUTPUT_DIR/libblaze.jar ${ARCHIVE_DIR}
@@ -269,7 +308,8 @@
-XX:+HeapDumpOnOutOfMemoryError -Xverify:none -Dfile.encoding=ISO-8859-1 \
-XX:HeapDumpPath=${OUTPUT_DIR} \
-Djava.util.logging.config.file=${OUTPUT_DIR}/javalog.properties \
- -Dio.bazel.EnableJni=0 \
+ -Dio.bazel.EnableJni=${ENABLE_JNI} \
+ -Djava.library.path="$JNI_PATH" \
-jar ${ARCHIVE_DIR}/libblaze.jar \
--batch \
--install_base=${ARCHIVE_DIR} \
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index b474265..d15c3f2 100644
--- a/src/main/java/com/google/devtools/build/lib/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/BUILD
@@ -135,6 +135,7 @@
":os_util",
":preconditions",
":unix",
+ ":windows",
"//third_party:guava",
"//third_party:jsr305",
],
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java
index b74b279..020ef69 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.vfs;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
-
+import com.google.devtools.build.lib.windows.WindowsFileOperations;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -88,7 +88,7 @@
@Override
protected boolean fileIsSymbolicLink(File file) {
try {
- if (file.isDirectory() && isJunction(file.toPath())) {
+ if (file.isDirectory() && WindowsFileOperations.isJunction(file.getPath())) {
return true;
}
} catch (IOException e) {
@@ -164,7 +164,7 @@
protected boolean isDirectory(Path path, boolean followSymlinks) {
if (!followSymlinks) {
try {
- if (isJunction(getIoFile(path).toPath())) {
+ if (WindowsFileOperations.isJunction(getIoFile(path).getPath())) {
return false;
}
} catch (IOException e) {
@@ -173,9 +173,4 @@
}
return super.isDirectory(path, followSymlinks);
}
-
- private static boolean isJunction(java.nio.file.Path p) throws IOException {
- // Jury-rigged
- return p.compareTo(p.toRealPath()) != 0;
- }
}
diff --git a/src/main/native/BUILD b/src/main/native/BUILD
index eed0d7e..2ae8927 100644
--- a/src/main/native/BUILD
+++ b/src/main/native/BUILD
@@ -65,6 +65,8 @@
genrule(
name = "windows_jni",
+ # Keep this `glob` in sync with scripts/bootstrap/compile.sh:build_jni
+ # function's msys*|mingw* case.
srcs = glob([
"windows_*.cc",
"windows_*.h",