From 4b4b9d33e50dfba8c4b2e798d3ede2c75fa3b256 Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Wed, 19 Oct 2016 11:47:10 +0000 Subject: [PATCH] Rollback of commit 8bb4299b28de14eed9d3b57bcaeb9350c81c7db3. *** Reason for rollback *** Suspected root cause for Windows bootstrap on Bazel CI breakage: java.lang.NullPointerException at com.google.devtools.build.lib.vfs.Path$1.run(Path.java:123) http://ci.bazel.io/view/Bazel%20bootstrap%20and%20maintenance/job/Bazel/922/JAVA_VERSION=1.8,PLATFORM_NAME=windows-x86_64/console *** Original change description *** VFS, WindowsFileSystem: fix UNIX_ROOT retrieval Executing bash.exe directly instead of through cmd.exe doesn't seem to work. This change fixes that problem. Fixes https://github.com/bazelbuild/bazel/issues/1463 (again) -- MOS_MIGRATED_REVID=136581532 --- .../build/lib/vfs/WindowsFileSystem.java | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) 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 48f1ff850286fc..bc9a10d414b130 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 @@ -20,7 +20,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.nio.file.Files; import java.nio.file.LinkOption; @@ -171,11 +170,9 @@ private static WindowsPath translateParent(WindowsPath parent, String name) { UNIX_ROOT, "Could not determine Unix path root or it is not an absolute Windows path. Set the " + "\"%s\" JVM argument, or export the \"%s\" environment variable for the MSYS bash" - + " and have /usr/bin/cygpath installed. Parent is \"%s\", name is \"%s\".", + + " and have /usr/bin/cygpath installed", WINDOWS_UNIX_ROOT_JVM_ARG, - BAZEL_SH_ENV_VAR, - parent, - name); + BAZEL_SH_ENV_VAR); return (WindowsPath) parent.getRelative(UNIX_ROOT); } else { @@ -411,19 +408,19 @@ private static PathFragment determineUnixRoot(String jvmArgName, String bazelShE String bash = System.getenv(bazelShEnvVar); Process process = null; try { - process = Runtime.getRuntime().exec("cmd.exe /C " + bash + " -c \"/usr/bin/cygpath -m /\""); + process = Runtime.getRuntime().exec(bash + "-c \"/usr/bin/cygpath -m /\""); // Wait 3 seconds max, that should be enough to run this command. process.waitFor(3, TimeUnit.SECONDS); if (process.exitValue() == 0) { - path = readAll(process.getInputStream()); - } else { - System.err.print( - String.format( - "ERROR: %s (exit code: %d)%n", - readAll(process.getErrorStream()), - process.exitValue())); + char[] buf = new char[256]; + try (InputStreamReader r = new InputStreamReader(process.getInputStream())) { + int len = 0; + while ((len = r.read(buf)) > 0) { + path = path + new String(buf, 0, len); + } + } } } catch (InterruptedException | IOException e) { // Silently ignore failure. Either MSYS is installed at a different location, or not @@ -440,18 +437,4 @@ private static PathFragment determineUnixRoot(String jvmArgName, String bazelShE return result; } } - - private static String readAll(InputStream s) { - String result = ""; - int len; - char[] buf = new char[4096]; - try (InputStreamReader r = new InputStreamReader(s)) { - while ((len = r.read(buf)) > 0) { - result += new String(buf, 0, len); - } - } catch (IOException e) { - return null; - } - return result; - } }