Skip to content

Commit

Permalink
[bazel clean] [pr] Enable async options for darwin/bsd clients
Browse files Browse the repository at this point in the history
Enable `bazel clean --async` on Darwin and BSD clients. Issue tracked at #16505

Closes #16510.

PiperOrigin-RevId: 482230045
Change-Id: I8345e3bf22acb7f672325bb7b22b05a102d56eac
  • Loading branch information
Adam Singer authored and copybara-github committed Oct 19, 2022
1 parent 4ae5b50 commit b8d0e26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,10 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti

@VisibleForTesting
public static boolean canUseAsync(boolean async, boolean expunge, OS os, Reporter reporter) {
// TODO(dmarting): Deactivate expunge_async on non-Linux platform until we completely fix it
// for non-Linux platforms (https://github.com/bazelbuild/bazel/issues/1906).
// MacOS and FreeBSD support setsid(2) but don't have /usr/bin/setsid, so if we wanted to
// support --expunge_async on these platforms, we'd have to write a wrapper that calls setsid(2)
// and exec(2).
boolean asyncSupport = os == OS.LINUX;
if (async && !asyncSupport) {
// TODO(bazel-team): Deactivate expunge_async on Windows or Unknown platforms as support for
// daemonizing is done in daemonize.c and does not support those platforms.
boolean asyncSupportMissing = os == OS.WINDOWS || os == OS.UNKNOWN;
if (async && asyncSupportMissing) {
String fallbackName = expunge ? "--expunge" : "synchronous clean";
reporter.handle(
Event.info(
Expand All @@ -193,7 +190,7 @@ public static boolean canUseAsync(boolean async, boolean expunge, OS os, Reporte
}

String cleanBanner =
(async || !asyncSupport)
(async || asyncSupportMissing)
? "Starting clean."
: "Starting clean (this may take a while). "
+ "Consider using --async if the clean takes more than several minutes.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ public static Iterable<Object[]> data() {
{/* asyncOnCommandLine= */ true, OS.LINUX, false},
{/* asyncOnCommandLine= */ true, OS.WINDOWS, false},
{/* asyncOnCommandLine= */ true, OS.DARWIN, false},
{/* asyncOnCommandLine= */ true, OS.FREEBSD, false},
{/* asyncOnCommandLine= */ true, OS.OPENBSD, false},
{/* asyncOnCommandLine= */ true, OS.UNKNOWN, false},

// When --async is not provided, expect the suggestion on platforms that support it.
{/* asyncOnCommandLine= */ false, OS.LINUX, true},
{/* asyncOnCommandLine= */ false, OS.WINDOWS, false},
{/* asyncOnCommandLine= */ false, OS.DARWIN, false},
{/* asyncOnCommandLine= */ false, OS.DARWIN, true},
{/* asyncOnCommandLine= */ false, OS.FREEBSD, true},
{/* asyncOnCommandLine= */ false, OS.OPENBSD, true},
{/* asyncOnCommandLine= */ false, OS.UNKNOWN, false},
});
}

Expand All @@ -66,7 +72,7 @@ public void testCleanProvidesExpectedSuggestion() throws Exception {

boolean async =
CleanCommand.canUseAsync(this.asyncOnCommandLine, /* expunge= */ false, os, reporter);
if (os != OS.LINUX) {
if (os == OS.WINDOWS || os == OS.UNKNOWN) {
assertThat(async).isFalse();
}

Expand Down

0 comments on commit b8d0e26

Please sign in to comment.