diff options
author | 2017-02-28 18:49:50 +0000 | |
---|---|---|
committer | 2017-02-28 18:57:13 +0000 | |
commit | 8c3a4efce2882a8823df06b369e5d079765bed5b (patch) | |
tree | fed7bba6f7666d73087ead7aaa9f8b540f21bede /src/main/java/com/google/devtools/build/lib/buildtool | |
parent | 6525e389b854b2bb4e84a4145c0a3945d7e195bd (diff) |
BEP: Add BuildFinished event.
The build event protocol now emits a BuildFinished event at the end of a build. The event is a child of the BuildStarted event.
The code changes were larger than expected, due to some refactoring in BuildEventStreamer. This was necessary as the BuildCompleteEvent now implements the BuildEvent interface and Guava's EventBus always invokes the most specialized subscriber method. Thus, the buildEvent(BuildEvent) and buildCompleted(BuildCompletedEvent) methods had to be merged.
--
Change-Id: Id0c2bd7220dc8ce03128b7126587e212ee8ce836
Reviewed-on: https://cr.bazel.build/9053
PiperOrigin-RevId: 148788582
MOS_MIGRATED_REVID=148788582
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/buildtool')
2 files changed, 36 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java index 93416ba7ea..2412221513 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java @@ -14,19 +14,31 @@ package com.google.devtools.build.lib.buildtool.buildevent; +import static com.google.devtools.build.lib.util.Preconditions.checkNotNull; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.buildeventstream.BuildEvent; +import com.google.devtools.build.lib.buildeventstream.BuildEventId; +import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; +import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildFinished; +import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.devtools.build.lib.buildtool.BuildResult; +import java.util.Collection; /** * This event is fired from BuildTool#stopRequest(). + * + * <p>This class also implements the {@link BuildFinished} event of the build event protocol (BEP). */ -public final class BuildCompleteEvent { +public final class BuildCompleteEvent implements BuildEvent { private final BuildResult result; /** * Construct the BuildCompleteEvent. */ public BuildCompleteEvent(BuildResult result) { - this.result = result; + this.result = checkNotNull(result); } /** @@ -35,4 +47,24 @@ public final class BuildCompleteEvent { public BuildResult getResult() { return result; } + + @Override + public BuildEventId getEventId() { + return BuildEventId.buildFinished(); + } + + @Override + public Collection<BuildEventId> getChildrenEvents() { + return ImmutableList.of(); + } + + @Override + public BuildEventStreamProtos.BuildEvent asStreamProto(PathConverter pathConverter) { + BuildFinished finished = + BuildFinished.newBuilder() + .setOverallSuccess(result.getSuccess()) + .setFinishTimeMillis(result.getStopTime()) + .build(); + return GenericBuildEvent.protoChaining(this).setFinished(finished).build(); + } } diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildStartingEvent.java b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildStartingEvent.java index 3eff203b8d..71f7b0ca07 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildStartingEvent.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildStartingEvent.java @@ -82,7 +82,8 @@ public final class BuildStartingEvent implements BuildEvent { public Collection<BuildEventId> getChildrenEvents() { return ImmutableList.of( ProgressEvent.INITIAL_PROGRESS_UPDATE, - BuildEventId.targetPatternExpanded(request.getTargets())); + BuildEventId.targetPatternExpanded(request.getTargets()), + BuildEventId.buildFinished()); } @Override |