diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
17 files changed, 108 insertions, 186 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java index 7ecdede085..e47d0e3bd6 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java @@ -301,11 +301,11 @@ public class Artifact } /** - * Get the {@code LabelAndConfiguration} of the {@code ConfiguredTarget} that owns this artifact, - * if it was set. Otherwise, this should be a dummy value -- either {@link - * ArtifactOwner#NULL_OWNER} or a dummy owner set in tests. Such a dummy value should only occur - * for source artifacts if created without specifying the owner, or for special derived artifacts, - * such as target completion middleman artifacts, build info artifacts, and the like. + * Gets the {@code ActionLookupKey} of the {@code ConfiguredTarget} that owns this artifact, if it + * was set. Otherwise, this should be a dummy value -- either {@link ArtifactOwner#NULL_OWNER} or + * a dummy owner set in tests. Such a dummy value should only occur for source artifacts if + * created without specifying the owner, or for special derived artifacts, such as target + * completion middleman artifacts, build info artifacts, and the like. */ public final ArtifactOwner getArtifactOwner() { return owner; diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java index 94f29632c6..597893f6b5 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactOwner.java @@ -17,23 +17,24 @@ import com.google.common.annotations.VisibleForTesting; import com.google.devtools.build.lib.cmdline.Label; /** - * An interface for {@code LabelAndConfiguration}, or at least for a {@link Label}. Only tests and - * internal {@link Artifact}-generators should implement this interface -- otherwise, - * {@code LabelAndConfiguration} should be the only implementation. + * An interface for {@code ActionLookupKey}, or at least for a {@link Label}. Only tests and + * internal {@link Artifact}-generators should implement this interface -- otherwise, {@code + * ActionLookupKey} and its subclasses should be the only implementation. */ public interface ArtifactOwner { Label getLabel(); @VisibleForTesting - public static final ArtifactOwner NULL_OWNER = new ArtifactOwner() { - @Override - public Label getLabel() { - return null; - } + ArtifactOwner NULL_OWNER = + new ArtifactOwner() { + @Override + public Label getLabel() { + return null; + } - @Override - public String toString() { - return "NULL_OWNER"; - } - }; + @Override + public String toString() { + return "NULL_OWNER"; + } + }; } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java index 0bc37b7d0f..0893a8e4d3 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisFailureEvent.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.analysis; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; /** * This event is fired during the build, when it becomes known that the analysis @@ -22,15 +23,15 @@ import com.google.devtools.build.lib.cmdline.Label; * dependencies. */ public class AnalysisFailureEvent { - private final LabelAndConfiguration failedTarget; + private final ConfiguredTargetKey failedTarget; private final Label failureReason; - public AnalysisFailureEvent(LabelAndConfiguration failedTarget, Label failureReason) { + public AnalysisFailureEvent(ConfiguredTargetKey failedTarget, Label failureReason) { this.failedTarget = failedTarget; this.failureReason = failureReason; } - public LabelAndConfiguration getFailedTarget() { + public ConfiguredTargetKey getFailedTarget() { return failedTarget; } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LabelAndConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/LabelAndConfiguration.java deleted file mode 100644 index eb527f8a58..0000000000 --- a/src/main/java/com/google/devtools/build/lib/analysis/LabelAndConfiguration.java +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.analysis; - -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.cmdline.Label; -import java.util.Objects; -import javax.annotation.Nullable; - -/** -* A (label,configuration) pair. -*/ -public final class LabelAndConfiguration { - private final Label label; - @Nullable - private final BuildConfiguration configuration; - - private LabelAndConfiguration(Label label, @Nullable BuildConfiguration configuration) { - this.label = Preconditions.checkNotNull(label); - this.configuration = configuration; - } - - public Label getLabel() { - return label; - } - - @Nullable - public BuildConfiguration getConfiguration() { - return configuration; - } - - @Override - public int hashCode() { - int configVal = configuration == null ? 79 : configuration.hashCode(); - return 31 * label.hashCode() + configVal; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof LabelAndConfiguration)) { - return false; - } - LabelAndConfiguration other = (LabelAndConfiguration) obj; - return Objects.equals(label, other.label) && Objects.equals(configuration, other.configuration); - } - - public static LabelAndConfiguration of( - Label label, @Nullable BuildConfiguration configuration) { - return new LabelAndConfiguration(label, configuration); - } - - public static LabelAndConfiguration of(ConfiguredTarget configuredTarget) { - AliasProvider aliasProvider = configuredTarget.getProvider(AliasProvider.class); - Label label = aliasProvider != null - ? aliasProvider.getAliasChain().get(0) - : configuredTarget.getLabel(); - - return new LabelAndConfiguration(label, configuredTarget.getConfiguration()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("label", label) - .add("configuration", configuration) - .toString(); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Util.java b/src/main/java/com/google/devtools/build/lib/analysis/Util.java index aa12b40463..02d05b51e0 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/Util.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/Util.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.compacthashset.CompactHashSet; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.Target; +import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.List; import java.util.Set; @@ -77,10 +78,10 @@ public abstract class Util { * build file and all toolchain deps. * note: nodes that are depended on both implicitly and explicitly are considered explicit. */ - public static ImmutableSet<LabelAndConfiguration> findImplicitDeps(RuleContext ruleContext) { + public static ImmutableSet<ConfiguredTargetKey> findImplicitDeps(RuleContext ruleContext) { // (1) Consider rule attribute dependencies. - Set<LabelAndConfiguration> maybeImplicitDeps = CompactHashSet.create(); - Set<LabelAndConfiguration> explicitDeps = CompactHashSet.create(); + Set<ConfiguredTargetKey> maybeImplicitDeps = CompactHashSet.create(); + Set<ConfiguredTargetKey> explicitDeps = CompactHashSet.create(); AttributeMap attributes = ruleContext.attributes(); ListMultimap<String, ? extends TransitiveInfoCollection> targetMap = ruleContext.getConfiguredTargetMap(); @@ -99,19 +100,19 @@ public abstract class Util { if (toolchainContext != null) { BuildConfiguration config = ruleContext.getConfiguration(); for (Label toolchain : toolchainContext.getResolvedToolchainLabels()) { - maybeImplicitDeps.add(LabelAndConfiguration.of(toolchain, config)); + maybeImplicitDeps.add(ConfiguredTargetKey.of(toolchain, config)); } maybeImplicitDeps.add( - LabelAndConfiguration.of(toolchainContext.getExecutionPlatform().label(), config)); + ConfiguredTargetKey.of(toolchainContext.getExecutionPlatform().label(), config)); maybeImplicitDeps.add( - LabelAndConfiguration.of(toolchainContext.getTargetPlatform().label(), config)); + ConfiguredTargetKey.of(toolchainContext.getTargetPlatform().label(), config)); } return ImmutableSet.copyOf(Sets.difference(maybeImplicitDeps, explicitDeps)); } private static void addLabelsAndConfigs( - Set<LabelAndConfiguration> set, List<? extends TransitiveInfoCollection> deps) { + Set<ConfiguredTargetKey> set, List<? extends TransitiveInfoCollection> deps) { deps.forEach( - target -> set.add(LabelAndConfiguration.of(target.getLabel(), target.getConfiguration()))); + target -> set.add(ConfiguredTargetKey.of(target.getLabel(), target.getConfiguration()))); } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java index d95c4d31ac..30959f72be 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/RuleConfiguredTarget.java @@ -20,7 +20,6 @@ import com.google.common.collect.Interner; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.FileProvider; import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; @@ -38,6 +37,7 @@ import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.OutputFile; import com.google.devtools.build.lib.packages.Provider; import com.google.devtools.build.lib.packages.Rule; +import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; import com.google.devtools.build.lib.syntax.Printer; import java.util.function.Consumer; @@ -63,14 +63,14 @@ public final class RuleConfiguredTarget extends AbstractConfiguredTarget { DONT_CHECK } /** A set of this target's implicitDeps. */ - private final ImmutableSet<LabelAndConfiguration> implicitDeps; + private final ImmutableSet<ConfiguredTargetKey> implicitDeps; /* * An interner for the implicitDeps set. {@link Util.findImplicitDeps} is called upon every * construction of a RuleConfiguredTarget and we expect many of these targets to contain the same * set of implicit deps so this reduces the memory load per build. */ - private static final Interner<ImmutableSet<LabelAndConfiguration>> IMPLICIT_DEPS_INTERNER = + private static final Interner<ImmutableSet<ConfiguredTargetKey>> IMPLICIT_DEPS_INTERNER = BlazeInterners.newWeakInterner(); private final TransitiveInfoProviderMap providers; @@ -124,7 +124,7 @@ public final class RuleConfiguredTarget extends AbstractConfiguredTarget { return configConditions; } - public ImmutableSet<LabelAndConfiguration> getImplicitDeps() { + public ImmutableSet<ConfiguredTargetKey> getImplicitDeps() { return implicitDeps; } diff --git a/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java index 73e253ec37..f71086733c 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java @@ -21,7 +21,6 @@ import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget; import com.google.devtools.build.lib.cmdline.Label; @@ -104,14 +103,14 @@ public class ConfiguredTargetQueryEnvironment private static final Function<ConfiguredTarget, SkyKey> CT_TO_SKYKEY = target -> ConfiguredTargetValue.key(target.getLabel(), target.getConfiguration()); - private static final Function<SkyKey, LabelAndConfiguration> SKYKEY_TO_LANDC = + private static final Function<SkyKey, ConfiguredTargetKey> SKYKEY_TO_CTKEY = skyKey -> { ConfiguredTargetKey key = (ConfiguredTargetKey) skyKey.argument(); - return LabelAndConfiguration.of(key.getLabel(), key.getConfiguration()); + return ConfiguredTargetKey.of(key.getLabel(), key.getConfiguration()); }; private static final ImmutableList<TargetPatternKey> ALL_PATTERNS; - private static final KeyExtractor<ConfiguredTarget, LabelAndConfiguration> - CONFIGURED_TARGET_KEY_EXTRACTOR = LabelAndConfiguration::of; + private static final KeyExtractor<ConfiguredTarget, ConfiguredTargetKey> + CONFIGURED_TARGET_KEY_EXTRACTOR = ConfiguredTargetKey::of; static { TargetPattern targetPattern; @@ -310,13 +309,13 @@ public class ConfiguredTargetQueryEnvironment } } if (settings.contains(Setting.NO_IMPLICIT_DEPS) && target instanceof RuleConfiguredTarget) { - Set<LabelAndConfiguration> implicitDeps = ((RuleConfiguredTarget) target).getImplicitDeps(); + Set<ConfiguredTargetKey> implicitDeps = ((RuleConfiguredTarget) target).getImplicitDeps(); deps = deps.stream() .filter( dep -> !implicitDeps.contains( - LabelAndConfiguration.of( + ConfiguredTargetKey.of( dep.getTarget().getLabel(), dep.getConfiguration()))) .collect(Collectors.toList()); } @@ -333,10 +332,10 @@ public class ConfiguredTargetQueryEnvironment Map<SkyKey, Collection<ConfiguredTarget>> directDeps = targetifyValues(graph.getDirectDeps(targetsByKey.keySet())); if (targetsByKey.keySet().size() != directDeps.keySet().size()) { - Iterable<LabelAndConfiguration> missingTargets = + Iterable<ConfiguredTargetKey> missingTargets = Sets.difference(targetsByKey.keySet(), directDeps.keySet()) .stream() - .map(SKYKEY_TO_LANDC) + .map(SKYKEY_TO_CTKEY) .collect(Collectors.toList()); eventHandler.handle(Event.warn("Targets were missing from graph: " + missingTargets)); } @@ -376,10 +375,10 @@ public class ConfiguredTargetQueryEnvironment Map<SkyKey, Collection<ConfiguredTarget>> reverseDepsByKey = targetifyValues(graph.getReverseDeps(targetsByKey.keySet())); if (targetsByKey.size() != reverseDepsByKey.size()) { - Iterable<LabelAndConfiguration> missingTargets = + Iterable<ConfiguredTargetKey> missingTargets = Sets.difference(targetsByKey.keySet(), reverseDepsByKey.keySet()) .stream() - .map(SKYKEY_TO_LANDC) + .map(SKYKEY_TO_CTKEY) .collect(Collectors.toList()); eventHandler.handle(Event.warn("Targets were missing from graph: " + missingTargets)); } @@ -407,7 +406,7 @@ public class ConfiguredTargetQueryEnvironment @Override public ImmutableList<ConfiguredTarget> getNodesOnPath(ConfiguredTarget from, ConfiguredTarget to) throws InterruptedException { - return SkyQueryUtils.getNodesOnPath(from, to, this::getFwdDeps, LabelAndConfiguration::of); + return SkyQueryUtils.getNodesOnPath(from, to, this::getFwdDeps, ConfiguredTargetKey::of); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java b/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java index a4a77c4814..b5ec577728 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/AggregatingTestListener.java @@ -30,7 +30,6 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.AliasProvider; import com.google.devtools.build.lib.analysis.AnalysisFailureEvent; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.TargetCompleteEvent; import com.google.devtools.build.lib.analysis.test.TestProvider; import com.google.devtools.build.lib.analysis.test.TestResult; @@ -40,6 +39,7 @@ import com.google.devtools.build.lib.buildtool.buildevent.BuildInterruptedEvent; import com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent; import com.google.devtools.build.lib.concurrent.ThreadSafety; import com.google.devtools.build.lib.rules.test.TestAttempt; +import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus; import java.util.Collection; import java.util.Collections; @@ -61,8 +61,8 @@ public class AggregatingTestListener { // summaryLock guards concurrent access to these two collections, which should be kept // synchronized with each other. - private final Map<LabelAndConfiguration, TestSummary.Builder> summaries; - private final Multimap<LabelAndConfiguration, Artifact> remainingRuns; + private final Map<ConfiguredTargetKey, TestSummary.Builder> summaries; + private final Multimap<ConfiguredTargetKey, Artifact> remainingRuns; private final Object summaryLock = new Object(); public AggregatingTestListener(TestResultAnalyzer analyzer, EventBus eventBus) { @@ -122,8 +122,8 @@ public class AggregatingTestListener { "Duplicate result reported for an individual test shard"); ActionOwner testOwner = result.getTestAction().getOwner(); - LabelAndConfiguration targetLabel = LabelAndConfiguration.of( - testOwner.getLabel(), result.getTestAction().getConfiguration()); + ConfiguredTargetKey targetLabel = + ConfiguredTargetKey.of(testOwner.getLabel(), result.getTestAction().getConfiguration()); // If a test result was cached, then no attempts for that test were actually // executed. Hence report that fact as a cached attempt. @@ -155,17 +155,17 @@ public class AggregatingTestListener { } } - private void targetFailure(LabelAndConfiguration label) { + private void targetFailure(ConfiguredTargetKey configuredTargetKey) { TestSummary finalSummary; synchronized (summaryLock) { - if (!remainingRuns.containsKey(label)) { + if (!remainingRuns.containsKey(configuredTargetKey)) { // Blaze does not guarantee that BuildResult.getSuccessfulTargets() and posted TestResult // events are in sync. Thus, it is possible that a test event was posted, but the target is // not present in the set of successful targets. return; } - TestSummary.Builder summary = summaries.get(label); + TestSummary.Builder summary = summaries.get(configuredTargetKey); if (summary == null) { // Not a test target; nothing to do. return; @@ -176,7 +176,7 @@ public class AggregatingTestListener { .build(); // These are never going to run; removing them marks the target complete. - remainingRuns.removeAll(label); + remainingRuns.removeAll(configuredTargetKey); } eventBus.post(finalSummary); } @@ -222,7 +222,7 @@ public class AggregatingTestListener { @AllowConcurrentEvents public void targetComplete(TargetCompleteEvent event) { if (event.failed()) { - targetFailure(LabelAndConfiguration.of(event.getTarget())); + targetFailure(ConfiguredTargetKey.of(event.getTarget())); } } @@ -261,8 +261,8 @@ public class AggregatingTestListener { return analyzer; } - private LabelAndConfiguration asKey(ConfiguredTarget target) { - return LabelAndConfiguration.of( + private ConfiguredTargetKey asKey(ConfiguredTarget target) { + return ConfiguredTargetKey.of( AliasProvider.getDependencyLabel(target), target.getConfiguration()); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java index 8808252848..8c49441f25 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionArtifactCycleReporter.java @@ -54,10 +54,10 @@ public class ActionArtifactCycleReporter extends AbstractLabelCycleReporter { return "action from: " + arg; } else if (arg instanceof TargetCompletionKey && skyFunctionName.equals(SkyFunctions.TARGET_COMPLETION)) { - return "configured target: " + ((TargetCompletionKey) arg).labelAndConfiguration().getLabel(); + return "configured target: " + ((TargetCompletionKey) arg).configuredTargetKey().getLabel(); } else if (arg instanceof TestCompletionKey && skyFunctionName.equals(SkyFunctions.TEST_COMPLETION)) { - return "test target: " + ((TestCompletionKey) arg).labelAndConfiguration().getLabel(); + return "test target: " + ((TestCompletionKey) arg).configuredTargetKey().getLabel(); } throw new IllegalStateException( "Argument is not Action, TargetCompletion, TestCompletion or OwnedArtifact: " + arg); @@ -72,10 +72,10 @@ public class ActionArtifactCycleReporter extends AbstractLabelCycleReporter { return ((ActionLookupData) arg).getLabelForErrors(); } else if (arg instanceof TargetCompletionKey && key.functionName().equals(SkyFunctions.TARGET_COMPLETION)) { - return ((TargetCompletionKey) arg).labelAndConfiguration().getLabel(); + return ((TargetCompletionKey) arg).configuredTargetKey().getLabel(); } else if (arg instanceof TestCompletionKey && key.functionName().equals(SkyFunctions.TEST_COMPLETION)) { - return ((TestCompletionKey) arg).labelAndConfiguration().getLabel(); + return ((TestCompletionKey) arg).configuredTargetKey().getLabel(); } throw new IllegalStateException( "Argument is not Action, TargetCompletion, TestCompletion or OwnedArtifact: " + arg); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java index 68533985cc..103fd73167 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java @@ -19,7 +19,6 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.MissingInputFileException; import com.google.devtools.build.lib.analysis.AspectCompleteEvent; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.TargetCompleteEvent; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper; @@ -101,7 +100,7 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S public ConfiguredTargetValue getValueFromSkyKey(SkyKey skyKey, Environment env) throws InterruptedException { TargetCompletionKey tcKey = (TargetCompletionKey) skyKey.argument(); - LabelAndConfiguration lac = tcKey.labelAndConfiguration(); + ConfiguredTargetKey lac = tcKey.configuredTargetKey(); return (ConfiguredTargetValue) env.getValue(ConfiguredTargetValue.key(lac.getLabel(), lac.getConfiguration())); } @@ -151,7 +150,7 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S @Override public String extractTag(SkyKey skyKey) { return Label.print( - ((TargetCompletionKey) skyKey.argument()).labelAndConfiguration().getLabel()); + ((TargetCompletionKey) skyKey.argument()).configuredTargetKey().getLabel()); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java index 51584f2d8e..af83e3c9a6 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java @@ -30,7 +30,6 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.ConfiguredTargetFactory; import com.google.devtools.build.lib.analysis.Dependency; import com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.TargetAndConfiguration; import com.google.devtools.build.lib.analysis.ToolchainContext; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; @@ -141,13 +140,12 @@ public final class ConfiguredTargetFunction implements SkyFunction { storeTransitivePackagesForPackageRootResolution ? NestedSetBuilder.stableOrder() : null; NestedSetBuilder<Label> transitiveLoadingRootCauses = NestedSetBuilder.stableOrder(); ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key.argument(); - LabelAndConfiguration lc = LabelAndConfiguration.of( - configuredTargetKey.getLabel(), configuredTargetKey.getConfiguration()); + Label label = configuredTargetKey.getLabel(); - BuildConfiguration configuration = lc.getConfiguration(); + BuildConfiguration configuration = configuredTargetKey.getConfiguration(); PackageValue packageValue = - (PackageValue) env.getValue(PackageValue.key(lc.getLabel().getPackageIdentifier())); + (PackageValue) env.getValue(PackageValue.key(label.getPackageIdentifier())); if (packageValue == null) { return null; } @@ -157,13 +155,13 @@ public final class ConfiguredTargetFunction implements SkyFunction { Package pkg = packageValue.getPackage(); Target target; try { - target = pkg.getTarget(lc.getLabel().getName()); + target = pkg.getTarget(label.getName()); } catch (NoSuchTargetException e) { throw new ConfiguredTargetFunctionException( - new ConfiguredValueCreationException(e.getMessage(), lc.getLabel())); + new ConfiguredValueCreationException(e.getMessage(), label)); } if (pkg.containsErrors()) { - transitiveLoadingRootCauses.add(lc.getLabel()); + transitiveLoadingRootCauses.add(label); } if (transitivePackagesForPackageRootResolution != null) { transitivePackagesForPackageRootResolution.add(pkg); @@ -181,8 +179,9 @@ public final class ConfiguredTargetFunction implements SkyFunction { // associates the corresponding error with this target, as expected. Without this line, // the first TransitiveTargetValue call happens on its dep (in trimConfigurations), so Bazel // associates the error with the dep, which is misleading. - if (configuration != null && configuration.trimConfigurations() - && env.getValue(TransitiveTargetKey.of(lc.getLabel())) == null) { + if (configuration != null + && configuration.trimConfigurations() + && env.getValue(TransitiveTargetKey.of(label)) == null) { return null; } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java index 7be2757422..c02fd999d9 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java @@ -14,8 +14,10 @@ package com.google.devtools.build.lib.skyframe; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey; +import com.google.devtools.build.lib.analysis.AliasProvider; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.Label; @@ -39,10 +41,22 @@ public class ConfiguredTargetKey extends ActionLookupKey { this.configuration = configuration; } + @VisibleForTesting public ConfiguredTargetKey(ConfiguredTarget rule) { this(rule.getTarget().getLabel(), rule.getConfiguration()); } + public static ConfiguredTargetKey of(ConfiguredTarget configuredTarget) { + AliasProvider aliasProvider = configuredTarget.getProvider(AliasProvider.class); + Label label = + aliasProvider != null ? aliasProvider.getAliasChain().get(0) : configuredTarget.getLabel(); + return of(label, configuredTarget.getConfiguration()); + } + + public static ConfiguredTargetKey of(Label label, @Nullable BuildConfiguration configuration) { + return new ConfiguredTargetKey(label, configuration); + } + @Override public Label getLabel() { return label; @@ -94,5 +108,4 @@ public class ConfiguredTargetKey extends ActionLookupKey { System.identityHashCode(this), (configuration == null ? "null" : System.identityHashCode(configuration))); } - } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java index c3c7d6b5f2..779dbaa255 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java @@ -21,7 +21,6 @@ import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.Dependency; import com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.TargetAndConfiguration; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider; @@ -167,7 +166,7 @@ public class PostConfiguredTargetFunction implements SkyFunction { @Nullable @Override public String extractTag(SkyKey skyKey) { - return Label.print(((LabelAndConfiguration) skyKey.argument()).getLabel()); + return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel()); } private static class ActionConflictFunctionException extends SkyFunctionException { diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java index 74c1cbabce..a62d501ccb 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java @@ -40,7 +40,6 @@ import com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.ConfiguredTargetFactory; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.ToolchainContext; import com.google.devtools.build.lib.analysis.ViewCreationFailedException; import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory; @@ -348,8 +347,10 @@ public final class SkyframeBuildView { Event.warn("errors encountered while analyzing target '" + topLevelLabel + "': it will not be built")); if (analysisRootCause != null) { - eventBus.post(new AnalysisFailureEvent( - LabelAndConfiguration.of(topLevelLabel, label.getConfiguration()), analysisRootCause)); + eventBus.post( + new AnalysisFailureEvent( + ConfiguredTargetKey.of(topLevelLabel, label.getConfiguration()), + analysisRootCause)); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java index 476f69da44..c08f5a6522 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetCompletionValue.java @@ -17,7 +17,6 @@ import com.google.auto.value.AutoValue; import com.google.common.base.Function; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; import com.google.devtools.build.skyframe.LegacySkyKey; import com.google.devtools.build.skyframe.SkyKey; @@ -39,11 +38,10 @@ public class TargetCompletionValue implements SkyValue { } public static SkyKey key( - LabelAndConfiguration labelAndConfiguration, - TopLevelArtifactContext topLevelArtifactContext) { + ConfiguredTargetKey configuredTargetKey, TopLevelArtifactContext topLevelArtifactContext) { return LegacySkyKey.create( SkyFunctions.TARGET_COMPLETION, - TargetCompletionKey.create(labelAndConfiguration, topLevelArtifactContext)); + TargetCompletionKey.create(configuredTargetKey, topLevelArtifactContext)); } public static Iterable<SkyKey> keys(Collection<ConfiguredTarget> targets, @@ -55,7 +53,7 @@ public class TargetCompletionValue implements SkyValue { public SkyKey apply(ConfiguredTarget ct) { return LegacySkyKey.create( SkyFunctions.TARGET_COMPLETION, - TargetCompletionKey.create(LabelAndConfiguration.of(ct), ctx)); + TargetCompletionKey.create(ConfiguredTargetKey.of(ct), ctx)); } }); } @@ -63,13 +61,13 @@ public class TargetCompletionValue implements SkyValue { @AutoValue abstract static class TargetCompletionKey { public static TargetCompletionKey create( - LabelAndConfiguration labelAndConfiguration, - TopLevelArtifactContext topLevelArtifactContext) { + ConfiguredTargetKey configuredTargetKey, TopLevelArtifactContext topLevelArtifactContext) { return new AutoValue_TargetCompletionValue_TargetCompletionKey( - labelAndConfiguration, topLevelArtifactContext); + configuredTargetKey, topLevelArtifactContext); } - public abstract LabelAndConfiguration labelAndConfiguration(); + abstract ConfiguredTargetKey configuredTargetKey(); + public abstract TopLevelArtifactContext topLevelArtifactContext(); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java index dcdf47e11d..d476098c69 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.skyframe; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; import com.google.devtools.build.lib.analysis.test.TestProvider; import com.google.devtools.build.lib.cmdline.Label; @@ -33,7 +32,7 @@ public final class TestCompletionFunction implements SkyFunction { public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException { TestCompletionValue.TestCompletionKey key = (TestCompletionValue.TestCompletionKey) skyKey.argument(); - LabelAndConfiguration lac = key.labelAndConfiguration(); + ConfiguredTargetKey lac = key.configuredTargetKey(); TopLevelArtifactContext ctx = key.topLevelArtifactContext(); if (env.getValue(TargetCompletionValue.key(lac, ctx)) == null) { return null; @@ -64,6 +63,6 @@ public final class TestCompletionFunction implements SkyFunction { @Override public String extractTag(SkyKey skyKey) { - return Label.print(((LabelAndConfiguration) skyKey.argument()).getLabel()); + return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel()); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java index 68e09f22de..b435720123 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionValue.java @@ -17,7 +17,6 @@ import com.google.auto.value.AutoValue; import com.google.common.base.Function; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.LabelAndConfiguration; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; import com.google.devtools.build.skyframe.LegacySkyKey; import com.google.devtools.build.skyframe.SkyKey; @@ -34,7 +33,7 @@ public class TestCompletionValue implements SkyValue { private TestCompletionValue() { } public static SkyKey key( - LabelAndConfiguration lac, + ConfiguredTargetKey lac, final TopLevelArtifactContext topLevelArtifactContext, final boolean exclusiveTesting) { return LegacySkyKey.create( @@ -53,7 +52,7 @@ public class TestCompletionValue implements SkyValue { return LegacySkyKey.create( SkyFunctions.TEST_COMPLETION, TestCompletionKey.create( - LabelAndConfiguration.of(ct), topLevelArtifactContext, exclusiveTesting)); + ConfiguredTargetKey.of(ct), topLevelArtifactContext, exclusiveTesting)); } }); } @@ -62,14 +61,15 @@ public class TestCompletionValue implements SkyValue { abstract static class TestCompletionKey { public static TestCompletionKey create( - LabelAndConfiguration labelAndConfiguration, + ConfiguredTargetKey configuredTargetKey, TopLevelArtifactContext topLevelArtifactContext, boolean exclusiveTesting) { return new AutoValue_TestCompletionValue_TestCompletionKey( - labelAndConfiguration, topLevelArtifactContext, exclusiveTesting); + configuredTargetKey, topLevelArtifactContext, exclusiveTesting); } - public abstract LabelAndConfiguration labelAndConfiguration(); + abstract ConfiguredTargetKey configuredTargetKey(); + public abstract TopLevelArtifactContext topLevelArtifactContext(); public abstract boolean exclusiveTesting(); } |