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 93254c793c4c6f..7e3d82b5628dbf 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 @@ -404,7 +404,23 @@ message Configuration { // 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 // target or target pattern it was expanded to. -message PatternExpanded {} +message PatternExpanded { + // Represents a test_suite target and the tests that it expanded to. Nested + // test suites are recursively expanded. The test labels only contain the + // final test targets, not any nested suites. + message TestSuiteExpansion { + // The label of the test_suite rule. + string suite_label = 1; + // Labels of the test targets included in the suite. Includes all tests in + // the suite regardless of any filters or negative patterns which may result + // in the test not actually being run. + repeated string test_labels = 2; + } + + // All test suites requested via top-level target patterns. Does not include + // test suites whose label matched a negative pattern. + repeated TestSuiteExpansion test_suite_expansions = 1; +} // Enumeration type characterizing the size of a test, as specified by the // test rule. diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/TargetParsingCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetParsingCompleteEvent.java index bc1bc9f91f599c..9d2a7ccebdd9fa 100644 --- a/src/main/java/com/google/devtools/build/lib/pkgcache/TargetParsingCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetParsingCompleteEvent.java @@ -13,9 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.pkgcache; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.Iterables; @@ -23,6 +24,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId; +import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.PatternExpanded; import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint; import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; import com.google.devtools.build.lib.cmdline.Label; @@ -79,12 +81,8 @@ public boolean isNotATestOrTestSuite() { private final ImmutableSet testFilteredTargets; private final ImmutableSet expandedTargets; private final ImmutableSetMultimap originalPatternsToLabels; + private final ImmutableMap> testSuiteExpansions; - /** - * Construct the event. - * - * @param targets The targets that were parsed from the command-line pattern. - */ public TargetParsingCompleteEvent( Collection targets, Collection filteredTargets, @@ -92,26 +90,16 @@ public TargetParsingCompleteEvent( ImmutableList originalTargetPattern, Collection expandedTargets, ImmutableList failedTargetPatterns, - ImmutableSetMultimap originalPatternsToLabels) { + ImmutableSetMultimap originalPatternsToLabels, + ImmutableMap> testSuiteExpansions) { this.targets = asThinTargets(targets); this.filteredTargets = asThinTargets(filteredTargets); this.testFilteredTargets = asThinTargets(testFilteredTargets); this.originalTargetPattern = Preconditions.checkNotNull(originalTargetPattern); this.expandedTargets = asThinTargets(expandedTargets); this.failedTargetPatterns = Preconditions.checkNotNull(failedTargetPatterns); - this.originalPatternsToLabels = originalPatternsToLabels; - } - - @VisibleForTesting - public TargetParsingCompleteEvent(Collection targets) { - this( - targets, - ImmutableSet.of(), - ImmutableSet.of(), - ImmutableList.of(), - targets, - ImmutableList.of(), - ImmutableSetMultimap.of()); + this.originalPatternsToLabels = Preconditions.checkNotNull(originalPatternsToLabels); + this.testSuiteExpansions = Preconditions.checkNotNull(testSuiteExpansions); } public ImmutableList getOriginalTargetPattern() { @@ -181,7 +169,7 @@ public Collection getChildrenEvents() { BuildEventIdUtil.targetPatternExpanded(ImmutableList.of(failedTargetPattern))); } for (ThinTarget target : expandedTargets) { - // Test suits won't produce target configuration and target-complete events, so do not + // Test suites won't produce target configuration and target-complete events, so do not // announce here completion as children. if (!target.isTestSuiteRule()) { childrenBuilder.add(BuildEventIdUtil.targetConfigured(target.getLabel())); @@ -192,9 +180,15 @@ public Collection getChildrenEvents() { @Override public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) { - return GenericBuildEvent.protoChaining(this) - .setExpanded(BuildEventStreamProtos.PatternExpanded.newBuilder().build()) - .build(); + PatternExpanded.Builder expanded = PatternExpanded.newBuilder(); + testSuiteExpansions.forEach( + (suite, tests) -> + expanded + .addTestSuiteExpansionsBuilder() + .setSuiteLabel(suite.toString()) + .addAllTestLabels(Collections2.transform(tests, Label::toString))); + + return GenericBuildEvent.protoChaining(this).setExpanded(expanded).build(); } private static ImmutableSet asThinTargets(Collection targets) { diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java index 6a373dd0f7e219..6cd4c7846fab9d 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java @@ -188,15 +188,18 @@ public TargetPatternPhaseValue compute(SkyKey key, Environment env) throws Inter maybeReportDeprecation(env.getListener(), targets.getTargets()); ResolvedTargets.Builder