Bazel client, Windows/MSVC: fix path handling bugs Fix blaze_util_windows.ConvertPath: in the MSVC version this is using the actual %PATH% value, we don't need to convert it. Fix blaze_util_windows.PathAsJvmFlag: shorten the path so we can pass it to the JVM process (long paths aren't understood by the shell), but also converrt backslashes to forward slashes so the JVM won't believe we are passing paths with escaped characters. See https://github.com/bazelbuild/bazel/issues/2107 See https://github.com/bazelbuild/bazel/issues/2181 -- PiperOrigin-RevId: 149396971 MOS_MIGRATED_REVID=149396971
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index a862fda..9f6aecb 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc
@@ -799,12 +799,15 @@ string ListSeparator() { return ";"; } string PathAsJvmFlag(const string& path) { + string spath; + if (!blaze_util::AsShortWindowsPath(path, &spath)) { + pdie(255, "PathAsJvmFlag(%s): AsShortWindowsPath failed", path.c_str()); + } // Convert backslashes to forward slashes, in order to avoid the JVM parsing // Windows paths as if they contained escaped characters. // See https://github.com/bazelbuild/bazel/issues/2576 - string result(path); - std::replace(result.begin(), result.end(), '\\', '/'); - return result; + std::replace(spath.begin(), spath.end(), '\\', '/'); + return spath; } string ConvertPath(const string& path) { @@ -828,6 +831,11 @@ // Convert a Unix path list to Windows path list string ConvertPathList(const string& path_list) { +#ifdef COMPILER_MSVC + // In the MSVC version we use the actual %PATH% value which is separated by + // ";" and contains Windows paths. + return path_list; +#else // not COMPILER_MSVC string w_list = ""; int start = 0; int pos; @@ -839,6 +847,7 @@ w_list += ConvertPath(path_list.substr(start)); } return w_list; +#endif // COMPILER_MSVC } static string ConvertPathToPosix(const string& win_path) {