aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/analysis
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2018-07-13 00:52:17 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-13 00:53:50 -0700
commit75bc18a6290f9112077884460d61f34bec325814 (patch)
treebdf837d9c727acd915c8cf7c9a316cd8515f5348 /src/main/java/com/google/devtools/build/lib/analysis
parentb39c69394c5e7991ca8d04efac2142c22947a7c5 (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')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/BuildView.java110
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java80
3 files changed, 107 insertions, 95 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java
index 401551333b..ff8dbe435b 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java
@@ -16,10 +16,12 @@ package com.google.devtools.build.lib.analysis;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.SetMultimap;
import com.google.devtools.build.lib.actions.ActionGraph;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.PackageRoots;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.skyframe.AspectValue;
import java.util.Collection;
import java.util.List;
@@ -35,7 +37,7 @@ public final class AnalysisResult {
private final ImmutableSet<ConfiguredTarget> targetsToSkip;
@Nullable private final String error;
private final ActionGraph actionGraph;
- private final ImmutableSet<Artifact> artifactsToBuild;
+ private final SetMultimap<Artifact, Label> topLevelArtifactsToOwnerLabels;
private final ImmutableSet<ConfiguredTarget> parallelTests;
private final ImmutableSet<ConfiguredTarget> exclusiveTests;
@Nullable private final TopLevelArtifactContext topLevelContext;
@@ -52,7 +54,7 @@ public final class AnalysisResult {
Collection<ConfiguredTarget> targetsToSkip,
@Nullable String error,
ActionGraph actionGraph,
- Collection<Artifact> artifactsToBuild,
+ SetMultimap<Artifact, Label> topLevelArtifactsToOwnerLabels,
Collection<ConfiguredTarget> parallelTests,
Collection<ConfiguredTarget> exclusiveTests,
TopLevelArtifactContext topLevelContext,
@@ -66,7 +68,7 @@ public final class AnalysisResult {
this.targetsToSkip = ImmutableSet.copyOf(targetsToSkip);
this.error = error;
this.actionGraph = actionGraph;
- this.artifactsToBuild = ImmutableSet.copyOf(artifactsToBuild);
+ this.topLevelArtifactsToOwnerLabels = topLevelArtifactsToOwnerLabels;
this.parallelTests = ImmutableSet.copyOf(parallelTests);
this.exclusiveTests = ImmutableSet.copyOf(exclusiveTests);
this.topLevelContext = topLevelContext;
@@ -120,8 +122,8 @@ public final class AnalysisResult {
return targetsToSkip;
}
- public ImmutableSet<Artifact> getAdditionalArtifactsToBuild() {
- return artifactsToBuild;
+ public SetMultimap<Artifact, Label> getTopLevelArtifactsToOwnerLabels() {
+ return topLevelArtifactsToOwnerLabels;
}
public ImmutableSet<ConfiguredTarget> getExclusiveTests() {
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 2143efaa19..caca6a7aef 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
@@ -14,18 +14,17 @@
package com.google.devtools.build.lib.analysis;
-import static com.google.common.collect.Iterables.concat;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
+import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
@@ -378,7 +377,7 @@ public class BuildView {
allTargetsToTest = filterTestsByTargets(configuredTargets, testsToRun);
}
- Set<Artifact> artifactsToBuild = new HashSet<>();
+ SetMultimap<Artifact, Label> topLevelArtifactsToOwnerLabels = HashMultimap.create();
Set<ConfiguredTarget> parallelTests = new HashSet<>();
Set<ConfiguredTarget> exclusiveTests = new HashSet<>();
@@ -386,15 +385,15 @@ public class BuildView {
Collection<Artifact> buildInfoArtifacts =
skyframeExecutor.getWorkspaceStatusArtifacts(eventHandler);
Preconditions.checkState(buildInfoArtifacts.size() == 2, buildInfoArtifacts);
- artifactsToBuild.addAll(buildInfoArtifacts);
+ addArtifactsWithNoOwner(buildInfoArtifacts, topLevelArtifactsToOwnerLabels);
// Extra actions
addExtraActionsIfRequested(
- viewOptions, configuredTargets, aspects, artifactsToBuild, eventHandler);
+ viewOptions, configuredTargets, aspects, topLevelArtifactsToOwnerLabels, eventHandler);
// Coverage
- NestedSet<Artifact> baselineCoverageArtifacts = getBaselineCoverageArtifacts(configuredTargets);
- Iterables.addAll(artifactsToBuild, baselineCoverageArtifacts);
+ NestedSet<Artifact> baselineCoverageArtifacts =
+ getBaselineCoverageArtifacts(configuredTargets, topLevelArtifactsToOwnerLabels);
if (coverageReportActionFactory != null) {
CoverageReportActionsWrapper actionsWrapper;
actionsWrapper =
@@ -409,7 +408,8 @@ public class BuildView {
if (actionsWrapper != null) {
ImmutableList<ActionAnalysisMetadata> actions = actionsWrapper.getActions();
skyframeExecutor.injectCoverageReportData(actions);
- artifactsToBuild.addAll(actionsWrapper.getCoverageOutputs());
+ addArtifactsWithNoOwner(
+ actionsWrapper.getCoverageOutputs(), topLevelArtifactsToOwnerLabels);
}
}
@@ -453,7 +453,7 @@ public class BuildView {
targetsToSkip,
error,
actionGraph,
- artifactsToBuild,
+ topLevelArtifactsToOwnerLabels,
parallelTests,
exclusiveTests,
topLevelOptions,
@@ -462,6 +462,11 @@ public class BuildView {
topLevelTargetsWithConfigs);
}
+ private static void addArtifactsWithNoOwner(
+ Collection<Artifact> artifacts, SetMultimap<Artifact, Label> topLevelArtifactsToOwnerLabels) {
+ artifacts.forEach((a) -> topLevelArtifactsToOwnerLabels.put(a, a.getOwnerLabel()));
+ }
+
@Nullable
public static String createErrorMessage(
LoadingResult loadingResult, @Nullable SkyframeAnalysisResult skyframeAnalysisResult) {
@@ -476,11 +481,17 @@ public class BuildView {
}
private static NestedSet<Artifact> getBaselineCoverageArtifacts(
- Collection<ConfiguredTarget> configuredTargets) {
+ Collection<ConfiguredTarget> configuredTargets,
+ SetMultimap<Artifact, Label> topLevelArtifactsToOwnerLabels) {
NestedSetBuilder<Artifact> baselineCoverageArtifacts = NestedSetBuilder.stableOrder();
for (ConfiguredTarget target : configuredTargets) {
InstrumentedFilesProvider provider = target.getProvider(InstrumentedFilesProvider.class);
if (provider != null) {
+ TopLevelArtifactHelper.addArtifactsWithOwnerLabel(
+ provider.getBaselineCoverageArtifacts(),
+ null,
+ target.getLabel(),
+ topLevelArtifactsToOwnerLabels);
baselineCoverageArtifacts.addTransitive(provider.getBaselineCoverageArtifacts());
}
}
@@ -491,28 +502,9 @@ public class BuildView {
AnalysisOptions viewOptions,
Collection<ConfiguredTarget> configuredTargets,
Collection<AspectValue> aspects,
- Set<Artifact> artifactsToBuild,
+ SetMultimap<Artifact, Label> artifactsToTopLevelLabelsMap,
ExtendedEventHandler eventHandler) {
- Iterable<Artifact> extraActionArtifacts =
- concat(
- addExtraActionsFromTargets(viewOptions, configuredTargets, eventHandler),
- addExtraActionsFromAspects(viewOptions, aspects));
-
RegexFilter filter = viewOptions.extraActionFilter;
- for (Artifact artifact : extraActionArtifacts) {
- boolean filterMatches =
- filter == null || filter.isIncluded(artifact.getOwnerLabel().toString());
- if (filterMatches) {
- artifactsToBuild.add(artifact);
- }
- }
- }
-
- private NestedSet<Artifact> addExtraActionsFromTargets(
- AnalysisOptions viewOptions,
- Collection<ConfiguredTarget> configuredTargets,
- ExtendedEventHandler eventHandler) {
- NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder();
for (ConfiguredTarget target : configuredTargets) {
ExtraActionArtifactsProvider provider =
target.getProvider(ExtraActionArtifactsProvider.class);
@@ -530,17 +522,46 @@ public class BuildView {
for (Attribute attr : actualTarget.getAssociatedRule().getAttributes()) {
aspectClasses.addAll(attr.getAspectClasses());
}
-
- builder.addTransitive(provider.getExtraActionArtifacts());
+ TopLevelArtifactHelper.addArtifactsWithOwnerLabel(
+ provider.getExtraActionArtifacts(),
+ filter,
+ target.getLabel(),
+ artifactsToTopLevelLabelsMap);
if (!aspectClasses.isEmpty()) {
- builder.addAll(filterTransitiveExtraActions(provider, aspectClasses));
+ TopLevelArtifactHelper.addArtifactsWithOwnerLabel(
+ filterTransitiveExtraActions(provider, aspectClasses),
+ filter,
+ target.getLabel(),
+ artifactsToTopLevelLabelsMap);
}
} else {
- builder.addTransitive(provider.getTransitiveExtraActionArtifacts());
+ TopLevelArtifactHelper.addArtifactsWithOwnerLabel(
+ provider.getTransitiveExtraActionArtifacts(),
+ filter,
+ target.getLabel(),
+ artifactsToTopLevelLabelsMap);
+ }
+ }
+ }
+ for (AspectValue aspect : aspects) {
+ ExtraActionArtifactsProvider provider =
+ aspect.getConfiguredAspect().getProvider(ExtraActionArtifactsProvider.class);
+ if (provider != null) {
+ if (viewOptions.extraActionTopLevelOnly) {
+ TopLevelArtifactHelper.addArtifactsWithOwnerLabel(
+ provider.getExtraActionArtifacts(),
+ filter,
+ aspect.getLabel(),
+ artifactsToTopLevelLabelsMap);
+ } else {
+ TopLevelArtifactHelper.addArtifactsWithOwnerLabel(
+ provider.getTransitiveExtraActionArtifacts(),
+ filter,
+ aspect.getLabel(),
+ artifactsToTopLevelLabelsMap);
}
}
}
- return builder.build();
}
/**
@@ -563,23 +584,6 @@ public class BuildView {
return artifacts.build();
}
- private NestedSet<Artifact> addExtraActionsFromAspects(
- AnalysisOptions viewOptions, Collection<AspectValue> aspects) {
- NestedSetBuilder<Artifact> builder = NestedSetBuilder.stableOrder();
- for (AspectValue aspect : aspects) {
- ExtraActionArtifactsProvider provider =
- aspect.getConfiguredAspect().getProvider(ExtraActionArtifactsProvider.class);
- if (provider != null) {
- if (viewOptions.extraActionTopLevelOnly) {
- builder.addTransitive(provider.getExtraActionArtifacts());
- } else {
- builder.addTransitive(provider.getTransitiveExtraActionArtifacts());
- }
- }
- }
- return builder.build();
- }
-
private static void scheduleTestsIfRequested(
Collection<ConfiguredTarget> targetsToTest,
Collection<ConfiguredTarget> targetsToTestExclusive,
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) {