diff options
author | janakr <janakr@google.com> | 2018-07-13 00:52:17 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-13 00:53:50 -0700 |
commit | 75bc18a6290f9112077884460d61f34bec325814 (patch) | |
tree | bdf837d9c727acd915c8cf7c9a316cd8515f5348 /src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java | |
parent | b39c69394c5e7991ca8d04efac2142c22947a7c5 (diff) |
For all top-level artifacts, track the labels that own them when that is available.
The owning labels are the labels of the top-level configured targets that requested this artifact to be built (there may be many such targets). In cases where the artifact is added not through a configured target (build-info artifacts and coverage artifacts), the label of the artifact's owner is used.
PiperOrigin-RevId: 204432951
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java index bb714903b6..7730719fe1 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java @@ -16,14 +16,17 @@ package com.google.devtools.build.lib.analysis; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.collect.ImmutableCollection; -import com.google.common.collect.ImmutableList; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.SetMultimap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.test.TestProvider; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.skyframe.AspectValue; +import com.google.devtools.build.lib.util.RegexFilter; import javax.annotation.Nullable; /** @@ -115,48 +118,51 @@ public final class TopLevelArtifactHelper { // Prevent instantiation. } - /** - * Utility function to form a list of all test output Artifacts of the given targets to test. - */ - public static ImmutableCollection<Artifact> getAllArtifactsToTest( - Iterable<? extends TransitiveInfoCollection> targets) { - if (targets == null) { - return ImmutableList.of(); + @VisibleForTesting + public static SetMultimap<Artifact, Label> makeTopLevelArtifactsToOwnerLabels( + AnalysisResult analysisResult, Iterable<AspectValue> aspects) { + SetMultimap<Artifact, Label> topLevelArtifactsToOwnerLabels = + HashMultimap.create(analysisResult.getTopLevelArtifactsToOwnerLabels()); + TopLevelArtifactContext artifactContext = analysisResult.getTopLevelContext(); + for (ConfiguredTarget target : analysisResult.getTargetsToBuild()) { + addArtifactsWithOwnerLabel( + getAllArtifactsToBuild(target, artifactContext).getAllArtifacts(), + null, + target.getLabel(), + topLevelArtifactsToOwnerLabels); } - ImmutableList.Builder<Artifact> allTestArtifacts = ImmutableList.builder(); - for (TransitiveInfoCollection target : targets) { - allTestArtifacts.addAll(TestProvider.getTestStatusArtifacts(target)); + for (AspectValue aspect : aspects) { + addArtifactsWithOwnerLabel( + getAllArtifactsToBuild(aspect, artifactContext).getAllArtifacts(), + null, + aspect.getLabel(), + topLevelArtifactsToOwnerLabels); } - return allTestArtifacts.build(); - } - - /** - * Utility function to form a NestedSet of all top-level Artifacts of the given targets. - */ - public static ArtifactsToBuild getAllArtifactsToBuild( - Iterable<? extends TransitiveInfoCollection> targets, TopLevelArtifactContext context) { - NestedSetBuilder<ArtifactsInOutputGroup> artifacts = NestedSetBuilder.stableOrder(); - for (TransitiveInfoCollection target : targets) { - ArtifactsToBuild targetArtifacts = getAllArtifactsToBuild(target, context); - artifacts.addTransitive(targetArtifacts.getAllArtifactsByOutputGroup()); + if (analysisResult.getTargetsToTest() != null) { + for (ConfiguredTarget target : analysisResult.getTargetsToTest()) { + addArtifactsWithOwnerLabel( + TestProvider.getTestStatusArtifacts(target), + null, + target.getLabel(), + topLevelArtifactsToOwnerLabels); + } } - return new ArtifactsToBuild(artifacts.build()); + // TODO(dslomov): Artifacts to test from aspects? + return topLevelArtifactsToOwnerLabels; } - /** - * Utility function to form a NestedSet of all top-level Artifacts of the given targets. - */ - public static ArtifactsToBuild getAllArtifactsToBuildFromAspects( - Iterable<AspectValue> aspects, TopLevelArtifactContext context) { - NestedSetBuilder<ArtifactsInOutputGroup> artifacts = NestedSetBuilder.stableOrder(); - for (AspectValue aspect : aspects) { - ArtifactsToBuild aspectArtifacts = getAllArtifactsToBuild(aspect, context); - artifacts.addTransitive(aspectArtifacts.getAllArtifactsByOutputGroup()); + public static void addArtifactsWithOwnerLabel( + Iterable<Artifact> artifacts, + @Nullable RegexFilter filter, + Label ownerLabel, + SetMultimap<Artifact, Label> artifactToTopLevelLabels) { + for (Artifact artifact : artifacts) { + if (filter == null || filter.isIncluded(artifact.getOwnerLabel().toString())) { + artifactToTopLevelLabels.put(artifact, ownerLabel); + } } - return new ArtifactsToBuild(artifacts.build()); } - /** * Returns all artifacts to build if this target is requested as a top-level target. The resulting * set includes the temps and either the files to compile, if @@ -184,7 +190,7 @@ public final class TopLevelArtifactHelper { context); } - public static ArtifactsToBuild getAllArtifactsToBuild( + static ArtifactsToBuild getAllArtifactsToBuild( @Nullable OutputGroupInfo outputGroupInfo, @Nullable FileProvider fileProvider, TopLevelArtifactContext context) { |