Skip to content

Commit a2bd3ef

Browse files
aoeuicopybara-github
authored andcommitted
Add filter in cquery/aquery to skip targets with mismatched configurations.
PiperOrigin-RevId: 542432271 Change-Id: Idad6ff6e333b8fd1c6f18858b9544a36c10ce659
1 parent 70b17c3 commit a2bd3ef

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/main/java/com/google/devtools/build/lib/query2/aquery/ActionGraphQueryEnvironment.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.io.OutputStream;
5252
import java.util.ArrayList;
5353
import java.util.List;
54+
import java.util.Objects;
5455
import java.util.Set;
5556
import java.util.function.Supplier;
5657
import javax.annotation.Nullable;
@@ -194,7 +195,15 @@ public Label getCorrectLabel(ConfiguredTargetValue configuredTargetValue) {
194195
@Nullable
195196
private ConfiguredTargetValue createConfiguredTargetValueFromKey(ConfiguredTargetKey key)
196197
throws InterruptedException {
197-
return getConfiguredTargetValue(key.toKey());
198+
ConfiguredTargetValue value = getConfiguredTargetValue(key.toKey());
199+
if (value == null
200+
|| !Objects.equals(
201+
value.getConfiguredTarget().getConfigurationKey(), key.getConfigurationKey())) {
202+
// The configurations might not match if the target's configuration changed due to a
203+
// transition or trimming. Filters such targets.
204+
return null;
205+
}
206+
return value;
198207
}
199208

200209
@Nullable
@@ -235,7 +244,7 @@ protected ConfiguredTargetValue getNullConfiguredTarget(Label label) throws Inte
235244
@Override
236245
protected ConfiguredTargetValue getValueFromKey(SkyKey key) throws InterruptedException {
237246
Preconditions.checkState(key instanceof ConfiguredTargetKey);
238-
return createConfiguredTargetValueFromKey((ConfiguredTargetKey) key);
247+
return getConfiguredTargetValue(((ConfiguredTargetKey) key).toKey());
239248
}
240249

241250
@Nullable
@@ -335,6 +344,6 @@ public void setActionFilters(AqueryActionFilter actionFilters) {
335344
}
336345

337346
private static ConfiguredTargetKey getConfiguredTargetKeyImpl(ConfiguredTargetValue targetValue) {
338-
return (ConfiguredTargetKey) targetValue.getConfiguredTarget().getKeyOrProxy();
347+
return ConfiguredTargetKey.fromConfiguredTarget(targetValue.getConfiguredTarget());
339348
}
340349
}

src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.google.devtools.build.lib.query2.query.aspectresolvers.AspectResolver;
5050
import com.google.devtools.build.lib.rules.AliasConfiguredTarget;
5151
import com.google.devtools.build.lib.server.FailureDetails.ConfigurableQuery;
52+
import com.google.devtools.build.lib.skyframe.BuildConfigurationKey;
5253
import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
5354
import com.google.devtools.build.lib.skyframe.SkyframeExecutor;
5455
import com.google.devtools.build.skyframe.SkyKey;
@@ -59,6 +60,7 @@
5960
import java.util.Collection;
6061
import java.util.Comparator;
6162
import java.util.List;
63+
import java.util.Objects;
6264
import java.util.Set;
6365
import java.util.function.Function;
6466
import java.util.function.Supplier;
@@ -339,14 +341,22 @@ public QueryTaskFuture<Void> getTargetsMatchingPattern(
339341
* null.
340342
*/
341343
@Nullable
342-
private ConfiguredTarget getConfiguredTarget(Label label, BuildConfigurationValue configuration)
343-
throws InterruptedException {
344-
return getValueFromKey(
345-
ConfiguredTargetKey.builder()
346-
.setLabel(label)
347-
.setConfiguration(configuration)
348-
.build()
349-
.toKey());
344+
private ConfiguredTarget getConfiguredTarget(
345+
Label label, @Nullable BuildConfigurationValue configuration) throws InterruptedException {
346+
BuildConfigurationKey configurationKey = configuration == null ? null : configuration.getKey();
347+
ConfiguredTarget target =
348+
getValueFromKey(
349+
ConfiguredTargetKey.builder()
350+
.setLabel(label)
351+
.setConfigurationKey(configurationKey)
352+
.build()
353+
.toKey());
354+
// The configurations might not match if the target's configuration changed due to a transition
355+
// or trimming. Filters such targets.
356+
if (target == null || !Objects.equals(configurationKey, target.getConfigurationKey())) {
357+
return null;
358+
}
359+
return target;
350360
}
351361

352362
@Override

0 commit comments

Comments
 (0)