Skip to content

Commit

Permalink
Windows: Bazel no longer fails if MSYS is missing
Browse files Browse the repository at this point in the history
Fixes bazelbuild#6462

Change-Id: I6792b6d3be7ea0d31154a4c3cb9983c601689301
  • Loading branch information
laszlocsomor committed Nov 2, 2018
1 parent f445af5 commit d25b2a6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
34 changes: 18 additions & 16 deletions src/main/cpp/blaze_util_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1447,14 +1447,16 @@ static string LocateBash() {
}

string result = GetBinaryFromPath("bash.exe");
if (result.empty()) {
BAZEL_LOG(ERROR) << "bash.exe not found on PATH";
}
// if (result.empty()) {
// BAZEL_LOG(ERROR) << "bash.exe not found on PATH";
// }
return result;
}

void DetectBashOrDie() {
if (!blaze::GetEnv("BAZEL_SH").empty()) return;
if (!blaze::GetEnv("BAZEL_SH").empty()) {
return;
}

uint64_t start = blaze::GetMillisecondsMonotonic();

Expand All @@ -1466,18 +1468,18 @@ void DetectBashOrDie() {
if (!bash.empty()) {
// Set process environment variable.
blaze::SetEnv("BAZEL_SH", bash);
} else {
// 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);
// } else {
// // 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

/** A configuration fragment that tells where the shell is. */
public class ShellConfiguration extends BuildConfiguration.Fragment {
private static final ImmutableMap<OS, PathFragment> OS_SPECIFIC_SHELL =
ImmutableMap.<OS, PathFragment>builder()
.put(OS.WINDOWS, PathFragment.create("c:/tools/msys64/usr/bin/bash.exe"))
.put(OS.FREEBSD, PathFragment.create("/usr/local/bin/bash"))
.build();
// private static final ImmutableMap<OS, PathFragment> OS_SPECIFIC_SHELL =
// ImmutableMap.<OS, PathFragment>builder()
// .put(OS.WINDOWS, PathFragment.create("c:/tools/msys64/usr/bin/bash.exe"))
// .put(OS.FREEBSD, PathFragment.create("/usr/local/bin/bash"))
// .build();

private final PathFragment shellExecutable;
private final boolean useShBinaryStubScript;
Expand Down Expand Up @@ -135,8 +135,9 @@ public static PathFragment determineShellExecutable(
// TODO(ulfjack): instead of using the OS Bazel runs on, we need to use the exec platform,
// which may be different for remote execution. For now, this can be overridden with
// --shell_executable, so at least there's a workaround.
PathFragment result = OS_SPECIFIC_SHELL.get(os);
return result != null ? result : defaultShell;
// PathFragment result = OS_SPECIFIC_SHELL.get(os);
// return result != null ? result : defaultShell;
return defaultShell;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ public StrictActionEnvOptions getHost() {
}
}

private static final PathFragment FALLBACK_SHELL = PathFragment.create("/bin/bash");
// private static final PathFragment FALLBACK_SHELL = PathFragment.create("/bin/bash");

public static final ShellExecutableProvider SHELL_EXECUTABLE = (BuildOptions options) ->
ShellConfiguration.Loader.determineShellExecutable(
OS.getCurrent(),
options.get(ShellConfiguration.Options.class),
FALLBACK_SHELL);
null); // FALLBACK_SHELL);

public static final ActionEnvironmentProvider SHELL_ACTION_ENV = (BuildOptions options) -> {
boolean strictActionEnv = options.get(StrictActionEnvOptions.class).useStrictActionEnv;
Expand Down

0 comments on commit d25b2a6

Please sign in to comment.