diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java index ac2f44fd597006..9ced2b7b11ba36 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java @@ -27,9 +27,7 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Interner; import com.google.common.collect.Iterables; -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; @@ -334,23 +332,30 @@ protected void afterExecute( throws ExecException {} @Override - public final ActionContinuationOrResult beginExecution( - ActionExecutionContext actionExecutionContext) + public final ActionResult execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException { - Spawn spawn; try { beforeExecute(actionExecutionContext); - spawn = getSpawn(actionExecutionContext); - } catch (ExecException e) { - throw ActionExecutionException.fromExecException(e, this); + Spawn spawn = getSpawn(actionExecutionContext); + SpawnContinuation continuation = + actionExecutionContext + .getContext(SpawnStrategyResolver.class) + .beginExecution(spawn, actionExecutionContext); + while (!continuation.isDone()) { + continuation = continuation.execute(); + } + + ImmutableList result = continuation.get(); + if (resultConsumer != null) { + resultConsumer.accept(Pair.of(actionExecutionContext, result)); + } + afterExecute(actionExecutionContext, result); + return ActionResult.create(result); } catch (CommandLineExpansionException e) { throw createCommandLineException(e); + } catch (ExecException e) { + throw ActionExecutionException.fromExecException(e, this); } - SpawnContinuation spawnContinuation = - actionExecutionContext - .getContext(SpawnStrategyResolver.class) - .beginExecution(spawn, actionExecutionContext); - return new SpawnActionContinuation(actionExecutionContext, spawnContinuation); } private ActionExecutionException createCommandLineException(CommandLineExpansionException e) { @@ -1440,41 +1445,6 @@ public Builder addResultConsumer( } } - private final class SpawnActionContinuation extends ActionContinuationOrResult { - private final ActionExecutionContext actionExecutionContext; - private final SpawnContinuation spawnContinuation; - - public SpawnActionContinuation( - 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()) { - if (resultConsumer != null) { - resultConsumer.accept(Pair.of(actionExecutionContext, nextContinuation.get())); - } - List spawnResults = nextContinuation.get(); - afterExecute(actionExecutionContext, spawnResults); - return ActionContinuationOrResult.of(ActionResult.create(nextContinuation.get())); - } - return new SpawnActionContinuation(actionExecutionContext, nextContinuation); - } catch (ExecException e) { - throw ActionExecutionException.fromExecException(e, SpawnAction.this); - } - } - } - /** A {@link PathFragment} that is expanded with {@link PathFragment#getCallablePathString()}. */ private static final class CallablePathFragment implements CommandLines.PathStrippable {