diff options
author | janakr <janakr@google.com> | 2018-03-26 09:26:53 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-26 09:28:16 -0700 |
commit | 171a7ebd9a28c4169f2c3018b9c4d740dadcf324 (patch) | |
tree | 6c97755630f7bce831ae7cc8a5fe0f0c9ee6cf1a /src/main/java/com/google/devtools/build/lib/query2 | |
parent | 8688b68d4331449f97b04a868c0d61c62eff71f2 (diff) |
Deprecate TransitiveInfoCollection#getConfiguration(), adding two new methods, TransitiveInfoCollection#getConfigurationKey() and ConfiguredTarget#getConfigurationChecksum(). These methods currently delegate to #getConfiguration(), but in the future they won't. I hope to get rid of #getConfigurationChecksum(), but I may have to fold the checksum into BuildConfigurationValue.Key or leave it as a separate field in ConfiguredTarget.
Transform a representative (random?) selection of #getConfiguration calls, to show that it's pretty much possible everywhere.
PiperOrigin-RevId: 190474978
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java | 36 |
1 files changed, 25 insertions, 11 deletions
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 547d7d107b..9daf252601 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 @@ -53,6 +53,7 @@ import com.google.devtools.build.lib.query2.engine.ThreadSafeOutputFormatterCall import com.google.devtools.build.lib.query2.engine.Uniquifier; import com.google.devtools.build.lib.query2.output.QueryOptions; import com.google.devtools.build.lib.rules.AliasConfiguredTarget; +import com.google.devtools.build.lib.skyframe.BuildConfigurationValue; import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; import com.google.devtools.build.lib.skyframe.ConfiguredTargetValue; import com.google.devtools.build.lib.skyframe.GraphBackedRecursivePackageProvider; @@ -104,8 +105,6 @@ public class ConfiguredTargetQueryEnvironment private ConfiguredTargetAccessor accessor; protected WalkableGraph graph; - private static final Function<ConfiguredTarget, SkyKey> CT_TO_SKYKEY = - target -> ConfiguredTargetValue.key(getCorrectLabel(target), target.getConfiguration()); private static final Function<SkyKey, ConfiguredTargetKey> SKYKEY_TO_CTKEY = skyKey -> (ConfiguredTargetKey) skyKey.argument(); private static final ImmutableList<TargetPatternKey> ALL_PATTERNS; @@ -408,22 +407,22 @@ public class ConfiguredTargetQueryEnvironment // host config. This is somewhat counterintuitive and subject to change in the future but seems // like the best option right now. if (settings.contains(Setting.NO_HOST_DEPS)) { - BuildConfiguration currentConfig = target.getConfiguration(); + BuildConfiguration currentConfig = getConfiguration(target); if (currentConfig != null && currentConfig.isHostConfiguration()) { deps = deps.stream() .filter( dep -> - dep.getConfiguration() != null - && dep.getConfiguration().isHostConfiguration()) + getConfiguration(dep) != null + && getConfiguration(dep).isHostConfiguration()) .collect(Collectors.toList()); } else { deps = deps.stream() .filter( dep -> - dep.getConfiguration() == null - || !dep.getConfiguration().isHostConfiguration()) + getConfiguration(dep) != null + && !getConfiguration(dep).isHostConfiguration()) .collect(Collectors.toList()); } } @@ -434,19 +433,34 @@ public class ConfiguredTargetQueryEnvironment .filter( dep -> !implicitDeps.contains( - ConfiguredTargetKey.of( - getCorrectLabel(dep), dep.getConfiguration()))) + ConfiguredTargetKey.of(getCorrectLabel(dep), getConfiguration(dep)))) .collect(Collectors.toList()); } return deps; } + @Nullable + private BuildConfiguration getConfiguration(ConfiguredTarget target) { + try { + return target.getConfigurationKey() == null + ? null + : ((BuildConfigurationValue) graph.getValue(target.getConfigurationKey())) + .getConfiguration(); + } catch (InterruptedException e) { + throw new IllegalStateException("Unexpected interruption during configured target query"); + } + } + + private ConfiguredTargetKey getSkyKey(ConfiguredTarget target) { + return ConfiguredTargetKey.of(target, getConfiguration(target)); + } + @Override public ThreadSafeMutableSet<ConfiguredTarget> getFwdDeps(Iterable<ConfiguredTarget> targets) throws InterruptedException { Map<SkyKey, ConfiguredTarget> targetsByKey = new HashMap<>(Iterables.size(targets)); for (ConfiguredTarget target : targets) { - targetsByKey.put(CT_TO_SKYKEY.apply(target), target); + targetsByKey.put(getSkyKey(target), target); } Map<SkyKey, Collection<ConfiguredTarget>> directDeps = targetifyValues(graph.getDirectDeps(targetsByKey.keySet())); @@ -489,7 +503,7 @@ public class ConfiguredTargetQueryEnvironment throws InterruptedException { Map<SkyKey, ConfiguredTarget> targetsByKey = new HashMap<>(Iterables.size(targets)); for (ConfiguredTarget target : targets) { - targetsByKey.put(CT_TO_SKYKEY.apply(target), target); + targetsByKey.put(getSkyKey(target), target); } Map<SkyKey, Collection<ConfiguredTarget>> reverseDepsByKey = targetifyValues(graph.getReverseDeps(targetsByKey.keySet())); |