aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-12-22 00:59:05 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-22 01:01:04 -0800
commitd8a9344699da2f6258eafa22566c7e541ec09792 (patch)
treedcbea48dc03ec18d98238184d3a9ffaf7930ab81 /src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
parente63a867feb2483851b5169894ff7b3c0bdb26581 (diff)
Move TargetCompleteEvent generation to the CompletionFunction
This change breaks without https://github.com/bazelbuild/bazel/commit/a0ea569f7df19b8284846a52854e73747f7ec005; if that change is rolled back, this change has to be rolled back as well. It was previously in ExecutionProgressReceiver, and directly hooked into Skyframe. Now that we have a way to post event bus events directly from Sky functions, we should just do that. Also, this allows us to access artifact metdata, since the completion function has all the necessary artifacts as dependencies, which in turn can be used to improve the build event protocol implementation, where we want to post URLs to the CAS, which requires knowing the checksum. PiperOrigin-RevId: 179903333
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java63
1 files changed, 48 insertions, 15 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
index 103fd73167..f4fb386996 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java
@@ -13,7 +13,6 @@
// limitations under the License.
package com.google.devtools.build.lib.skyframe;
-import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.MissingInputFileException;
@@ -29,6 +28,7 @@ import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.events.Event;
+import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.skyframe.AspectCompletionValue.AspectCompletionKey;
import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey;
import com.google.devtools.build.lib.skyframe.TargetCompletionValue.TargetCompletionKey;
@@ -38,7 +38,6 @@ import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.devtools.build.skyframe.ValueOrException2;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
/**
@@ -86,7 +85,11 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S
TResult createResult(TValue value);
/** Creates a failed completion value. */
- SkyValue createFailed(TValue value, NestedSet<Cause> rootCauses);
+ ExtendedEventHandler.Postable createFailed(TValue value, NestedSet<Cause> rootCauses);
+
+ /** Creates a succeeded completion value. */
+ ExtendedEventHandler.Postable createSucceeded(
+ SkyKey skyKey, TValue value, TopLevelArtifactContext topLevelArtifactContext);
/**
* Extracts a tag given the {@link SkyKey}.
@@ -143,7 +146,8 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S
}
@Override
- public SkyValue createFailed(ConfiguredTargetValue value, NestedSet<Cause> rootCauses) {
+ public ExtendedEventHandler.Postable createFailed(
+ ConfiguredTargetValue value, NestedSet<Cause> rootCauses) {
return TargetCompleteEvent.createFailed(value.getConfiguredTarget(), rootCauses);
}
@@ -152,6 +156,22 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S
return Label.print(
((TargetCompletionKey) skyKey.argument()).configuredTargetKey().getLabel());
}
+
+ @Override
+ public ExtendedEventHandler.Postable createSucceeded(
+ SkyKey skyKey,
+ ConfiguredTargetValue value,
+ TopLevelArtifactContext topLevelArtifactContext) {
+ ConfiguredTarget target = value.getConfiguredTarget();
+ if (((TargetCompletionKey) skyKey.argument()).willTest()) {
+ return TargetCompleteEvent.successfulBuildSchedulingTest(target);
+ } else {
+ ArtifactsToBuild artifactsToBuild =
+ TopLevelArtifactHelper.getAllArtifactsToBuild(target, topLevelArtifactContext);
+ return TargetCompleteEvent.successfulBuild(
+ target, artifactsToBuild.getAllArtifactsByOutputGroup());
+ }
+ }
}
private static class AspectCompletor implements Completor<AspectValue, AspectCompletionValue> {
@@ -203,7 +223,8 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S
}
@Override
- public SkyValue createFailed(AspectValue value, NestedSet<Cause> rootCauses) {
+ public ExtendedEventHandler.Postable createFailed(
+ AspectValue value, NestedSet<Cause> rootCauses) {
return AspectCompleteEvent.createFailed(value, rootCauses);
}
@@ -211,22 +232,27 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S
public String extractTag(SkyKey skyKey) {
return Label.print(((AspectCompletionKey) skyKey.argument()).aspectKey().getLabel());
}
+
+ @Override
+ public ExtendedEventHandler.Postable createSucceeded(
+ SkyKey skyKey, AspectValue value, TopLevelArtifactContext topLevelArtifactContext) {
+ ArtifactsToBuild artifacts =
+ TopLevelArtifactHelper.getAllArtifactsToBuild(value, topLevelArtifactContext);
+ return AspectCompleteEvent.createSuccessful(value, artifacts);
+ }
}
- public static SkyFunction targetCompletionFunction(AtomicReference<EventBus> eventBusRef) {
- return new CompletionFunction<>(eventBusRef, new TargetCompletor());
+ public static SkyFunction targetCompletionFunction() {
+ return new CompletionFunction<>(new TargetCompletor());
}
- public static SkyFunction aspectCompletionFunction(AtomicReference<EventBus> eventBusRef) {
- return new CompletionFunction<>(eventBusRef, new AspectCompletor());
+ public static SkyFunction aspectCompletionFunction() {
+ return new CompletionFunction<>(new AspectCompletor());
}
- private final AtomicReference<EventBus> eventBusRef;
private final Completor<TValue, TResult> completor;
- private CompletionFunction(
- AtomicReference<EventBus> eventBusRef, Completor<TValue, TResult> completor) {
- this.eventBusRef = eventBusRef;
+ private CompletionFunction(Completor<TValue, TResult> completor) {
this.completor = completor;
}
@@ -280,7 +306,7 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S
NestedSet<Cause> rootCauses = rootCausesBuilder.build();
if (!rootCauses.isEmpty()) {
- eventBusRef.get().post(completor.createFailed(value, rootCauses));
+ env.getListener().post(completor.createFailed(value, rootCauses));
if (firstActionExecutionException != null) {
throw new CompletionFunctionException(firstActionExecutionException);
} else {
@@ -288,7 +314,14 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S
}
}
- return env.valuesMissing() ? null : completor.createResult(value);
+ // Only check for missing values *after* reporting errors: if there are missing files in a build
+ // with --nokeep_going, there may be missing dependencies during error bubbling, we still need
+ // to report the error.
+ if (env.valuesMissing()) {
+ return null;
+ }
+ env.getListener().post(completor.createSucceeded(skyKey, value, topLevelContext));
+ return completor.createResult(value);
}
@Override