Skip to content

Commit

Permalink
Make CppLinkAction implement Action.execute() instead of beginExecuti…
Browse files Browse the repository at this point in the history
…on().

Another step towards removing the continuation-based action execution machinery.

RELNOTES: None.
PiperOrigin-RevId: 490458651
Change-Id: I9133033da1fc529da6375fbe6eded77900884c80
  • Loading branch information
lberki authored and copybara-github committed Nov 23, 2022
1 parent e432f75 commit b6c2904
Showing 1 changed file with 11 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.devtools.build.lib.actions.AbstractAction;
import com.google.devtools.build.lib.actions.ActionContinuationOrResult;
import com.google.devtools.build.lib.actions.ActionEnvironment;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionException;
Expand Down Expand Up @@ -275,15 +273,22 @@ public ImmutableCollection<Artifact> getLinkstampObjectFileInputs() {
}

@Override
@ThreadCompatible
public ActionContinuationOrResult beginExecution(ActionExecutionContext actionExecutionContext)
public ActionResult execute(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException, InterruptedException {
Spawn spawn = createSpawn(actionExecutionContext);
SpawnContinuation spawnContinuation =
SpawnContinuation continuation =
actionExecutionContext
.getContext(SpawnStrategyResolver.class)
.beginExecution(spawn, actionExecutionContext);
return new CppLinkActionContinuation(actionExecutionContext, spawnContinuation);

try {
while (!continuation.isDone()) {
continuation = continuation.execute();
}
return ActionResult.create(continuation.get());
} catch (ExecException e) {
throw ActionExecutionException.fromExecException(e, CppLinkAction.this);
}
}

private Spawn createSpawn(ActionExecutionContext actionExecutionContext)
Expand Down Expand Up @@ -428,36 +433,6 @@ public ResourceSet estimateResourceConsumptionLocal(OS os, int inputs) {
}
}

private final class CppLinkActionContinuation extends ActionContinuationOrResult {
private final ActionExecutionContext actionExecutionContext;
private final SpawnContinuation spawnContinuation;

public CppLinkActionContinuation(
ActionExecutionContext actionExecutionContext, SpawnContinuation spawnContinuation) {
this.actionExecutionContext = actionExecutionContext;
this.spawnContinuation = spawnContinuation;
}

@Override
public ListenableFuture<?> getFuture() {
return spawnContinuation.getFuture();
}

@Override
public ActionContinuationOrResult execute()
throws ActionExecutionException, InterruptedException {
try {
SpawnContinuation nextContinuation = spawnContinuation.execute();
if (!nextContinuation.isDone()) {
return new CppLinkActionContinuation(actionExecutionContext, nextContinuation);
}
return ActionContinuationOrResult.of(ActionResult.create(nextContinuation.get()));
} catch (ExecException e) {
throw ActionExecutionException.fromExecException(e, CppLinkAction.this);
}
}
}

@Override
public Sequence<String> getStarlarkArgv() throws EvalException {
try {
Expand Down

0 comments on commit b6c2904

Please sign in to comment.