diff options
author | 2017-03-22 16:16:31 +0000 | |
---|---|---|
committer | 2017-03-23 09:48:20 +0000 | |
commit | 99847a1febb01be2fa35a4aa54dcf99873deb65c (patch) | |
tree | 3d6dd5b4847744a0a887fd399c0db096a4456537 /src/main/cpp | |
parent | fd0169244a104a9b2ddf03f131a0e92903b3e798 (diff) |
Bazel client, Windows: fix MSYS root computation
Make it more robust: it now works with Cygwin too,
e.g. BAZEL_SH=c:/cygwin64/bin/bash.exe
See https://github.com/bazelbuild/bazel/issues/2725
Related to https://github.com/bazelbuild/bazel/issues/2447
--
Change-Id: I911f09acd3e39c7cd0fe0750774fa0a900ffd844
Reviewed-on: https://cr.bazel.build/9510
PiperOrigin-RevId: 150885982
MOS_MIGRATED_REVID=150885982
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() { |