Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Bash is no longer required for everything #7666

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
(void) DetectBashAndExportBazelSh();
#endif // if defined(_WIN32) || defined(__CYGWIN__)

globals->binary_path = CheckAndGetBinaryPath(argv[0]);
Expand Down
1 change: 0 additions & 1 deletion src/main/cpp/blaze_util_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ bool UnlimitCoredumps();

#if defined(_WIN32) || defined(__CYGWIN__)
std::string DetectBashAndExportBazelSh();
void DetectBashOrDie();
#endif // if defined(_WIN32) || defined(__CYGWIN__)

// This function has no effect on Unix platforms.
Expand Down
42 changes: 10 additions & 32 deletions src/main/cpp/blaze_util_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1452,17 +1452,9 @@ 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() {
Expand All @@ -1473,33 +1465,19 @@ 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);
}
return bash;
}

void EnsurePythonPathOption(std::vector<string>* options) {
Expand Down