Skip to content

Commit

Permalink
Implement Clean
Browse files Browse the repository at this point in the history
If `--experimental_remote_output_service` is set, Bazel issues a Clean RPC to the output service when running `bazel clean`.

Working towards #21630.

Closes #21743.

PiperOrigin-RevId: 617501624
Change-Id: Idf83b45913f5b35acfb1a29231f2fa7e5aedc850
  • Loading branch information
coeuvre authored and copybara-github committed Mar 20, 2024
1 parent 6788347 commit 3b6aac0
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import build.bazel.remote.execution.v2.DigestFunction;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.EnvironmentalExecException;
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.cache.OutputMetadataStore;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.remote.BazelOutputServiceProto.CleanRequest;
import com.google.devtools.build.lib.remote.BazelOutputServiceProto.CleanResponse;
import com.google.devtools.build.lib.remote.BazelOutputServiceProto.FinalizeBuildRequest;
import com.google.devtools.build.lib.remote.BazelOutputServiceProto.FinalizeBuildResponse;
import com.google.devtools.build.lib.remote.BazelOutputServiceProto.StartBuildRequest;
Expand Down Expand Up @@ -300,7 +303,25 @@ public void createSymlinkTree(
}

@Override
public void clean() {
// TODO(chiwang): implement this
public void clean() throws ExecException, InterruptedException {
var request = CleanRequest.newBuilder().setOutputBaseId(outputBaseId).build();
try {
var unused = clean(request);
} catch (IOException e) {
throw new EnvironmentalExecException(e, Code.UNEXPECTED_EXCEPTION);
}
}

private CleanResponse clean(CleanRequest request) throws IOException, InterruptedException {
return retrier.execute(
() ->
channel.withChannelBlocking(
channel -> {
try {
return BazelOutputServiceGrpc.newBlockingStub(channel).clean(request);
} catch (StatusRuntimeException e) {
throw new IOException(e);
}
}));
}
}

0 comments on commit 3b6aac0

Please sign in to comment.