diff options
Diffstat (limited to 'src/main/cpp')
-rw-r--r-- | src/main/cpp/util/file_windows.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc index 66c0197d47..c2e0fd79ee 100644 --- a/src/main/cpp/util/file_windows.cc +++ b/src/main/cpp/util/file_windows.cc @@ -407,19 +407,21 @@ bool MsysRoot::Get(string* path) { result = value2; } - ToLower(&result); - - // BAZEL_SH is usually "c:\tools\msys64\usr\bin\bash.exe", we need to return - // "c:\tools\msys64". Look for the rightmost msys-looking component. - while (!IsRootDirectory(result) && - Basename(result).find("msys") == string::npos) { - result = Dirname(result); - } - if (IsRootDirectory(result)) { - return false; + // BAZEL_SH is usually "c:\tools\msys64\usr\bin\bash.exe" but could also be + // "c:\cygwin64\bin\bash.exe", and may have forward slashes instead of + // backslashes. Either way, we just need to remove the "usr/bin/bash.exe" or + // "bin/bash.exe" suffix (we don't care about the basename being "bash.exe"). + result = Dirname(result); + pair<string, string> parent(SplitPath(result)); + pair<string, string> grandparent(SplitPath(parent.first)); + if (AsLower(grandparent.second) == "usr" && AsLower(parent.second) == "bin") { + *path = grandparent.first; + return true; + } else if (AsLower(parent.second) == "bin") { + *path = parent.first; + return true; } - *path = result; - return true; + return false; } void MsysRoot::InitIfNecessary() { |