Switch JavaCompileAction to use continuations
Remove the legacy blocking code path.
Progress on #6394.
PiperOrigin-RevId: 240196479
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java
index 3cb1784..ffaabc2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java
@@ -282,6 +282,7 @@
return ImmutableMap.copyOf(effectiveEnvironment);
}
+ @Override
public ActionContinuationOrResult beginExecution(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException, InterruptedException {
ReducedClasspath reducedClasspath;
@@ -318,62 +319,15 @@
return continuation.execute();
}
- // TODO(b/119813262) Remove this method. It duplicates the logic in beginExecution above and
- // JavaActionContinuation below. If this is still here, please keep the two code paths in sync.
+ // TODO(b/119813262): Move this method to AbstractAction.
@Override
public ActionResult execute(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException, InterruptedException {
- SpawnActionContext spawnActionContext =
- actionExecutionContext.getContext(SpawnActionContext.class);
- try {
- switch (classpathMode) {
- case OFF:
- case JAVABUILDER:
- // No special classpath logic in Bazel. Just execute with the full spawn.
- return ActionResult.create(
- spawnActionContext.exec(
- getFullSpawn(actionExecutionContext), actionExecutionContext));
-
- case BAZEL:
- // Try a compilation with a reduced classpath and check whether a fallback is required.
- ReducedClasspath reducedClasspath =
- getReducedClasspath(
- actionExecutionContext.getContext(JavaCompileActionContext.class));
- List<SpawnResult> results =
- spawnActionContext.exec(
- getReducedSpawn(actionExecutionContext, reducedClasspath, /* fallback= */ false),
- actionExecutionContext);
-
- SpawnResult spawnResult = Iterables.getOnlyElement(results);
- InputStream inMemoryOutput = spawnResult.getInMemoryOutput(outputDepsProto);
- try (InputStream input =
- inMemoryOutput == null
- ? outputDepsProto.getPath().getInputStream()
- : inMemoryOutput) {
- if (!Deps.Dependencies.parseFrom(input).getRequiresReducedClasspathFallback()) {
- return ActionResult.create(results);
- }
- }
-
- // Fall back to running with the full classpath. This requires first deleting potential
- // artifacts generated by the reduced action and clearing the metadata caches.
- deleteOutputs(
- actionExecutionContext.getFileSystem(), actionExecutionContext.getExecRoot());
- actionExecutionContext.getMetadataHandler().resetOutputs(getOutputs());
- List<SpawnResult> fallbackResults =
- spawnActionContext.exec(
- getReducedSpawn(actionExecutionContext, reducedClasspath, /* fallback=*/ true),
- actionExecutionContext);
- return ActionResult.create(
- ImmutableList.copyOf(Iterables.concat(results, fallbackResults)));
- }
- throw new AssertionError("Unknown classpath mode");
- } catch (ExecException e) {
- throw e.toActionExecutionException(
- getRawProgressMessage(), actionExecutionContext.getVerboseFailures(), this);
- } catch (CommandLineExpansionException | IOException e) {
- throw new ActionExecutionException(e, this, false);
+ ActionContinuationOrResult continuation = beginExecution(actionExecutionContext);
+ while (!continuation.isDone()) {
+ continuation = continuation.execute();
}
+ return continuation.get();
}
@Override