Skip to content

Commit

Permalink
Bazel client, Windows/MSVC: fix path handling bugs
Browse files Browse the repository at this point in the history
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 #2107
See #2181

--
PiperOrigin-RevId: 149396971
MOS_MIGRATED_REVID=149396971
  • Loading branch information
laszlocsomor authored and vladmos committed Mar 7, 2017
1 parent 869d52f commit 9d3f989
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/cpp/blaze_util_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,15 @@ void ExecuteProgram(const string& exe, const std::vector<string>& args_vector) {
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) {
Expand All @@ -828,6 +831,11 @@ string ConvertPath(const string& path) {

// 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;
Expand All @@ -839,6 +847,7 @@ string ConvertPathList(const string& path_list) {
w_list += ConvertPath(path_list.substr(start));
}
return w_list;
#endif // COMPILER_MSVC
}

static string ConvertPathToPosix(const string& win_path) {
Expand Down

0 comments on commit 9d3f989

Please sign in to comment.