Skip to content

Commit

Permalink
Windows: Bash is no longer required for everything
Browse files Browse the repository at this point in the history
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 bazelbuild#6462
  • Loading branch information
laszlocsomor committed Mar 7, 2019
1 parent de0612a commit ea8509a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/main/cpp/blaze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
3 changes: 1 addition & 2 deletions src/main/cpp/blaze_util_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 10 additions & 34 deletions src/main/cpp/blaze_util_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1452,54 +1452,30 @@ 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;
}

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<string>* options) {
Expand Down

0 comments on commit ea8509a

Please sign in to comment.