Skip to content

Commit 4fca652

Browse files
joelebacopybara-github
authored andcommitted
Add the missing build status for skymeld.
Skymeld, prior to this CL, has been missing the aggregators setup for targets. Therefore the targets' statuses in the BEP were always reported as "aborted". This CL adds the aggregators when a target (including tests) is ready to be executed. PiperOrigin-RevId: 459696157 Change-Id: I109cbdef7051cbcc73cc0b11e5364a7612c140a3
1 parent d35f923 commit 4fca652

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

src/main/java/com/google/devtools/build/lib/runtime/TargetSummaryPublisher.java

+42-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import com.google.devtools.build.lib.concurrent.ThreadSafety;
3535
import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey;
3636
import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
37+
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelTargetPendingExecutionEvent;
3738
import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
39+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3840
import com.google.errorprone.annotations.concurrent.GuardedBy;
3941
import java.util.Collection;
4042
import java.util.concurrent.ConcurrentHashMap;
@@ -79,8 +81,6 @@ public void buildStarting(BuildStartingEvent event) {
7981
*/
8082
@Subscribe
8183
public void populateTargets(TestFilteringCompleteEvent event) {
82-
int expectedCompletions = aspectCount.get() + 1; // + 1 for target itself
83-
checkState(expectedCompletions > 0, "Haven't received BuildStartingEvent");
8484
ImmutableSet<ConfiguredTarget> testTargets =
8585
event.getTestTargets() != null
8686
? ImmutableSet.copyOf(event.getTestTargets())
@@ -92,16 +92,48 @@ public void populateTargets(TestFilteringCompleteEvent event) {
9292
// we'll still get (and ignore) a TestSummary event, but that event isn't published to BEP.
9393
continue;
9494
}
95-
// We want target summaries for alias targets, but note they don't receive test summaries.
96-
TargetSummaryAggregator aggregator =
97-
new TargetSummaryAggregator(
98-
target,
99-
expectedCompletions,
100-
!AliasProvider.isAlias(target) && testTargets.contains(target));
101-
TargetSummaryAggregator oldAggregator = aggregators.put(asKey(target), aggregator);
95+
TargetSummaryAggregator oldAggregator =
96+
replaceAggregatorForTarget(/*isTest=*/ testTargets.contains(target), target);
10297
checkState(
103-
oldAggregator == null, "target: %s, values: %s %s", target, oldAggregator, aggregator);
98+
oldAggregator == null,
99+
"target: %s, values: %s %s",
100+
target,
101+
oldAggregator,
102+
aggregators.get(asKey(target)));
103+
}
104+
}
105+
106+
/**
107+
* Populates the aggregator for a particular top level target, including test targets.
108+
*
109+
* <p>Since the event is fired from within a SkyFunction, it is possible to receive duplicate
110+
* events. In case of duplication, simply return without creating any new aggregator.
111+
*/
112+
@Subscribe
113+
@AllowConcurrentEvents
114+
public void populateTarget(TopLevelTargetPendingExecutionEvent event) {
115+
replaceAggregatorForTarget(event.isTest(), event.configuredTarget());
116+
}
117+
118+
/**
119+
* Creates a TargetSummaryAggregator for the given target and stores it in {@link aggregators}
120+
*
121+
* @return the existing aggregator, if any.
122+
*/
123+
@Nullable
124+
@CanIgnoreReturnValue
125+
private TargetSummaryAggregator replaceAggregatorForTarget(
126+
boolean isTest, ConfiguredTarget target) {
127+
if (aggregators.containsKey(asKey(target))) {
128+
return null;
104129
}
130+
int expectedCompletions = aspectCount.get() + 1; // + 1 for target itself
131+
checkState(expectedCompletions > 0, "Haven't received BuildStartingEvent");
132+
// We want target summaries for alias targets, but note they don't receive test summaries.
133+
TargetSummaryAggregator aggregator =
134+
new TargetSummaryAggregator(
135+
target, expectedCompletions, isTest && !AliasProvider.isAlias(target));
136+
return aggregators.put(asKey(target), aggregator);
105137
}
106138

107139
@Subscribe

src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverFunction.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
import com.google.devtools.build.lib.skyframe.AspectCompletionValue.AspectCompletionKey;
5555
import com.google.devtools.build.lib.skyframe.AspectKeyCreator.AspectKey;
5656
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.AspectAnalyzedEvent;
57+
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.SomeExecutionStartedEvent;
5758
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TestAnalyzedEvent;
5859
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelTargetAnalyzedEvent;
59-
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelTargetExecutionStartedEvent;
60+
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelTargetPendingExecutionEvent;
6061
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelTargetSkippedEvent;
6162
import com.google.devtools.build.lib.util.RegexFilter;
6263
import com.google.devtools.build.skyframe.SkyFunction;
6364
import com.google.devtools.build.skyframe.SkyFunction.Environment.SkyKeyComputeState;
6465
import com.google.devtools.build.skyframe.SkyFunctionException;
65-
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
6666
import com.google.devtools.build.skyframe.SkyKey;
6767
import com.google.devtools.build.skyframe.SkyValue;
6868
import com.google.devtools.build.skyframe.SkyframeIterableResult;
@@ -187,6 +187,10 @@ public SkyValue compute(SkyKey skyKey, Environment env)
187187
}
188188
}
189189

190+
env.getListener()
191+
.post(
192+
TopLevelTargetPendingExecutionEvent.create(
193+
configuredTarget, buildDriverKey.isTest()));
190194
requestConfiguredTargetExecution(
191195
configuredTarget,
192196
buildDriverKey,
@@ -296,7 +300,7 @@ private void requestConfiguredTargetExecution(
296300
ImmutableSet.Builder<Artifact> artifactsToBuild = ImmutableSet.builder();
297301
addExtraActionsIfRequested(
298302
configuredTarget.getProvider(ExtraActionArtifactsProvider.class), artifactsToBuild);
299-
env.getListener().post(TopLevelTargetExecutionStartedEvent.create());
303+
env.getListener().post(SomeExecutionStartedEvent.create());
300304
if (NOT_TEST.equals(buildDriverKey.getTestType())) {
301305
declareDependenciesAndCheckValues(
302306
env,
@@ -337,7 +341,7 @@ private void requestAspectExecution(
337341
TopLevelArtifactContext topLevelArtifactContext)
338342
throws InterruptedException {
339343

340-
env.getListener().post(TopLevelTargetExecutionStartedEvent.create());
344+
env.getListener().post(SomeExecutionStartedEvent.create());
341345
ImmutableSet.Builder<Artifact> artifactsToBuild = ImmutableSet.builder();
342346
List<SkyKey> aspectCompletionKeys = new ArrayList<>();
343347
for (SkyValue aspectValue : topLevelAspectsValue.getTopLevelAspectsValues()) {

src/main/java/com/google/devtools/build/lib/skyframe/BuildDriverKey.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public ActionLookupKey getActionLookupKey() {
8484
}
8585

8686
public boolean isTest() {
87-
return TestType.NOT_TEST.equals(testType);
87+
return !TestType.NOT_TEST.equals(testType);
8888
}
8989

9090
public TestType getTestType() {

src/main/java/com/google/devtools/build/lib/skyframe/TopLevelStatusEvents.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,29 @@ public static TopLevelTargetSkippedEvent create(ConfiguredTarget configuredTarge
5353
}
5454
}
5555

56-
/** An event that marks the start of execution of a top-level target, including tests. */
56+
/**
57+
* An event that marks that a top-level target won't be skipped and is pending execution,
58+
* including test targets.
59+
*/
5760
@AutoValue
58-
public abstract static class TopLevelTargetExecutionStartedEvent implements Postable {
61+
public abstract static class TopLevelTargetPendingExecutionEvent implements Postable {
62+
public abstract ConfiguredTarget configuredTarget();
63+
64+
public abstract boolean isTest();
65+
66+
public static TopLevelTargetPendingExecutionEvent create(
67+
ConfiguredTarget configuredTarget, boolean isTest) {
68+
return new AutoValue_TopLevelStatusEvents_TopLevelTargetPendingExecutionEvent(
69+
configuredTarget, isTest);
70+
}
71+
}
72+
73+
/** An event that denotes that some execution has started in this build. */
74+
@AutoValue
75+
public abstract static class SomeExecutionStartedEvent implements Postable {
5976

60-
public static TopLevelTargetExecutionStartedEvent create() {
61-
return new AutoValue_TopLevelStatusEvents_TopLevelTargetExecutionStartedEvent();
77+
public static SomeExecutionStartedEvent create() {
78+
return new AutoValue_TopLevelStatusEvents_SomeExecutionStartedEvent();
6279
}
6380
}
6481
/** An event that marks the successful build of a top-level target, including tests. */

0 commit comments

Comments
 (0)