Bazel client: make jvm.log path platform-safe
When writing the javalog.properties file that
configures the java logger, pass the log file path
in a platform safe manner. Namely if we're
running on Windows, don't write paths with
backslashes because they are mistaken for paths
with escaped characters.
Fixes: https://github.com/bazelbuild/bazel/issues/2576
--
Change-Id: Ibd907c13f1ffe4561c3a4e737f0c2b25ec5d4b17
Reviewed-on: https://cr.bazel.build/9059
PiperOrigin-RevId: 148342757
MOS_MIGRATED_REVID=148342757
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index 73c5f35..8eb7a11 100644
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -33,6 +33,7 @@
#include <io.h> // _open
#endif // COMPILER_MSVC
+#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
@@ -797,6 +798,15 @@
string ListSeparator() { return ";"; }
+string PathAsJvmFlag(const string& path) {
+ // 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;
+}
+
string ConvertPath(const string& path) {
#ifdef COMPILER_MSVC
// This isn't needed when the binary isn't linked against msys-2.0.dll (when