WindowsFileSystem: use JNI impl. of isJunction
Also build the JNI library while bootstraping.
This was once submitted in commit 4a249b6962d32ed4cfd4165dfdae4a555b00bb69 but got
rolled back due to some test breakage that's long
since fixed. In this change I'm slightly modifying
the original code in compile.sh.
Using JNI methods however is necessary because we
can't implement WindowsFileOperations.GetLongPath
in native Java, and having that code is a
prerequisite for the fix of https://github.com/bazelbuild/bazel/issues/2145
See also https://github.com/bazelbuild/bazel/issues/2238
--
PiperOrigin-RevId: 142535019
MOS_MIGRATED_REVID=142535019
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index 2d4026c..8508682 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -284,6 +284,45 @@
EOF
chmod 0755 ${ARCHIVE_DIR}/_embedded_binaries/process-wrapper${EXE_EXT}
+function build_jni() {
+ local -r output_dir=$1
+
+ case "${PLATFORM}" in
+ msys*|mingw*)
+ # We need JNI on Windows because some filesystem operations are not (and
+ # cannot be) implemented in native Java.
+ log "Building Windows JNI library..."
+
+ local -r jni_lib_name="windows_jni.dll"
+ local -r output="${output_dir}/${jni_lib_name}"
+ local -r tmp_output="${NEW_TMPDIR}/jni/${jni_lib_name}"
+ mkdir -p "$(dirname "$tmp_output")"
+ mkdir -p "$(dirname "$output")"
+
+ # 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 0555 "$output"
+
+ JNI_FLAGS="-Dio.bazel.EnableJni=1 -Djava.library.path=${output_dir}"
+ ;;
+
+ *)
+ # We don't need JNI on other platforms.
+ JNI_FLAGS="-Dio.bazel.EnableJni=0"
+ ;;
+ esac
+}
+
+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}
@@ -303,7 +342,7 @@
-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 \
+ ${JNI_FLAGS} \
-jar ${ARCHIVE_DIR}/libblaze.jar \
--batch \
--install_base=${ARCHIVE_DIR} \
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 9b8ba02..1694f8c 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
@@ -17,6 +17,7 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.Path.PathFactory;
+import com.google.devtools.build.lib.windows.WindowsFileOperations;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -377,24 +378,9 @@
* <p>This method returns true for all three types as long as their target is a directory (even if
* they are dangling), though only directory junctions and directory symlinks are useful.
*/
- // TODO(laszlocsomor): fix https://github.com/bazelbuild/bazel/issues/1735 and use the JNI method
- // in WindowsFileOperations.
@VisibleForTesting
static boolean isJunction(File file) throws IOException {
- if (Files.exists(file.toPath(), symlinkOpts(/* followSymlinks */ false))) {
- DosFileAttributes attributes = getAttribs(file, /* followSymlinks */ false);
-
- if (attributes.isRegularFile()) {
- return false;
- }
-
- if (attributes.isDirectory()) {
- return attributes.isOther();
- } else {
- return attributes.isSymbolicLink();
- }
- }
- return false;
+ return WindowsFileOperations.isJunction(file.getPath());
}
private static DosFileAttributes getAttribs(File file, boolean followSymlinks)