aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2017-05-02 19:08:29 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-05-03 10:57:02 +0200
commit4b7df4f24c25bb84af968234c1adebc8f56eefb0 (patch)
tree77323f8c4b513e1bb715590677509ec8bdecfc77 /src/main/java
parentd7273274861801353a35ce0f4f5b70266e5cd6a7 (diff)
BEP: Add WorkspaceStatus
Add an event reporting the workspace status as key-value pairs reported via the workspace_status_command. Change-Id: I5791551798a594bc2465f483eb97f9d4fd4c7cfd PiperOrigin-RevId: 154845224
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/BuildInfoEvent.java38
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto18
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildStartingEvent.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java10
6 files changed, 76 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildInfoEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildInfoEvent.java
index af0c015c76..de67b6c974 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildInfoEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildInfoEvent.java
@@ -14,14 +14,18 @@
package com.google.devtools.build.lib.analysis;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-
+import com.google.devtools.build.lib.buildeventstream.BuildEvent;
+import com.google.devtools.build.lib.buildeventstream.BuildEventConverters;
+import com.google.devtools.build.lib.buildeventstream.BuildEventId;
+import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
+import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
+import java.util.Collection;
import java.util.Map;
-/**
- * This event is fired once build info data is available.
- */
-public final class BuildInfoEvent {
+/** This event is fired once build info data is available. */
+public final class BuildInfoEvent implements BuildEvent {
private final Map<String, String> buildInfoMap;
/**
@@ -37,4 +41,28 @@ public final class BuildInfoEvent {
public Map<String, String> getBuildInfoMap() {
return buildInfoMap;
}
+
+ @Override
+ public BuildEventId getEventId() {
+ return BuildEventId.workspaceStatusId();
+ }
+
+ @Override
+ public Collection<BuildEventId> getChildrenEvents() {
+ return ImmutableList.<BuildEventId>of();
+ }
+
+ @Override
+ public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) {
+ BuildEventStreamProtos.WorkspaceStatus.Builder status =
+ BuildEventStreamProtos.WorkspaceStatus.newBuilder();
+ for (Map.Entry<String, String> entry : getBuildInfoMap().entrySet()) {
+ status.addItem(
+ BuildEventStreamProtos.WorkspaceStatus.Item.newBuilder()
+ .setKey(entry.getKey())
+ .setValue(entry.getValue())
+ .build());
+ }
+ return GenericBuildEvent.protoChaining(this).setWorkspaceStatus(status.build()).build();
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java
index 2dbc2282a0..812c60a305 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java
@@ -33,6 +33,7 @@ import com.google.devtools.build.lib.actions.ExecutionStrategy;
import com.google.devtools.build.lib.actions.Root;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.BuildInfo;
+import com.google.devtools.build.lib.analysis.BuildInfoEvent;
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction;
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction.Key;
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction.KeyType;
@@ -219,6 +220,11 @@ public class BazelWorkspaceStatusModule extends BlazeModule {
}
volatileMap.put(BuildInfo.BUILD_TIMESTAMP, Long.toString(System.currentTimeMillis()));
+ Map<String, String> overallMap = new TreeMap<>();
+ overallMap.putAll(volatileMap);
+ overallMap.putAll(stableMap);
+ actionExecutionContext.getExecutor().getEventBus().post(new BuildInfoEvent(overallMap));
+
// Only update the stableStatus contents if they are different than what we have on disk.
// This is to preserve the old file's mtime so that we do not generate an unnecessary dirty
// file on each incremental build.
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java
index 0817d02c68..0e13b62b29 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java
@@ -99,6 +99,14 @@ public final class BuildEventId implements Serializable {
BuildEventStreamProtos.BuildEventId.newBuilder().setOptionsParsed(optionsParsedId).build());
}
+ public static BuildEventId workspaceStatusId() {
+ return new BuildEventId(
+ BuildEventStreamProtos.BuildEventId.newBuilder()
+ .setWorkspaceStatus(
+ BuildEventStreamProtos.BuildEventId.WorkspaceStatusId.getDefaultInstance())
+ .build());
+ }
+
private static BuildEventId targetPatternExpanded(List<String> targetPattern, boolean skipped) {
BuildEventStreamProtos.BuildEventId.PatternExpandedId patternId =
BuildEventStreamProtos.BuildEventId.PatternExpandedId.newBuilder()
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto
index 2f0c53e3ba..ea7aba800c 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto
@@ -54,6 +54,10 @@ message BuildEventId {
message CommandLineId {
}
+ // Identifier of an event indicating the workspace status.
+ message WorkspaceStatusId {
+ }
+
// Identifier on an event reporting on the options included in the command
// line, both explicitly and implicitly.
message OptionsParsedId {
@@ -120,6 +124,7 @@ message BuildEventId {
ProgressId progress = 2;
BuildStartedId started = 3;
CommandLineId command_line = 11;
+ WorkspaceStatusId workspace_status = 14;
OptionsParsedId options_parsed = 12;
PatternExpandedId pattern = 4;
PatternExpandedId pattern_skipped = 10;
@@ -225,6 +230,18 @@ message OptionsParsed {
repeated string explicit_cmd_line = 4;
}
+// Payload of an event reporting the workspace status. Key-value pairs can be
+// provided by specifying the workspace_status_command to an executable that
+// returns one key-value pair per line of output (key and value separated by a
+// space).
+message WorkspaceStatus {
+ message Item {
+ string key = 1;
+ string value = 2;
+ }
+ repeated Item item = 1;
+}
+
// Payload of the event indicating the expansion of a target pattern.
// The main information is in the chaining part: the id will contain the
// target pattern that was expanded and the children id will contain the
@@ -414,6 +431,7 @@ message BuildEvent {
BuildStarted started = 5;
CommandLine command_line = 12;
OptionsParsed options_parsed = 13;
+ WorkspaceStatus workspace_status = 16;
PatternExpanded expanded = 6;
ActionExecuted action = 7;
NamedSetOfFiles named_set_of_files = 15;
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 c13723cf67..e84df587de 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
@@ -84,6 +84,7 @@ public final class BuildStartingEvent implements BuildEvent {
ProgressEvent.INITIAL_PROGRESS_UPDATE,
BuildEventId.commandlineId(),
BuildEventId.optionsParsedId(),
+ BuildEventId.workspaceStatusId(),
BuildEventId.targetPatternExpanded(request.getTargets()),
BuildEventId.buildFinished());
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java
index e75ad1482f..b81341f54e 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java
@@ -29,6 +29,7 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.devtools.build.lib.actions.ActionExecutedEvent;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.EventReportingArtifacts;
+import com.google.devtools.build.lib.analysis.BuildInfoEvent;
import com.google.devtools.build.lib.analysis.NoBuildEvent;
import com.google.devtools.build.lib.buildeventstream.AbortedEvent;
import com.google.devtools.build.lib.buildeventstream.AnnounceBuildEventTransportsEvent;
@@ -182,6 +183,15 @@ public class BuildEventStreamer implements EventHandler {
postedEvents.add(linkEvent.getEventId());
}
}
+
+ if (event instanceof BuildInfoEvent) {
+ // The specification for BuildInfoEvent says that there may be many such events,
+ // but all except the first one should be ignored.
+ if (postedEvents.contains(id)) {
+ return;
+ }
+ }
+
postedEvents.add(id);
announcedEvents.addAll(event.getChildrenEvents());
}