From 67446d625e4daafadcb5918a88ed52f517a8871f Mon Sep 17 00:00:00 2001 From: Googler Date: Sat, 27 May 2023 16:48:19 -0700 Subject: [PATCH] Delete KeyedConfiguredTarget. No longer needed since ConfiguredTargetKey is embedded in ConfiguredTarget. PiperOrigin-RevId: 535908504 Change-Id: Id0b11ae876d32a94438c7409136c0c52dcadf1ad --- .../build/lib/buildtool/CqueryProcessor.java | 4 +- .../cquery/BuildOutputFormatterCallback.java | 19 ++-- .../lib/query2/cquery/ConfigFunction.java | 5 +- .../cquery/ConfiguredTargetAccessor.java | 58 ++++++------- .../ConfiguredTargetQueryEnvironment.java | 75 ++++++++-------- .../cquery/CqueryThreadsafeCallback.java | 6 +- .../cquery/CqueryTransitionResolver.java | 7 +- .../cquery/FilesOutputFormatterCallback.java | 7 +- .../cquery/GraphOutputFormatterCallback.java | 45 +++++----- .../query2/cquery/KeyedConfiguredTarget.java | 86 ------------------- ...dConfigurationOutputFormatterCallback.java | 12 +-- .../cquery/ProtoOutputFormatterCallback.java | 21 ++--- .../StarlarkOutputFormatterCallback.java | 13 ++- .../TransitionsOutputFormatterCallback.java | 19 ++-- .../lib/skyframe/BuildConfigurationKey.java | 4 + .../devtools/build/lib/query2/cquery/BUILD | 9 +- .../BuildOutputFormatterCallbackTest.java | 3 +- .../cquery/ConfiguredTargetQueryHelper.java | 7 +- .../ConfiguredTargetQuerySemanticsTest.java | 56 ++++++------ .../cquery/ConfiguredTargetQueryTest.java | 14 +-- .../FilesOutputFormatterCallbackTest.java | 3 +- .../GraphOutputFormatterCallbackTest.java | 3 +- .../ProtoOutputFormatterCallbackTest.java | 32 +++---- .../TransitionsOutputFormatterTest.java | 3 +- 24 files changed, 214 insertions(+), 297 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/query2/cquery/KeyedConfiguredTarget.java diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java b/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java index 1dc1d94018ded1..3fea7717249374 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java @@ -14,11 +14,11 @@ package com.google.devtools.build.lib.buildtool; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.cmdline.TargetPattern; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment.TopLevelConfigurations; import com.google.devtools.build.lib.query2.cquery.ConfiguredTargetQueryEnvironment; import com.google.devtools.build.lib.query2.cquery.CqueryOptions; -import com.google.devtools.build.lib.query2.cquery.KeyedConfiguredTarget; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; import com.google.devtools.build.lib.query2.engine.QueryExpression; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -27,7 +27,7 @@ import java.util.Collection; /** Performs {@code cquery} processing. */ -public final class CqueryProcessor extends PostAnalysisQueryProcessor { +public final class CqueryProcessor extends PostAnalysisQueryProcessor { public CqueryProcessor( QueryExpression queryExpression, TargetPattern.Parser mainRepoTargetParser) { diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java index 0a8944f458dea5..515a0abd461a3c 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallback.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.configuredtargets.OutputFileConfiguredTarget; import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.packages.Attribute; @@ -37,7 +38,7 @@ class BuildOutputFormatterCallback extends CqueryThreadsafeCallback { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor) { + TargetAccessor accessor) { super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false); } @@ -66,28 +67,28 @@ public Iterable getPossibleValues(Rule rule, Attribute attr) { } @Nullable - private ConfiguredAttributeMapper getAttributeMap(KeyedConfiguredTarget kct) + private ConfiguredAttributeMapper getAttributeMap(ConfiguredTarget kct) throws InterruptedException { Rule associatedRule = accessor.getTarget(kct).getAssociatedRule(); if (associatedRule == null) { return null; - } else if (kct.getConfiguredTarget() instanceof OutputFileConfiguredTarget) { + } else if (kct instanceof OutputFileConfiguredTarget) { return ConfiguredAttributeMapper.of( associatedRule, accessor.getGeneratingConfiguredTarget(kct).getConfigConditions(), - kct.getConfigurationChecksum(), - /*alwaysSucceed=*/ false); + kct.getConfigurationKey().getOptionsChecksum(), + /* alwaysSucceed= */ false); } else { return ConfiguredAttributeMapper.of( associatedRule, kct.getConfigConditions(), - kct.getConfigurationChecksum(), - /*alwaysSucceed=*/ false); + kct.getConfigurationKey().getOptionsChecksum(), + /* alwaysSucceed= */ false); } } @Override - public void processOutput(Iterable partialResult) + public void processOutput(Iterable partialResult) throws InterruptedException, IOException { BuildOutputFormatter.TargetOutputter outputter = new TargetOutputter( @@ -98,7 +99,7 @@ public void processOutput(Iterable partialResult) // and which path is chosen, which people may find even more informative. (rule, attr) -> false, System.lineSeparator()); - for (KeyedConfiguredTarget configuredTarget : partialResult) { + for (ConfiguredTarget configuredTarget : partialResult) { Target target = accessor.getTarget(configuredTarget); outputter.output(target, new CqueryAttributeReader(getAttributeMap(configuredTarget))); } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java index 4aa10323ffded8..1b105be912fa65 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfigFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.query2.common.AbstractBlazeQueryEnvironment; import com.google.devtools.build.lib.query2.engine.Callback; import com.google.devtools.build.lib.query2.engine.QueryEnvironment; @@ -58,7 +59,7 @@ public List getArgumentTypes() { /** * This function is only viable with ConfiguredTargetQueryEnvironment which extends {@link - * AbstractBlazeQueryEnvironment }. + * AbstractBlazeQueryEnvironment }. */ @Override @SuppressWarnings("unchecked") @@ -84,6 +85,6 @@ public QueryTaskFuture eval( targetExpression.toString(), targetsFuture, configuration, - (Callback) callback)); + (Callback) callback)); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java index 0698fd7c11bc67..6a30dd3d313ad9 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetAccessor.java @@ -17,9 +17,9 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.ConfiguredTargetValue; @@ -57,7 +57,7 @@ * *

Incomplete; we'll implement getVisibility when needed. */ -public class ConfiguredTargetAccessor implements TargetAccessor { +public class ConfiguredTargetAccessor implements TargetAccessor { private final WalkableGraph walkableGraph; private final ConfiguredTargetQueryEnvironment queryEnvironment; @@ -69,55 +69,56 @@ public ConfiguredTargetAccessor( } @Override - public String getTargetKind(KeyedConfiguredTarget target) { + public String getTargetKind(ConfiguredTarget target) { Target actualTarget = getTarget(target); return actualTarget.getTargetKind(); } @Override - public String getLabel(KeyedConfiguredTarget target) { - return target.getLabel().toString(); + public String getLabel(ConfiguredTarget target) { + return target.getOriginalLabel().toString(); } @Override - public String getPackage(KeyedConfiguredTarget target) { - return target.getLabel().getPackageIdentifier().getPackageFragment().toString(); + public String getPackage(ConfiguredTarget target) { + return target.getOriginalLabel().getPackageIdentifier().getPackageFragment().toString(); } @Override - public boolean isRule(KeyedConfiguredTarget target) { + public boolean isRule(ConfiguredTarget target) { Target actualTarget = getTarget(target); return actualTarget instanceof Rule; } @Override - public boolean isTestRule(KeyedConfiguredTarget target) { + public boolean isTestRule(ConfiguredTarget target) { Target actualTarget = getTarget(target); return TargetUtils.isTestRule(actualTarget); } @Override - public boolean isTestSuite(KeyedConfiguredTarget target) { + public boolean isTestSuite(ConfiguredTarget target) { Target actualTarget = getTarget(target); return TargetUtils.isTestSuiteRule(actualTarget); } @Override - public List getPrerequisites( + public List getPrerequisites( QueryExpression caller, - KeyedConfiguredTarget keyedConfiguredTarget, + ConfiguredTarget keyedConfiguredTarget, String attrName, String errorMsgPrefix) throws QueryException, InterruptedException { // Process aliases. - KeyedConfiguredTarget actual = keyedConfiguredTarget.getActual(); + ConfiguredTarget actual = keyedConfiguredTarget.getActual(); Preconditions.checkArgument( isRule(actual), "%s %s is not a rule configured target", errorMsgPrefix, getLabel(actual)); - Multimap depsByLabel = + ImmutableListMultimap depsByLabel = Multimaps.index( - queryEnvironment.getFwdDeps(ImmutableList.of(actual)), KeyedConfiguredTarget::getLabel); + queryEnvironment.getFwdDeps(ImmutableList.of(actual)), + ConfiguredTarget::getOriginalLabel); Rule rule = (Rule) getTarget(actual); ImmutableMap configConditions = actual.getConfigConditions(); @@ -135,41 +136,41 @@ public List getPrerequisites( errorMsgPrefix, rule.getRuleClass(), attrName), ConfigurableQuery.Code.ATTRIBUTE_MISSING); } - ImmutableList.Builder toReturn = ImmutableList.builder(); + ImmutableList.Builder toReturn = ImmutableList.builder(); attributeMapper.visitLabels(attrName, label -> toReturn.addAll(depsByLabel.get(label))); return toReturn.build(); } @Override - public List getStringListAttr(KeyedConfiguredTarget target, String attrName) { + public List getStringListAttr(ConfiguredTarget target, String attrName) { Target actualTarget = getTarget(target); return TargetUtils.getStringListAttr(actualTarget, attrName); } @Override - public String getStringAttr(KeyedConfiguredTarget target, String attrName) { + public String getStringAttr(ConfiguredTarget target, String attrName) { Target actualTarget = getTarget(target); return TargetUtils.getStringAttr(actualTarget, attrName); } @Override - public Iterable getAttrAsString(KeyedConfiguredTarget target, String attrName) { + public Iterable getAttrAsString(ConfiguredTarget target, String attrName) { Target actualTarget = getTarget(target); return TargetUtils.getAttrAsString(actualTarget, attrName); } @Override - public ImmutableSet> getVisibility( - QueryExpression caller, KeyedConfiguredTarget from) throws QueryException { + public ImmutableSet> getVisibility( + QueryExpression caller, ConfiguredTarget from) throws QueryException { // TODO(bazel-team): implement this if needed. throw new QueryException( "visible() is not supported on configured targets", ConfigurableQuery.Code.VISIBLE_FUNCTION_NOT_SUPPORTED); } - public Target getTarget(KeyedConfiguredTarget keyedConfiguredTarget) { + public Target getTarget(ConfiguredTarget configuredTarget) { // Dereference any aliases that might be present. - Label label = keyedConfiguredTarget.getConfiguredTarget().getOriginalLabel(); + Label label = configuredTarget.getOriginalLabel(); try { return queryEnvironment.getTarget(label); } catch (InterruptedException e) { @@ -180,18 +181,15 @@ public Target getTarget(KeyedConfiguredTarget keyedConfiguredTarget) { } /** Returns the rule that generates the given output file. */ - RuleConfiguredTarget getGeneratingConfiguredTarget(KeyedConfiguredTarget kct) + RuleConfiguredTarget getGeneratingConfiguredTarget(ConfiguredTarget kct) throws InterruptedException { - Preconditions.checkArgument(kct.getConfiguredTarget() instanceof OutputFileConfiguredTarget); + Preconditions.checkArgument(kct instanceof OutputFileConfiguredTarget); return (RuleConfiguredTarget) ((ConfiguredTargetValue) walkableGraph.getValue( ConfiguredTargetKey.builder() - .setLabel( - ((OutputFileConfiguredTarget) kct.getConfiguredTarget()) - .getGeneratingRule() - .getLabel()) - .setConfiguration(queryEnvironment.getConfiguration(kct)) + .setLabel(((OutputFileConfiguredTarget) kct).getGeneratingRule().getLabel()) + .setConfigurationKey(kct.getConfigurationKey()) .build() .toKey())) .getConfiguredTarget(); diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java index 1beeae8e8f7be7..40393df3b86901 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java @@ -72,7 +72,7 @@ * comments on {@link PostAnalysisQueryEnvironment#targetifyValues} and b/163052263 for details. */ public class ConfiguredTargetQueryEnvironment - extends PostAnalysisQueryEnvironment { + extends PostAnalysisQueryEnvironment { /** Common query functions and cquery specific functions. */ public static final ImmutableList FUNCTIONS = populateFunctions(); /** Cquery specific functions. */ @@ -82,8 +82,7 @@ public class ConfiguredTargetQueryEnvironment private final TopLevelArtifactContext topLevelArtifactContext; - private final KeyExtractor - configuredTargetKeyExtractor; + private final KeyExtractor configuredTargetKeyExtractor; private final ConfiguredTargetAccessor accessor; @@ -105,8 +104,7 @@ public class ConfiguredTargetQueryEnvironment private final ImmutableMap transitiveConfigurations; @Override - protected KeyExtractor - getConfiguredTargetKeyExtractor() { + protected KeyExtractor getConfiguredTargetKeyExtractor() { return configuredTargetKeyExtractor; } @@ -132,7 +130,7 @@ public ConfiguredTargetQueryEnvironment( walkableGraphSupplier, settings); this.accessor = new ConfiguredTargetAccessor(walkableGraphSupplier.get(), this); - this.configuredTargetKeyExtractor = KeyedConfiguredTarget::getConfiguredTargetKey; + this.configuredTargetKeyExtractor = ConfiguredTargetKey::fromConfiguredTarget; this.transitiveConfigurations = getTransitiveConfigurations(transitiveConfigurationKeys, walkableGraphSupplier.get()); this.topLevelArtifactContext = topLevelArtifactContext; @@ -187,9 +185,9 @@ private static ImmutableMap getTransitiveConfig } @Override - public ImmutableList> + public ImmutableList> getDefaultOutputFormatters( - TargetAccessor accessor, + TargetAccessor accessor, ExtendedEventHandler eventHandler, OutputStream out, SkyframeExecutor skyframeExecutor, @@ -278,7 +276,7 @@ public ConfiguredTargetAccessor getAccessor() { @Override public QueryTaskFuture getTargetsMatchingPattern( - QueryExpression owner, String pattern, Callback callback) { + QueryExpression owner, String pattern, Callback callback) { TargetPattern patternToEval; try { patternToEval = getPattern(pattern); @@ -304,7 +302,7 @@ public QueryTaskFuture getTargetsMatchingPattern( /* excludedSubdirectories= */ ImmutableSet.of(), (Callback) partialResult -> { - List transformedResult = new ArrayList<>(); + List transformedResult = new ArrayList<>(); for (Target target : partialResult) { transformedResult.addAll( getConfiguredTargetsForConfigFunction(target.getLabel())); @@ -322,8 +320,8 @@ public QueryTaskFuture getTargetsMatchingPattern( * null. */ @Nullable - private KeyedConfiguredTarget getConfiguredTarget( - Label label, BuildConfigurationValue configuration) throws InterruptedException { + private ConfiguredTarget getConfiguredTarget(Label label, BuildConfigurationValue configuration) + throws InterruptedException { return getValueFromKey( ConfiguredTargetKey.builder() .setLabel(label) @@ -334,11 +332,9 @@ private KeyedConfiguredTarget getConfiguredTarget( @Override @Nullable - protected KeyedConfiguredTarget getValueFromKey(SkyKey key) throws InterruptedException { + protected ConfiguredTarget getValueFromKey(SkyKey key) throws InterruptedException { ConfiguredTargetValue value = getConfiguredTargetValue(key); - return value == null - ? null - : KeyedConfiguredTarget.create((ConfiguredTargetKey) key, value.getConfiguredTarget()); + return value == null ? null : value.getConfiguredTarget(); } /** @@ -346,16 +342,16 @@ protected KeyedConfiguredTarget getValueFromKey(SkyKey key) throws InterruptedEx * *

If there are no matches, returns an empty list. */ - private List getConfiguredTargetsForConfigFunction(Label label) + private ImmutableList getConfiguredTargetsForConfigFunction(Label label) throws InterruptedException { - ImmutableList.Builder ans = ImmutableList.builder(); + ImmutableList.Builder ans = ImmutableList.builder(); for (BuildConfigurationValue config : transitiveConfigurations.values()) { - KeyedConfiguredTarget kct = getConfiguredTarget(label, config); + ConfiguredTarget kct = getConfiguredTarget(label, config); if (kct != null) { ans.add(kct); } } - KeyedConfiguredTarget nullConfiguredTarget = getNullConfiguredTarget(label); + ConfiguredTarget nullConfiguredTarget = getNullConfiguredTarget(label); if (nullConfiguredTarget != null) { ans.add(nullConfiguredTarget); } @@ -380,19 +376,19 @@ QueryTaskCallable getConfiguredTargetsForConfigFunction( String pattern, QueryTaskFuture> targetsFuture, String configPrefix, - Callback callback) { + Callback callback) { // There's no technical reason other callers beside ConfigFunction can't call this. But they'd // need to adjust the error messaging below to not make it config()-specific. Please don't just // remove that line: the counter-priority is making error messages as clear, precise, and // actionable as possible. return () -> { - ThreadSafeMutableSet targets = - (ThreadSafeMutableSet) targetsFuture.getIfSuccessful(); - List transformedResult = new ArrayList<>(); + ThreadSafeMutableSet targets = + (ThreadSafeMutableSet) targetsFuture.getIfSuccessful(); + List transformedResult = new ArrayList<>(); boolean userFriendlyConfigName = true; - for (KeyedConfiguredTarget target : targets) { + for (ConfiguredTarget target : targets) { Label label = getCorrectLabel(target); - KeyedConfiguredTarget keyedConfiguredTarget; + ConfiguredTarget keyedConfiguredTarget; switch (configPrefix) { case "host": throw new QueryException( @@ -467,20 +463,19 @@ QueryTaskCallable getConfiguredTargetsForConfigFunction( * the "actual" target instead of the alias target. Grr. */ @Override - public Label getCorrectLabel(KeyedConfiguredTarget target) { + public Label getCorrectLabel(ConfiguredTarget target) { // Dereference any aliases that might be present. - return target.getConfiguredTarget().getOriginalLabel(); + return target.getOriginalLabel(); } @Nullable @Override - protected KeyedConfiguredTarget getTargetConfiguredTarget(Label label) - throws InterruptedException { + protected ConfiguredTarget getTargetConfiguredTarget(Label label) throws InterruptedException { if (topLevelConfigurations.isTopLevelTarget(label)) { return getConfiguredTarget( label, topLevelConfigurations.getConfigurationForTopLevelTarget(label)); } else { - KeyedConfiguredTarget toReturn; + ConfiguredTarget toReturn; for (BuildConfigurationValue configuration : topLevelConfigurations.getConfigurations()) { toReturn = getConfiguredTarget(label, configuration); if (toReturn != null) { @@ -493,22 +488,22 @@ protected KeyedConfiguredTarget getTargetConfiguredTarget(Label label) @Nullable @Override - protected KeyedConfiguredTarget getNullConfiguredTarget(Label label) throws InterruptedException { + protected ConfiguredTarget getNullConfiguredTarget(Label label) throws InterruptedException { return getConfiguredTarget(label, null); } @Nullable @Override - protected RuleConfiguredTarget getRuleConfiguredTarget(KeyedConfiguredTarget configuredTarget) { - if (configuredTarget.getConfiguredTarget() instanceof RuleConfiguredTarget) { - return (RuleConfiguredTarget) configuredTarget.getConfiguredTarget(); + protected RuleConfiguredTarget getRuleConfiguredTarget(ConfiguredTarget configuredTarget) { + if (configuredTarget instanceof RuleConfiguredTarget) { + return (RuleConfiguredTarget) configuredTarget; } return null; } @Nullable @Override - protected BuildConfigurationValue getConfiguration(KeyedConfiguredTarget target) { + protected BuildConfigurationValue getConfiguration(ConfiguredTarget target) { try { return target.getConfigurationKey() == null ? null @@ -519,15 +514,15 @@ protected BuildConfigurationValue getConfiguration(KeyedConfiguredTarget target) } @Override - protected ConfiguredTargetKey getConfiguredTargetKey(KeyedConfiguredTarget target) { - return target.getConfiguredTargetKey(); + protected ConfiguredTargetKey getConfiguredTargetKey(ConfiguredTarget target) { + return ConfiguredTargetKey.fromConfiguredTarget(target); } @Override - public ThreadSafeMutableSet createThreadSafeMutableSet() { + public ThreadSafeMutableSet createThreadSafeMutableSet() { return new ThreadSafeMutableKeyExtractorBackedSetImpl<>( configuredTargetKeyExtractor, - KeyedConfiguredTarget.class, + ConfiguredTarget.class, SkyQueryEnvironment.DEFAULT_THREAD_COUNT); } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java index af559992d54160..bc8c3f7595cab2 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryThreadsafeCallback.java @@ -13,9 +13,9 @@ // limitations under the License. package com.google.devtools.build.lib.query2.cquery; - import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.query2.NamedThreadSafeOutputFormatterCallback; @@ -42,7 +42,7 @@ * focused on completeness, should output full configuration checksums. */ public abstract class CqueryThreadsafeCallback - extends NamedThreadSafeOutputFormatterCallback { + extends NamedThreadSafeOutputFormatterCallback { protected final ExtendedEventHandler eventHandler; protected final CqueryOptions options; @@ -64,7 +64,7 @@ public abstract class CqueryThreadsafeCallback CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, boolean uniquifyResults) { this.eventHandler = eventHandler; this.options = options; diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java index 64de8ac00631b1..951baa0906bd46 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryTransitionResolver.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.DependencyKey; import com.google.devtools.build.lib.analysis.DependencyKind; import com.google.devtools.build.lib.analysis.DependencyKind.NonAttributeDependencyKind; @@ -110,17 +111,17 @@ public CqueryTransitionResolver( } /** - * Return the set of dependencies of a KeyedConfiguredTarget, including information about the + * Return the set of dependencies of a ConfiguredTarget, including information about the * configuration transitions applied to the dependencies. * * @see ResolvedTransition for more details. * @param keyedConfiguredTarget the configured target whose dependencies are being looked up. */ - public ImmutableSet dependencies(KeyedConfiguredTarget keyedConfiguredTarget) + public ImmutableSet dependencies(ConfiguredTarget keyedConfiguredTarget) throws DependencyResolver.Failure, InconsistentAspectOrderException, InterruptedException { ImmutableSet.Builder resolved = new ImmutableSet.Builder<>(); - if (!(keyedConfiguredTarget.getConfiguredTarget() instanceof RuleConfiguredTarget)) { + if (!(keyedConfiguredTarget instanceof RuleConfiguredTarget)) { return resolved.build(); } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java index e4d94b995470cb..f873120c8417c1 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java @@ -36,7 +36,7 @@ public class FilesOutputFormatterCallback extends CqueryThreadsafeCallback { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, TopLevelArtifactContext topLevelArtifactContext) { // Different targets may provide the same artifact, so we deduplicate the collection of all // results at the end. @@ -50,10 +50,9 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) + public void processOutput(Iterable partialResult) throws IOException, InterruptedException { - for (KeyedConfiguredTarget keyedTarget : partialResult) { - ConfiguredTarget target = keyedTarget.getConfiguredTarget(); + for (ConfiguredTarget target : partialResult) { if (!TopLevelArtifactHelper.shouldConsiderForDisplay(target) && !(target instanceof InputFileConfiguredTarget)) { continue; diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java index 009fcd4b0a974a..a8e3dfffb982d0 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallback.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.events.ExtendedEventHandler; @@ -37,20 +38,19 @@ public String getName() { /** Interface for finding a configured target's direct dependencies. */ @FunctionalInterface public interface DepsRetriever { - Iterable getDirectDeps(KeyedConfiguredTarget target) - throws InterruptedException; + Iterable getDirectDeps(ConfiguredTarget target) throws InterruptedException; } private final DepsRetriever depsRetriever; - private final GraphOutputWriter.NodeReader nodeReader = - new NodeReader() { + private final GraphOutputWriter.NodeReader nodeReader = + new NodeReader() { - private final Comparator configuredTargetOrdering = + private final Comparator configuredTargetOrdering = (ct1, ct2) -> { // Order graph output first by target label, then by configuration hash. - Label label1 = ct1.getLabel(); - Label label2 = ct2.getLabel(); + Label label1 = ct1.getOriginalLabel(); + Label label2 = ct2.getOriginalLabel(); if (!label1.equals(label2)) { return label1.compareTo(label2); } @@ -67,18 +67,18 @@ Iterable getDirectDeps(KeyedConfiguredTarget target) @Override public String getLabel( - Node node, RepositoryMapping mainRepositoryMapping) { + Node node, RepositoryMapping mainRepositoryMapping) { // Node payloads are ConfiguredTargets. Output node labels are target labels + config // hashes. - KeyedConfiguredTarget kct = node.getLabel(); + ConfiguredTarget kct = node.getLabel(); return String.format( "%s (%s)", - kct.getLabel().getDisplayForm(mainRepositoryMapping), + kct.getOriginalLabel().getDisplayForm(mainRepositoryMapping), shortId(getConfiguration(kct.getConfigurationKey()))); } @Override - public Comparator comparator() { + public Comparator comparator() { return configuredTargetOrdering; } }; @@ -90,7 +90,7 @@ public Comparator comparator() { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, DepsRetriever depsRetriever, RepositoryMapping mainRepoMapping) { super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false); @@ -99,32 +99,31 @@ public Comparator comparator() { } @Override - public void processOutput(Iterable partialResult) - throws InterruptedException { + public void processOutput(Iterable partialResult) throws InterruptedException { // Transform the cquery-backed graph into a Digraph to make it suitable for GraphOutputWriter. // Note that this involves an extra iteration over the entire query result subgraph. We could // conceptually merge transformation and output writing into the same iteration if needed. - Digraph graph = new Digraph<>(); - ImmutableSet allNodes = ImmutableSet.copyOf(partialResult); - for (KeyedConfiguredTarget configuredTarget : partialResult) { - Node node = graph.createNode(configuredTarget); - for (KeyedConfiguredTarget dep : depsRetriever.getDirectDeps(configuredTarget)) { + Digraph graph = new Digraph<>(); + ImmutableSet allNodes = ImmutableSet.copyOf(partialResult); + for (ConfiguredTarget configuredTarget : partialResult) { + Node node = graph.createNode(configuredTarget); + for (ConfiguredTarget dep : depsRetriever.getDirectDeps(configuredTarget)) { if (allNodes.contains(dep)) { - Node depNode = graph.createNode(dep); + Node depNode = graph.createNode(dep); graph.addEdge(node, depNode); } } } - GraphOutputWriter graphWriter = + GraphOutputWriter graphWriter = new GraphOutputWriter<>( nodeReader, options.getLineTerminator(), - /*sortLabels=*/ true, + /* sortLabels= */ true, options.graphNodeStringLimit, // select() conditions don't matter for cquery because cquery operates post-analysis // phase, when select()s have been resolved and removed from the graph. - /*maxConditionalEdges=*/ 0, + /* maxConditionalEdges= */ 0, options.graphFactored, mainRepoMapping); graphWriter.write(graph, /*conditionalEdges=*/ null, outputStream); diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/KeyedConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/KeyedConfiguredTarget.java deleted file mode 100644 index fb14222d3df433..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/KeyedConfiguredTarget.java +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2020 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.query2.cquery; - -import com.google.auto.value.AutoValue; -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.skyframe.BuildConfigurationKey; -import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; -import javax.annotation.Nullable; - -/** - * A representation of a ConfiguredTargetKey and the ConfiguredTarget that it points to, for use in - * configured target queries. - */ -@AutoValue -public abstract class KeyedConfiguredTarget { - - /** Returns a new KeyedConfiguredTarget for the given data. */ - public static KeyedConfiguredTarget create( - ConfiguredTargetKey configuredTargetKey, ConfiguredTarget configuredTarget) { - return new AutoValue_KeyedConfiguredTarget(configuredTargetKey, configuredTarget); - } - - /** Returns the key for this KeyedConfiguredTarget. */ - @Nullable - public abstract ConfiguredTargetKey getConfiguredTargetKey(); - - /** Returns the ConfiguredTarget for this KeyedConfiguredTarget. */ - public abstract ConfiguredTarget getConfiguredTarget(); - - /** Returns the original (pre-alias) label for the underlying ConfiguredTarget. */ - public Label getLabel() { - return getConfiguredTarget().getOriginalLabel(); - } - - /** Returns the configuration key used for this KeyedConfiguredTarget. */ - @Nullable - public BuildConfigurationKey getConfigurationKey() { - return getConfiguredTarget().getConfigurationKey(); - } - - /** Returns the configuration checksum in use for this KeyedConfiguredTarget. */ - @Nullable - public String getConfigurationChecksum() { - return getConfigurationKey() == null ? null : getConfigurationKey().getOptions().checksum(); - } - - /** - * The configuration conditions that trigger this configured target's configurable attributes. For - * targets that do not support configurable attributes, this will be an empty map. - */ - public ImmutableMap getConfigConditions() { - return getConfiguredTarget().getConfigConditions(); - } - - /** Returns a KeyedConfiguredTarget instance that resolves aliases. */ - public KeyedConfiguredTarget getActual() { - ConfiguredTarget actual = getConfiguredTarget().getActual(); - // Use old values for unchanged fields, like toolchain ctx, if possible. - ConfiguredTargetKey.Builder oldKey = - (this.getConfiguredTargetKey() == null - ? ConfiguredTargetKey.builder() - : this.getConfiguredTargetKey().toBuilder()); - - ConfiguredTargetKey actualKey = - oldKey - .setLabel(actual.getLabel()) - .setConfigurationKey(actual.getConfigurationKey()) - .build(); - return KeyedConfiguredTarget.create(actualKey, actual); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java index 73bfd9cfc0bd67..533408fb58b2c9 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/LabelAndConfigurationOutputFormatterCallback.java @@ -15,6 +15,7 @@ import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.RequiredConfigFragmentsProvider; import com.google.devtools.build.lib.analysis.config.CoreOptions.IncludeConfigFragmentsEnum; import com.google.devtools.build.lib.cmdline.Label; @@ -36,7 +37,7 @@ public class LabelAndConfigurationOutputFormatterCallback extends CqueryThreadsa CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, boolean showKind, RepositoryMapping mainRepoMapping) { super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false); @@ -50,8 +51,8 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) { - for (KeyedConfiguredTarget keyedConfiguredTarget : partialResult) { + public void processOutput(Iterable partialResult) { + for (ConfiguredTarget keyedConfiguredTarget : partialResult) { StringBuilder output = new StringBuilder(); if (showKind) { Target actualTarget = accessor.getTarget(keyedConfiguredTarget); @@ -59,7 +60,7 @@ public void processOutput(Iterable partialResult) { } output = output - .append(keyedConfiguredTarget.getLabel().getDisplayForm(mainRepoMapping)) + .append(keyedConfiguredTarget.getOriginalLabel().getDisplayForm(mainRepoMapping)) .append(" (") .append(shortId(getConfiguration(keyedConfiguredTarget.getConfigurationKey()))) .append(")"); @@ -73,10 +74,9 @@ public void processOutput(Iterable partialResult) { } private static ImmutableSortedSet requiredFragmentStrings( - KeyedConfiguredTarget keyedConfiguredTarget) { + ConfiguredTarget keyedConfiguredTarget) { RequiredConfigFragmentsProvider requiredFragments = keyedConfiguredTarget - .getConfiguredTarget() .getProvider(RequiredConfigFragmentsProvider.class); if (requiredFragments == null) { return ImmutableSortedSet.of(); diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java index 16e5ea2e77cde9..9ffc8d44185e6e 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallback.java @@ -23,6 +23,7 @@ import com.google.devtools.build.lib.actions.BuildConfigurationEvent; import com.google.devtools.build.lib.analysis.AnalysisProtosV2; import com.google.devtools.build.lib.analysis.AnalysisProtosV2.Configuration; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.DependencyResolver; import com.google.devtools.build.lib.analysis.InconsistentAspectOrderException; import com.google.devtools.build.lib.analysis.config.BuildOptions; @@ -114,14 +115,14 @@ public ImmutableList getConfigurations() { private AnalysisProtosV2.CqueryResult.Builder protoResult; private final Map partialResultMap; - private KeyedConfiguredTarget currentTarget; + private ConfiguredTarget currentTarget; ProtoOutputFormatterCallback( ExtendedEventHandler eventHandler, CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, AspectResolver resolver, OutputType outputType, @Nullable TransitionFactory trimmingTransitionFactory) { @@ -184,9 +185,9 @@ public AnalysisProtosV2.CqueryResult getProtoResult() { } @Override - public void processOutput(Iterable partialResult) - throws InterruptedException { - partialResult.forEach(kct -> partialResultMap.put(kct.getLabel(), accessor.getTarget(kct))); + public void processOutput(Iterable partialResult) throws InterruptedException { + partialResult.forEach( + kct -> partialResultMap.put(kct.getOriginalLabel(), accessor.getTarget(kct))); KnownTargetsDependencyResolver knownTargetsDependencyResolver = new KnownTargetsDependencyResolver(partialResultMap); @@ -201,7 +202,7 @@ public void processOutput(Iterable partialResult) ConfiguredProtoOutputFormatter formatter = new ConfiguredProtoOutputFormatter(); formatter.setOptions(options, resolver, skyframeExecutor.getDigestFunction().getHashFunction()); - for (KeyedConfiguredTarget keyedConfiguredTarget : partialResult) { + for (ConfiguredTarget keyedConfiguredTarget : partialResult) { AnalysisProtosV2.ConfiguredTarget.Builder builder = AnalysisProtosV2.ConfiguredTarget.newBuilder(); @@ -251,7 +252,7 @@ public void processOutput(Iterable partialResult) builder.setConfiguration( AnalysisProtosV2.Configuration.newBuilder().setChecksum(String.valueOf(checksum))); - ConfiguredTargetKey configuredTargetKey = keyedConfiguredTarget.getConfiguredTargetKey(); + var configuredTargetKey = ConfiguredTargetKey.fromConfiguredTarget(keyedConfiguredTarget); // Some targets don't have a configuration, e.g. InputFileConfiguredTarget if (configuredTargetKey != null) { BuildConfigurationKey configurationKey = configuredTargetKey.getConfigurationKey(); @@ -277,13 +278,13 @@ protected void addAttributes( // because this method is only triggered in ProtoOutputFormatter.toTargetProtoBuffer when // the target in currentTarget is an instanceof Rule. ImmutableMap configConditions = - currentTarget.getConfiguredTarget().getConfigConditions(); + currentTarget.getConfigConditions(); ConfiguredAttributeMapper attributeMapper = ConfiguredAttributeMapper.of( rule, configConditions, - currentTarget.getConfigurationChecksum(), - /*alwaysSucceed=*/ false); + currentTarget.getConfigurationKey().getOptionsChecksum(), + /* alwaysSucceed= */ false); for (Attribute attr : sortAttributes(rule.getAttributes())) { if (!shouldIncludeAttribute(rule, attr)) { continue; diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java index 92a0ca1663dc72..6edba927e3f215 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/StarlarkOutputFormatterCallback.java @@ -137,7 +137,7 @@ public Object providers(ConfiguredTarget target) { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor) + TargetAccessor accessor) throws QueryException, InterruptedException { super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false); @@ -224,18 +224,15 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) - throws InterruptedException { - for (KeyedConfiguredTarget target : partialResult) { + public void processOutput(Iterable partialResult) throws InterruptedException { + for (ConfiguredTarget target : partialResult) { try { StarlarkThread thread = new StarlarkThread(Mutability.create("cquery evaluation"), StarlarkSemantics.DEFAULT); thread.setMaxExecutionSteps(500_000L); // Invoke formatFn with `target` argument. - Object result = - Starlark.fastcall( - thread, this.formatFn, new Object[] {target.getConfiguredTarget()}, NO_ARGS); + Object result = Starlark.fastcall(thread, this.formatFn, new Object[] {target}, NO_ARGS); addResult(Starlark.str(result, thread.getSemantics())); } catch (EvalException ex) { @@ -243,7 +240,7 @@ public void processOutput(Iterable partialResult) Event.error( String.format( "Starlark evaluation error for %s: %s", - target.getLabel(), ex.getMessageWithStack()))); + target.getOriginalLabel(), ex.getMessageWithStack()))); continue; } } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java index 6e5b12f7aa65ec..9cb0d1da2928a1 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterCallback.java @@ -62,7 +62,7 @@ public String getName() { CqueryOptions options, OutputStream out, SkyframeExecutor skyframeExecutor, - TargetAccessor accessor, + TargetAccessor accessor, @Nullable TransitionFactory trimmingTransitionFactory, RepositoryMapping mainRepoMapping) { super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/ false); @@ -72,8 +72,7 @@ public String getName() { } @Override - public void processOutput(Iterable partialResult) - throws InterruptedException { + public void processOutput(Iterable partialResult) throws InterruptedException { CqueryOptions.Transitions verbosity = options.transitions; if (verbosity.equals(CqueryOptions.Transitions.NONE)) { eventHandler.handle( @@ -82,19 +81,17 @@ public void processOutput(Iterable partialResult) + " flag explicitly to 'lite' or 'full'")); return; } - partialResult.forEach(kct -> partialResultMap.put(kct.getLabel(), accessor.getTarget(kct))); - for (KeyedConfiguredTarget keyedConfiguredTarget : partialResult) { - Target target = partialResultMap.get(keyedConfiguredTarget.getLabel()); + partialResult.forEach( + kct -> partialResultMap.put(kct.getOriginalLabel(), accessor.getTarget(kct))); + for (ConfiguredTarget keyedConfiguredTarget : partialResult) { + Target target = partialResultMap.get(keyedConfiguredTarget.getOriginalLabel()); BuildConfigurationValue config = getConfiguration(keyedConfiguredTarget.getConfigurationKey()); addResult( - getRuleClassTransition(keyedConfiguredTarget.getConfiguredTarget(), target) + getRuleClassTransition(keyedConfiguredTarget, target) + String.format( "%s (%s)", - keyedConfiguredTarget - .getConfiguredTarget() - .getOriginalLabel() - .getDisplayForm(mainRepoMapping), + keyedConfiguredTarget.getOriginalLabel().getDisplayForm(mainRepoMapping), shortId(config))); KnownTargetsDependencyResolver knownTargetsDependencyResolver = new KnownTargetsDependencyResolver(partialResultMap); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java index 19f338ce64ec22..7facee83fb784a 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java @@ -72,6 +72,10 @@ public SkyFunctionName functionName() { return SkyFunctions.BUILD_CONFIGURATION; } + public String getOptionsChecksum() { + return options.checksum(); + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD b/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD index 0b9d60f9a90d7d..c9378ab6a6c1a1 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/BUILD @@ -19,6 +19,7 @@ java_test( deps = [ ":configured_target_query_helper", ":configured_target_query_test", + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/query2", @@ -40,6 +41,7 @@ java_test( deps = [ ":configured_target_query_helper", ":configured_target_query_test", + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/query2", @@ -63,11 +65,11 @@ java_test( "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options", "//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/patch_transition", + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/analysis:test/test_configuration", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", - "//src/main/java/com/google/devtools/build/lib/query2", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/lib/util:filetype", "//src/main/java/com/google/devtools/build/lib/vfs", @@ -85,6 +87,7 @@ java_library( testonly = 1, srcs = ["ConfiguredTargetQueryHelper.java"], deps = [ + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/query2", "//src/main/java/com/google/devtools/build/lib/query2/engine", "//src/main/java/com/google/devtools/build/skyframe", @@ -105,6 +108,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis:config/build_options", "//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/split_transition", + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/query2", "//src/main/java/com/google/devtools/build/lib/query2/engine", @@ -125,6 +129,7 @@ java_test( ":configured_target_query_helper", ":configured_target_query_test", "//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory", + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/query2", @@ -152,6 +157,7 @@ java_test( "//src/main/java/com/google/devtools/build/lib/analysis:config/transition_factories", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/no_transition", "//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/transition_factory", + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/packages", @@ -175,6 +181,7 @@ java_test( ":configured_target_query_helper", ":configured_target_query_test", "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster", + "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/analysis:top_level_artifact_context", "//src/main/java/com/google/devtools/build/lib/events", "//src/main/java/com/google/devtools/build/lib/query2", diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java index 949eaa3650471f..60093188556e21 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/BuildOutputFormatterCallbackTest.java @@ -19,6 +19,7 @@ import static com.google.devtools.build.lib.packages.BuildType.OUTPUT; import com.google.common.eventbus.EventBus; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.util.MockRule; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; @@ -73,7 +74,7 @@ private List getOutput(String queryExpression) throws Exception { Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java index a713d59651fef0..3953238a6ad18d 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryHelper.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.query2.cquery; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.util.AnalysisTestCase; import com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment.TopLevelConfigurations; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; @@ -30,7 +31,7 @@ * AnalysisTestCase} must be run manually. @BeforeClass and @AfterClass are completely ignored for * now. */ -public class ConfiguredTargetQueryHelper extends PostAnalysisQueryHelper { +public class ConfiguredTargetQueryHelper extends PostAnalysisQueryHelper { @Override protected ConfiguredTargetQueryEnvironment getPostAnalysisQueryEnvironment( WalkableGraph walkableGraph, @@ -53,7 +54,7 @@ protected ConfiguredTargetQueryEnvironment getPostAnalysisQueryEnvironment( } @Override - public String getLabel(KeyedConfiguredTarget target) { - return target.getConfiguredTarget().getLabel().toString(); + public String getLabel(ConfiguredTarget target) { + return target.getOriginalLabel().toString(); } } diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java index 1a2534d411fef5..2fb6bedc1eeb77 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQuerySemanticsTest.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.BuildOptionsView; @@ -45,7 +46,6 @@ import com.google.devtools.build.lib.server.FailureDetails.Query.Code; import com.google.devtools.build.lib.util.FileTypeSet; import com.google.devtools.build.lib.vfs.Path; -import java.util.Collection; import java.util.Iterator; import java.util.Set; import java.util.stream.Collectors; @@ -121,9 +121,9 @@ public void testLabelFunction_getCorrectlyConfiguredDeps() throws Exception { setUpLabelsFunctionTests(); // Test that this retrieves the correctly configured version(s) of the dep(s). - KeyedConfiguredTarget patchDep = + ConfiguredTarget patchDep = Iterables.getOnlyElement(eval("labels('patch_dep', //test:my_rule)")); - KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); String targetConfiguration = myRule.getConfigurationChecksum(); assertThat(patchDep.getConfigurationChecksum()).doesNotMatch(targetConfiguration); } @@ -132,12 +132,12 @@ public void testLabelFunction_getCorrectlyConfiguredDeps() throws Exception { public void testLabelsFunction_splitTransitionAttribute() throws Exception { setUpLabelsFunctionTests(); - KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); String targetConfiguration = myRule.getConfigurationChecksum(); - Collection splitDeps = eval("labels('split_dep', //test:my_rule)"); + Set splitDeps = eval("labels('split_dep', //test:my_rule)"); assertThat(splitDeps).hasSize(2); - for (KeyedConfiguredTarget kct : splitDeps) { + for (ConfiguredTarget kct : splitDeps) { assertThat(kct.getConfigurationChecksum()).doesNotMatch(targetConfiguration); } } @@ -146,13 +146,13 @@ public void testLabelsFunction_splitTransitionAttribute() throws Exception { public void testLabelsFunction_labelListAttribute() throws Exception { setUpLabelsFunctionTests(); - KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); String targetConfiguration = myRule.getConfigurationChecksum(); // Test that this works for label_lists as well. - Set deps = eval("labels('patch_dep_list', //test:my_rule)"); + Set deps = eval("labels('patch_dep_list', //test:my_rule)"); assertThat(deps).hasSize(2); - for (KeyedConfiguredTarget kct : deps) { + for (ConfiguredTarget kct : deps) { assertThat(kct.getConfigurationChecksum()).doesNotMatch(targetConfiguration); } } @@ -195,7 +195,7 @@ public void testGetPrerequisitesFromAliasReturnsActualPrerequisites() throws Exc "rule_with_dep(name = 'actual', dep = ':dep')", "rule_with_dep(name = 'dep')"); - KeyedConfiguredTarget dep = Iterables.getOnlyElement(eval("labels('dep', '//test:alias')")); + ConfiguredTarget dep = Iterables.getOnlyElement(eval("labels('dep', '//test:alias')")); assertThat(dep.getLabel()).isEqualTo(Label.parseCanonicalUnchecked("//test:dep")); } @@ -223,12 +223,11 @@ public void testAlias_filtering() throws Exception { "alias(name = 'other_impl_dep', actual = 'impl_dep')", "simple_rule(name='impl_dep')"); - KeyedConfiguredTarget other = Iterables.getOnlyElement(eval("//test:other_my_rule")); - KeyedConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); - // Note: {@link KeyedConfiguredTarget#getLabel} returns the label of the "actual" value not the + ConfiguredTarget other = Iterables.getOnlyElement(eval("//test:other_my_rule")); + ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule")); + // Note: {@link ConfiguredTarget#getLabel} returns the label of the "actual" value not the // label of the alias, so we need to check the underlying label. - assertThat(other.getConfiguredTarget().getLabel()) - .isEqualTo(myRule.getConfiguredTarget().getLabel()); + assertThat(other.getLabel()).isEqualTo(myRule.getLabel()); // Regression test for b/73496081 in which alias-ed configured targets were skipping filtering. helper.setQuerySettings(Setting.ONLY_TARGET_DEPS, Setting.NO_IMPLICIT_DEPS); @@ -249,7 +248,7 @@ public void testTopLevelTransition() throws Exception { writeFile("test/BUILD", "rule_class_transition(name='rule_class')"); - Set ruleClass = eval("//test:rule_class"); + Set ruleClass = eval("//test:rule_class"); DummyTestOptions testOptions = getConfiguration(Iterables.getOnlyElement(ruleClass)) .getOptions() @@ -376,10 +375,10 @@ public void testConfig_configHash() throws Exception { // setting --universe_scope we ensure only the transitioned version exists. helper.setUniverseScope("//test:buildme"); helper.setQuerySettings(Setting.ONLY_TARGET_DEPS, Setting.NO_IMPLICIT_DEPS); - Set result = eval("deps(//test:buildme, 1)"); + Set result = eval("deps(//test:buildme, 1)"); assertThat(result).hasSize(2); - ImmutableList stableOrderList = ImmutableList.copyOf(result); + ImmutableList stableOrderList = ImmutableList.copyOf(result); int myDepIndex = stableOrderList.get(0).getLabel().toString().equals("//test:mydep") ? 0 : 1; BuildConfigurationValue myDepConfig = getConfiguration(stableOrderList.get(myDepIndex)); BuildConfigurationValue stringFlagConfig = @@ -404,12 +403,11 @@ public void testConfig_configHashPrefix() throws Exception { createConfigRulesAndBuild(); writeFile("mytest/BUILD", "simple_rule(name = 'mytarget')"); - Set result = eval("//mytest:mytarget"); + Set result = eval("//mytest:mytarget"); String configHash = getConfiguration(Iterables.getOnlyElement(result)).checksum(); String hashPrefix = configHash.substring(0, configHash.length() / 2); - Set resultFromPrefix = - eval("config(//mytest:mytarget," + hashPrefix + ")"); + Set resultFromPrefix = eval("config(//mytest:mytarget," + hashPrefix + ")"); assertThat(resultFromPrefix).containsExactlyElementsIn(result); } @@ -418,7 +416,7 @@ public void testConfig_configHashUnknownPrefix() throws Exception { createConfigRulesAndBuild(); writeFile("mytest/BUILD", "simple_rule(name = 'mytarget')"); - Set result = eval("//mytest:mytarget"); + Set result = eval("//mytest:mytarget"); String configHash = getConfiguration(Iterables.getOnlyElement(result)).checksum(); String rightPrefix = configHash.substring(0, configHash.length() / 2); char lastChar = rightPrefix.charAt(rightPrefix.length() - 1); @@ -504,12 +502,12 @@ public void testRecursiveTargetPatternOutsideOfScopeFailsGracefully() throws Exc public void testMultipleTopLevelConfigurations_nullConfigs() throws Exception { writeFile("test/BUILD", "java_library(name='my_java',", " srcs = ['foo.java'],", ")"); - Set result = eval("//test:my_java+//test:foo.java"); + Set result = eval("//test:my_java+//test:foo.java"); assertThat(result).hasSize(2); - Iterator resultIterator = result.iterator(); - KeyedConfiguredTarget first = resultIterator.next(); + Iterator resultIterator = result.iterator(); + ConfiguredTarget first = resultIterator.next(); if (first.getLabel().toString().equals("//test:foo.java")) { assertThat(getConfiguration(first)).isNull(); assertThat(getConfiguration(resultIterator.next())).isNotNull(); @@ -539,7 +537,7 @@ public void testSomePath_depInCustomConfiguration() throws Exception { // cases cquery prefers the top-level configured one, which won't produce a match since that's // not the one down this dependency path. helper.setUniverseScope("//test:buildme"); - Set result = eval("somepath(//test:buildme, //test:mydep)"); + Set result = eval("somepath(//test:buildme, //test:mydep)"); assertThat(result.stream().map(kct -> kct.getLabel().toString()).collect(Collectors.toList())) .contains("//test:mydep"); } @@ -585,7 +583,7 @@ public void testQueryHandlesDroppingFragments() throws Exception { "simple_rule(name='foo', deps = [':bar'])", "simple_rule(name='bar')"); - Set result = + Set result = eval("somepath(//test:top, filter(//test:bar, deps(//test:top)))"); assertThat(result).isNotEmpty(); } @@ -605,7 +603,7 @@ public void testLabelExpressionsMatchesAllConfiguredTargetsWithLabel() throws Ex "simple_rule(name = 'simple')"); helper.setUniverseScope("//test:transitioner,//test:simple"); - Set result = eval("//test:simple"); + Set result = eval("//test:simple"); assertThat(result.size()).isEqualTo(2); } @@ -627,7 +625,7 @@ public void testConfigFunctionRefinesMultipleMatches() throws Exception { "simple_rule(name = 'simple')"); helper.setUniverseScope("//test:transitioner,//test:simple"); - Set result = eval("config(//test:simple, target)"); + Set result = eval("config(//test:simple, target)"); assertThat(result.size()).isEqualTo(1); } } diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java index fe7f60246a3bab..75176014fb2645 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryTest.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.BuildOptionsView; @@ -37,11 +38,10 @@ /** Tests for {@link ConfiguredTargetQueryEnvironment}. */ @RunWith(JUnit4.class) -public abstract class ConfiguredTargetQueryTest - extends PostAnalysisQueryTest { +public abstract class ConfiguredTargetQueryTest extends PostAnalysisQueryTest { @Override - protected QueryHelper createQueryHelper() { + protected QueryHelper createQueryHelper() { return new ConfiguredTargetQueryHelper(); } @@ -57,7 +57,7 @@ public HashMap getDefaultFunctions() { } @Override - protected final BuildConfigurationValue getConfiguration(KeyedConfiguredTarget kct) { + protected final BuildConfigurationValue getConfiguration(ConfiguredTarget kct) { return getHelper() .getSkyframeExecutor() .getConfiguration(getHelper().getReporter(), kct.getConfigurationKey()); @@ -93,12 +93,12 @@ public Map split(BuildOptionsView options, EventHandler ev public void testMultipleTopLevelConfigurations_nullConfigs() throws Exception { writeFile("test/BUILD", "java_library(name='my_java',", " srcs = ['foo.java'],", ")"); - Set result = eval("//test:my_java+//test:foo.java"); + Set result = eval("//test:my_java+//test:foo.java"); assertThat(result).hasSize(2); - Iterator resultIterator = result.iterator(); - KeyedConfiguredTarget first = resultIterator.next(); + Iterator resultIterator = result.iterator(); + ConfiguredTarget first = resultIterator.next(); if (first.getLabel().toString().equals("//test:foo.java")) { assertThat(getConfiguration(first)).isNull(); assertThat(getConfiguration(resultIterator.next())).isNotNull(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java index 63fc09e77bd966..89c17b687f9f99 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.OutputGroupInfo; import com.google.devtools.build.lib.analysis.OutputGroupInfo.ValidationMode; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; @@ -111,7 +112,7 @@ private List getOutput(String queryExpression, List outputGroups QueryExpression expression = QueryParser.parse(queryExpression, getDefaultFunctions()); Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java index 2e96a4427c998a..aeaa272d7209e4 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/GraphOutputFormatterCallbackTest.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; @@ -70,7 +71,7 @@ private List getOutput(String queryExpression) throws Exception { Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java index 8b8cf65658bb5e..70166d57ff4e59 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/ProtoOutputFormatterCallbackTest.java @@ -22,7 +22,7 @@ import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.analysis.AnalysisProtosV2; import com.google.devtools.build.lib.analysis.AnalysisProtosV2.Configuration; -import com.google.devtools.build.lib.analysis.AnalysisProtosV2.ConfiguredTarget; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory; import com.google.devtools.build.lib.analysis.util.MockRule; import com.google.devtools.build.lib.events.Event; @@ -160,12 +160,13 @@ public void testConfigurations() throws Exception { List configurations = cqueryResult.getConfigurationsList(); assertThat(configurations).hasSize(2); - List resultsList = cqueryResult.getResultsList(); + List resultsList = cqueryResult.getResultsList(); - ConfiguredTarget parentRuleProto = getRuleProtoByName(resultsList, "//test:parent_rule"); - Set keyedTargets = eval("deps(//test:parent_rule)"); + AnalysisProtosV2.ConfiguredTarget parentRuleProto = + getRuleProtoByName(resultsList, "//test:parent_rule"); + Set keyedTargets = eval("deps(//test:parent_rule)"); - KeyedConfiguredTarget parentRule = getKeyedTargetByLabel(keyedTargets, "//test:parent_rule"); + ConfiguredTarget parentRule = getKeyedTargetByLabel(keyedTargets, "//test:parent_rule"); assertThat(parentRuleProto.getConfiguration().getChecksum()) .isEqualTo(parentRule.getConfigurationChecksum()); @@ -183,10 +184,9 @@ public void testConfigurations() throws Exception { .setIsTool(false) .build()); - ConfiguredTarget transitionRuleProto = + AnalysisProtosV2.ConfiguredTarget transitionRuleProto = getRuleProtoByName(resultsList, "//test:transition_rule"); - KeyedConfiguredTarget transitionRule = - getKeyedTargetByLabel(keyedTargets, "//test:transition_rule"); + ConfiguredTarget transitionRule = getKeyedTargetByLabel(keyedTargets, "//test:transition_rule"); assertThat(transitionRuleProto.getConfiguration().getChecksum()) .isEqualTo(transitionRule.getConfigurationChecksum()); @@ -195,14 +195,14 @@ public void testConfigurations() throws Exception { assertThat(transitionConfiguration.getChecksum()) .isEqualTo(transitionRule.getConfigurationChecksum()); - ConfiguredTarget depRuleProto = getRuleProtoByName(resultsList, "//test:dep"); + AnalysisProtosV2.ConfiguredTarget depRuleProto = getRuleProtoByName(resultsList, "//test:dep"); Configuration depRuleConfiguration = getConfigurationForId(configurations, depRuleProto.getConfigurationId()); assertThat(depRuleConfiguration.getPlatformName()).isEqualTo("k8"); assertThat(depRuleConfiguration.getMnemonic()).matches("k8-opt-exec-.*"); assertThat(depRuleConfiguration.getIsTool()).isTrue(); - KeyedConfiguredTarget depRule = getKeyedTargetByLabel(keyedTargets, "//test:dep"); + ConfiguredTarget depRule = getKeyedTargetByLabel(keyedTargets, "//test:dep"); assertThat(depRuleProto.getConfiguration().getChecksum()) .isEqualTo(depRule.getConfigurationChecksum()); @@ -211,7 +211,7 @@ public void testConfigurations() throws Exception { assertThat(depRuleConfiguration.getChecksum()) .isNotEqualTo(transitionConfiguration.getChecksum()); // Targets without a configuration have a configuration_id of 0. - ConfiguredTarget fileTargetProto = + AnalysisProtosV2.ConfiguredTarget fileTargetProto = resultsList.stream() .filter(result -> "//test:patched".equals(result.getTarget().getSourceFile().getName())) .findAny() @@ -238,11 +238,10 @@ public void testConfigurations() throws Exception { .containsExactly(patchedConfiguredRuleInput, depConfiguredRuleInput); } - private KeyedConfiguredTarget getKeyedTargetByLabel( - Set keyedTargets, String label) { + private ConfiguredTarget getKeyedTargetByLabel(Set keyedTargets, String label) { return Iterables.getOnlyElement( keyedTargets.stream() - .filter(t -> label.equals(t.getConfiguredTarget().getLabel().getCanonicalForm())) + .filter(t -> label.equals(t.getLabel().getCanonicalForm())) .collect(Collectors.toSet())); } @@ -250,7 +249,8 @@ private Configuration getConfigurationForId(List configurations, return configurations.stream().filter(c -> c.getId() == id).findAny().orElseThrow(); } - private ConfiguredTarget getRuleProtoByName(List resultsList, String s) { + private AnalysisProtosV2.ConfiguredTarget getRuleProtoByName( + List resultsList, String s) { return resultsList.stream() .filter(result -> s.equals(result.getTarget().getRule().getName())) .findAny() @@ -316,7 +316,7 @@ private AnalysisProtosV2.CqueryResult getOutput(String queryExpression) throws E Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); ProtoOutputFormatterCallback callback = diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java index 75183e55dbd592..7b15a79ac99c14 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/TransitionsOutputFormatterTest.java @@ -20,6 +20,7 @@ import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.config.TransitionFactories; import com.google.devtools.build.lib.analysis.config.transitions.NoTransition; import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory; @@ -234,7 +235,7 @@ private List getOutput(String queryExpression, CqueryOptions.Transitions Set targetPatternSet = new LinkedHashSet<>(); expression.collectTargetPatterns(targetPatternSet); helper.setQuerySettings(Setting.NO_IMPLICIT_DEPS); - PostAnalysisQueryEnvironment env = + PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); options.transitions = verbosity; // TODO(blaze-configurability): Test late-bound attributes.