From ea8509abfc4fe194f109d9b350d014d928b0603c Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Thu, 7 Mar 2019 15:13:00 +0100 Subject: [PATCH 1/2] Windows: Bash is no longer required for everything Bazel no longer reports an error if it fails to locate Bash. This allows "bazel info release" to work even in absence of Bash. To clarify, Bazel still requires Bash to build rules that depend on Bash. This PR simply removes the fatal error Bazel used to display if Bash was missing even when Bash was not required. Fixes https://github.com/bazelbuild/bazel/issues/6462 --- src/main/cpp/blaze.cc | 2 +- src/main/cpp/blaze_util_platform.h | 3 +- src/main/cpp/blaze_util_windows.cc | 44 +++++++----------------------- 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index f31155ff0a6cdb..257d1304d4a869 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -1546,7 +1546,7 @@ int Main(int argc, const char *argv[], WorkspaceLayout *workspace_layout, // Must be done before command line parsing. // ParseOptions already populate --client_env, so detect bash before it // happens. - DetectBashOrDie(); + DetectBashAndExportBazelSh(); #endif // if defined(_WIN32) || defined(__CYGWIN__) globals->binary_path = CheckAndGetBinaryPath(argv[0]); diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index 832bfe0eca8065..9d8cdb0942dc65 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -263,8 +263,7 @@ bool UnlimitResources(); bool UnlimitCoredumps(); #if defined(_WIN32) || defined(__CYGWIN__) -std::string DetectBashAndExportBazelSh(); -void DetectBashOrDie(); +void DetectBashAndExportBazelSh(); #endif // if defined(_WIN32) || defined(__CYGWIN__) // This function has no effect on Unix platforms. diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index b113c54dfefd45..22ed7d090a1de2 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -1452,20 +1452,12 @@ static string GetBinaryFromPath(const string& binary_name) { return string(); } -static string LocateBash() { +static string LocateBashMaybe() { string msys_bash = GetMsysBash(); - if (!msys_bash.empty()) { - return msys_bash; - } - - string result = GetBinaryFromPath("bash.exe"); - if (result.empty()) { - BAZEL_LOG(ERROR) << "bash.exe not found on PATH"; - } - return result; + return msys_bash.empty() ? GetBinaryFromPath("bash.exe") : msys_bash; } -string DetectBashAndExportBazelSh() { +void DetectBashAndExportBazelSh() { string bash = blaze::GetEnv("BAZEL_SH"); if (!bash.empty()) { return bash; @@ -1473,33 +1465,17 @@ string DetectBashAndExportBazelSh() { uint64_t start = blaze::GetMillisecondsMonotonic(); - bash = LocateBash(); + bash = LocateBashMaybe(); uint64_t end = blaze::GetMillisecondsMonotonic(); - BAZEL_LOG(INFO) << "BAZEL_SH detection took " << end - start - << " msec, found " << bash.c_str(); - - if (!bash.empty()) { + if (bash.empty()) { + BAZEL_LOG(INFO) << "BAZEL_SH detection took " << end - start + << " msec, not found"; + } else { + BAZEL_LOG(INFO) << "BAZEL_SH detection took " << end - start + << " msec, found " << bash.c_str(); // Set process environment variable. blaze::SetEnv("BAZEL_SH", bash); } - return bash; -} - -void DetectBashOrDie() { - string bash = DetectBashAndExportBazelSh(); - if (bash.empty()) { - // TODO(bazel-team) should this be printed to stderr? If so, it should use - // BAZEL_LOG(ERROR) - printf( - "Bazel on Windows requires MSYS2 Bash, but we could not find it.\n" - "If you do not have it installed, you can install MSYS2 from\n" - " http://repo.msys2.org/distrib/msys2-x86_64-latest.exe\n" - "\n" - "If you already have it installed but Bazel cannot find it,\n" - "set BAZEL_SH environment variable to its location:\n" - " set BAZEL_SH=c:\\path\\to\\msys2\\usr\\bin\\bash.exe\n"); - exit(1); - } } void EnsurePythonPathOption(std::vector* options) { From 75c986000ad7108ae996f37a83f9788624630288 Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Thu, 7 Mar 2019 15:34:37 +0100 Subject: [PATCH 2/2] Fix compilation error --- src/main/cpp/blaze.cc | 2 +- src/main/cpp/blaze_util_platform.h | 2 +- src/main/cpp/blaze_util_windows.cc | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 257d1304d4a869..da1dc5ff175c5b 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -1546,7 +1546,7 @@ int Main(int argc, const char *argv[], WorkspaceLayout *workspace_layout, // Must be done before command line parsing. // ParseOptions already populate --client_env, so detect bash before it // happens. - DetectBashAndExportBazelSh(); + (void) DetectBashAndExportBazelSh(); #endif // if defined(_WIN32) || defined(__CYGWIN__) globals->binary_path = CheckAndGetBinaryPath(argv[0]); diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index 9d8cdb0942dc65..3686aa72c238fb 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -263,7 +263,7 @@ bool UnlimitResources(); bool UnlimitCoredumps(); #if defined(_WIN32) || defined(__CYGWIN__) -void DetectBashAndExportBazelSh(); +std::string DetectBashAndExportBazelSh(); #endif // if defined(_WIN32) || defined(__CYGWIN__) // This function has no effect on Unix platforms. diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index 22ed7d090a1de2..a89a9afe5c59d0 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -1457,7 +1457,7 @@ static string LocateBashMaybe() { return msys_bash.empty() ? GetBinaryFromPath("bash.exe") : msys_bash; } -void DetectBashAndExportBazelSh() { +string DetectBashAndExportBazelSh() { string bash = blaze::GetEnv("BAZEL_SH"); if (!bash.empty()) { return bash; @@ -1476,6 +1476,8 @@ void DetectBashAndExportBazelSh() { // Set process environment variable. blaze::SetEnv("BAZEL_SH", bash); } + + return bash; } void EnsurePythonPathOption(std::vector* options) {