aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-08-10 09:03:26 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-10 09:04:58 -0700
commit3df620a1ef16e81780d7af40cd2dfa3251d40668 (patch)
treef1bd2797215caa3c0e8c6693b32211c98cdbf9f2
parentfc0654ff3798309c8b412220b1202f12059fd1ff (diff)
Persist mappings from original command line patterns to expanded labels in TargetParsingCompleteEvent.
PiperOrigin-RevId: 208217102
-rw-r--r--src/main/java/com/google/devtools/build/lib/pkgcache/TargetParsingCompleteEvent.java29
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java23
-rw-r--r--src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java29
3 files changed, 75 insertions, 6 deletions
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 5266ae5cb2..0028fd5792 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
@@ -17,6 +17,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
import com.google.devtools.build.lib.buildeventstream.BuildEventId;
@@ -77,6 +78,7 @@ public class TargetParsingCompleteEvent implements BuildEventWithOrderConstraint
private final ImmutableSet<ThinTarget> filteredTargets;
private final ImmutableSet<ThinTarget> testFilteredTargets;
private final ImmutableSet<ThinTarget> expandedTargets;
+ private final ImmutableSetMultimap<String, Label> originalPatternsToLabels;
/**
* Construct the event.
@@ -89,24 +91,27 @@ public class TargetParsingCompleteEvent implements BuildEventWithOrderConstraint
Collection<Target> testFilteredTargets,
List<String> originalTargetPattern,
Collection<Target> expandedTargets,
- List<String> failedTargetPatterns) {
+ List<String> failedTargetPatterns,
+ ImmutableSetMultimap<String, Label> originalPatternsToLabels) {
this.targets = asThinTargets(targets);
this.filteredTargets = asThinTargets(filteredTargets);
this.testFilteredTargets = asThinTargets(testFilteredTargets);
this.originalTargetPattern = ImmutableList.copyOf(originalTargetPattern);
this.expandedTargets = asThinTargets(expandedTargets);
this.failedTargetPatterns = ImmutableList.copyOf(failedTargetPatterns);
+ this.originalPatternsToLabels = originalPatternsToLabels;
}
@VisibleForTesting
public TargetParsingCompleteEvent(Collection<Target> targets) {
this(
targets,
- ImmutableSet.<Target>of(),
- ImmutableSet.<Target>of(),
- ImmutableList.<String>of(),
+ ImmutableSet.of(),
+ ImmutableSet.of(),
+ ImmutableList.of(),
targets,
- ImmutableList.<String>of());
+ ImmutableList.of(),
+ ImmutableSetMultimap.of());
}
public ImmutableList<String> getOriginalTargetPattern() {
@@ -144,6 +149,20 @@ public class TargetParsingCompleteEvent implements BuildEventWithOrderConstraint
return testFilteredTargets;
}
+ /**
+ * Returns a mapping from patterns originally passed on the command line to the labels they were
+ * expanded to.
+ *
+ * <p>Negative patterns are not included here. Neither are labels of targets that are skipped due
+ * to matching a negative pattern (even if they also matched a positive pattern).
+ *
+ * <p>Test suite labels are included here, but not the labels of the tests that the suite expanded
+ * to.
+ */
+ public ImmutableSetMultimap<String, Label> getOriginalPatternsToLabels() {
+ return originalPatternsToLabels;
+ }
+
@Override
public BuildEventId getEventId() {
return BuildEventId.targetPatternExpanded(originalTargetPattern);
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 955649065e..afd09b5781 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
@@ -13,10 +13,13 @@
// limitations under the License.
package com.google.devtools.build.lib.skyframe;
+import static com.google.common.collect.ImmutableSetMultimap.flatteningToImmutableSetMultimap;
+
import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.cmdline.Label;
@@ -218,7 +221,8 @@ final class TargetPatternPhaseFunction implements SkyFunction {
testFilteredTargets,
options.getTargetPatterns(),
expandedTargets.getTargets(),
- failedPatterns));
+ failedPatterns,
+ mapOriginalPatternsToLabels(expandedPatterns, targets.getTargets())));
env.getListener()
.post(new LoadingPhaseCompleteEvent(result.getTargetLabels(), removedTargetLabels));
return result;
@@ -436,6 +440,23 @@ final class TargetPatternPhaseFunction implements SkyFunction {
return testTargetsBuilder.build();
}
+ private static ImmutableSetMultimap<String, Label> mapOriginalPatternsToLabels(
+ List<ExpandedPattern> expandedPatterns, Set<Target> includedTargets) {
+ return expandedPatterns
+ .stream()
+ .filter(expansion -> !expansion.pattern().isNegative())
+ .collect(
+ flatteningToImmutableSetMultimap(
+ expansion -> expansion.pattern().getPattern(),
+ expansion ->
+ expansion
+ .resolvedTargets()
+ .getTargets()
+ .stream()
+ .filter(includedTargets::contains)
+ .map(Target::getLabel)));
+ }
+
@Nullable
@Override
public String extractTag(SkyKey skyKey) {
diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java
index fdb6e80755..29ff98f98f 100644
--- a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java
@@ -23,6 +23,7 @@ import com.google.common.base.Predicate;
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;
import com.google.common.collect.Iterators;
import com.google.common.collect.MoreCollectors;
@@ -695,6 +696,30 @@ public class LoadingPhaseRunnerTest {
assertThat(err.getPattern()).containsExactly("//test:cycle1");
}
+ @Test
+ public void mapsOriginalPatternsToLabels() throws Exception {
+ tester.addFile("test/a/BUILD", "cc_library(name = 'a_lib', srcs = ['a.cc'])");
+ tester.addFile("test/b/BUILD", "cc_library(name = 'b_lib', srcs = ['b.cc'])");
+
+ tester.load("test/a:all", "test/b:all", "test/...");
+
+ assertThat(tester.getOriginalPatternsToLabels())
+ .containsExactly(
+ "test/a:all", Label.parseAbsoluteUnchecked("//test/a:a_lib"),
+ "test/b:all", Label.parseAbsoluteUnchecked("//test/b:b_lib"),
+ "test/...", Label.parseAbsoluteUnchecked("//test/a:a_lib"),
+ "test/...", Label.parseAbsoluteUnchecked("//test/b:b_lib"));
+ }
+
+ @Test
+ public void mapsOriginalPatternsToLabels_omitsExcludedTargets() throws Exception {
+ tester.addFile("test/a/BUILD", "cc_library(name = 'a_lib', srcs = ['a.cc'])");
+
+ tester.load("test/...", "-test/a:a_lib");
+
+ assertThat(tester.getOriginalPatternsToLabels()).isEmpty();
+ }
+
private static class LoadingPhaseTester {
private final ManualClock clock = new ManualClock();
private final Path workspace;
@@ -891,6 +916,10 @@ public class LoadingPhaseRunnerTest {
return ImmutableSet.copyOf(targetParsingCompleteEvent.getLabels());
}
+ public ImmutableSetMultimap<String, Label> getOriginalPatternsToLabels() {
+ return targetParsingCompleteEvent.getOriginalPatternsToLabels();
+ }
+
public ImmutableSet<Label> getTestSuiteTargets() {
return loadingPhaseCompleteEvent.getFilteredLabels();
}