BEP: move configuration-independent information to TargetConfigured event
Some information about a target is configuration independent and therefore can
already be provided at a target level (i.e., in the TargetConfigured event). Do
so, to have that information available earlier and, once the deprecation period
is over, avoid redundant information in the stream.
Change-Id: I8021ce3dd2a8168d409ea513190c4e3a349dbc2f
PiperOrigin-RevId: 164967059
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index 87cb74a..559cad1 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -507,8 +507,8 @@
for (TargetAndConfiguration pair : topLevelTargetsWithConfigs) {
byLabel.put(pair.getLabel(), pair.getConfiguration());
}
- for (Label label : byLabel.keySet()) {
- eventBus.post(new TargetConfiguredEvent(label, byLabel.get(label)));
+ for (Target target : targets) {
+ eventBus.post(new TargetConfiguredEvent(target, byLabel.get(target.getLabel())));
}
List<ConfiguredTargetKey> topLevelCtKeys = Lists.transform(topLevelTargetsWithConfigs,
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
index 48ac8fb..4f2ee3b 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
@@ -146,21 +146,6 @@
return childrenBuilder.build();
}
- private BuildEventStreamProtos.TestSize bepTestSize(TestSize size) {
- switch (size) {
- case SMALL:
- return BuildEventStreamProtos.TestSize.SMALL;
- case MEDIUM:
- return BuildEventStreamProtos.TestSize.MEDIUM;
- case LARGE:
- return BuildEventStreamProtos.TestSize.LARGE;
- case ENORMOUS:
- return BuildEventStreamProtos.TestSize.ENORMOUS;
- default:
- return BuildEventStreamProtos.TestSize.UNKNOWN;
- }
- }
-
@Override
public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) {
BuildEventStreamProtos.TargetComplete.Builder builder =
@@ -173,7 +158,8 @@
if (isTest) {
builder.setTestSize(
- bepTestSize(TestSize.getTestSize(target.getTarget().getAssociatedRule())));
+ TargetConfiguredEvent.bepTestSize(
+ TestSize.getTestSize(target.getTarget().getAssociatedRule())));
}
// TODO(aehlig): remove direct reporting of artifacts as soon as clients no longer
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java
index 56ddc4d..8395337 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java
@@ -22,17 +22,19 @@
import com.google.devtools.build.lib.buildeventstream.BuildEventWithConfiguration;
import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
import com.google.devtools.build.lib.buildeventstream.NullConfiguration;
-import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.packages.Target;
+import com.google.devtools.build.lib.packages.TargetUtils;
+import com.google.devtools.build.lib.packages.TestSize;
import java.util.Collection;
/** Event reporting about the configurations associated with a given target */
public class TargetConfiguredEvent implements BuildEventWithConfiguration {
- private final Label label;
+ private final Target target;
private final Collection<BuildConfiguration> configurations;
- TargetConfiguredEvent(Label label, Collection<BuildConfiguration> configurations) {
- this.label = label;
+ TargetConfiguredEvent(Target target, Collection<BuildConfiguration> configurations) {
this.configurations = configurations;
+ this.target = target;
}
@Override
@@ -50,7 +52,7 @@
@Override
public BuildEventId getEventId() {
- return BuildEventId.targetConfigured(label);
+ return BuildEventId.targetConfigured(target.getLabel());
}
@Override
@@ -58,19 +60,37 @@
ImmutableList.Builder childrenBuilder = ImmutableList.builder();
for (BuildConfiguration config : configurations) {
if (config != null) {
- childrenBuilder.add(BuildEventId.targetCompleted(label, config.getEventId()));
+ childrenBuilder.add(BuildEventId.targetCompleted(target.getLabel(), config.getEventId()));
} else {
childrenBuilder.add(
- BuildEventId.targetCompleted(label, BuildEventId.nullConfigurationId()));
+ BuildEventId.targetCompleted(target.getLabel(), BuildEventId.nullConfigurationId()));
}
}
return childrenBuilder.build();
}
+ static BuildEventStreamProtos.TestSize bepTestSize(TestSize size) {
+ switch (size) {
+ case SMALL:
+ return BuildEventStreamProtos.TestSize.SMALL;
+ case MEDIUM:
+ return BuildEventStreamProtos.TestSize.MEDIUM;
+ case LARGE:
+ return BuildEventStreamProtos.TestSize.LARGE;
+ case ENORMOUS:
+ return BuildEventStreamProtos.TestSize.ENORMOUS;
+ default:
+ return BuildEventStreamProtos.TestSize.UNKNOWN;
+ }
+ }
+
@Override
public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) {
- return GenericBuildEvent.protoChaining(this)
- .setConfigured(BuildEventStreamProtos.TargetConfigured.getDefaultInstance())
- .build();
+ BuildEventStreamProtos.TargetConfigured.Builder builder =
+ BuildEventStreamProtos.TargetConfigured.newBuilder().setTargetKind(target.getTargetKind());
+ if (TargetUtils.isTestRule(target)) {
+ builder.setTestSize(bepTestSize(TestSize.getTestSize(target.getAssociatedRule())));
+ }
+ return GenericBuildEvent.protoChaining(this).setConfigured(builder.build()).build();
}
}