BuildView; move the methods around.
Production API at the top, then ide_build_info, and testing at the bottom.
This is separate from the refactoring to make both easier to review.
--
MOS_MIGRATED_REVID=104095498
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index b9e7afe..113cd18 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -265,82 +265,6 @@
return skyframeExecutor.getLastWorkspaceStatusActionForTesting();
}
- @VisibleForTesting
- public Iterable<ConfiguredTarget> getDirectPrerequisitesForTesting(
- EventHandler eventHandler, ConfiguredTarget ct, BuildConfigurationCollection configurations)
- throws InterruptedException {
- return skyframeExecutor.getConfiguredTargets(
- eventHandler, ct.getConfiguration(),
- getDirectPrerequisiteDependenciesForTesting(eventHandler, ct, null, configurations), false);
- }
-
- @VisibleForTesting
- public Iterable<Dependency> getDirectPrerequisiteDependenciesForTesting(
- EventHandler eventHandler, ConfiguredTarget ct,
- @Nullable final LoadingCache<Label, Target> targetCache,
- BuildConfigurationCollection configurations) throws InterruptedException {
- if (!(ct.getTarget() instanceof Rule)) {
- return ImmutableList.of();
- }
-
- class SilentDependencyResolver extends DependencyResolver {
- @Override
- protected void invalidVisibilityReferenceHook(TargetAndConfiguration node, Label label) {
- // The error must have been reported already during analysis.
- }
-
- @Override
- protected void invalidPackageGroupReferenceHook(TargetAndConfiguration node, Label label) {
- // The error must have been reported already during analysis.
- }
-
- @Override
- protected Target getTarget(Label label) throws NoSuchThingException {
- if (targetCache == null) {
- return packageManager.getLoadedTarget(label);
- }
-
- try {
- return targetCache.get(label);
- } catch (ExecutionException e) {
- // All lookups should succeed because we should not be looking up any targets in error.
- throw new IllegalStateException(e);
- }
- }
- }
-
- DependencyResolver dependencyResolver = new SilentDependencyResolver();
- TargetAndConfiguration ctgNode =
- new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
- return dependencyResolver.dependentNodes(ctgNode, configurations.getHostConfiguration(),
- getConfigurableAttributeKeysForTesting(eventHandler, ctgNode));
- }
-
- /**
- * Returns ConfigMatchingProvider instances corresponding to the configurable attribute keys
- * present in this rule's attributes.
- */
- private Set<ConfigMatchingProvider> getConfigurableAttributeKeysForTesting(
- EventHandler eventHandler, TargetAndConfiguration ctg) {
- if (!(ctg.getTarget() instanceof Rule)) {
- return ImmutableSet.of();
- }
- Rule rule = (Rule) ctg.getTarget();
- ImmutableSet.Builder<ConfigMatchingProvider> keys = ImmutableSet.builder();
- RawAttributeMapper mapper = RawAttributeMapper.of(rule);
- for (Attribute attribute : rule.getAttributes()) {
- for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
- if (BuildType.Selector.isReservedLabel(label)) {
- continue;
- }
- ConfiguredTarget ct = getConfiguredTargetForTesting(
- eventHandler, label, ctg.getConfiguration());
- keys.add(Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class)));
- }
- }
- return keys.build();
- }
-
public TransitiveInfoCollection getGeneratingRule(OutputFileConfiguredTarget target) {
return target.getGeneratingRule();
}
@@ -756,77 +680,6 @@
return ImmutableList.copyOf(nodes);
}
- // For ide_build_info
- public ConfiguredTarget getConfiguredTargetForIdeInfo(
- EventHandler eventHandler, Label label, BuildConfiguration configuration) {
- return Iterables.getFirst(
- skyframeExecutor.getConfiguredTargets(
- eventHandler,
- configuration,
- ImmutableList.of(new Dependency(label, configuration)),
- true),
- null);
- }
-
- public ConfiguredTarget getConfiguredTargetForIdeInfo(
- EventHandler eventHandler, Target target, BuildConfiguration config) {
- return getConfiguredTargetForIdeInfo(eventHandler, target.getLabel(), config);
- }
-
- public Iterable<ConfiguredTarget> getDirectPrerequisitesForIdeInfo(
- EventHandler eventHandler, ConfiguredTarget ct, BuildConfigurationCollection configurations)
- throws InterruptedException {
- return getDirectPrerequisitesForTesting(eventHandler, ct, configurations);
- }
-
- public Iterable<Dependency> getDirectPrerequisiteDependenciesForIdeInfo(
- EventHandler eventHandler, ConfiguredTarget ct,
- @Nullable final LoadingCache<Label, Target> targetCache,
- BuildConfigurationCollection configurations) throws InterruptedException {
- return getDirectPrerequisiteDependenciesForTesting(
- eventHandler, ct, targetCache, configurations);
- }
-
- private ListMultimap<Attribute, ConfiguredTarget> getPrerequisiteMapForTesting(
- EventHandler eventHandler, ConfiguredTarget target,
- BuildConfigurationCollection configurations) throws InterruptedException {
- DependencyResolver resolver = new DependencyResolver() {
- @Override
- protected void invalidVisibilityReferenceHook(TargetAndConfiguration node, Label label) {
- throw new RuntimeException("bad visibility on " + label + " during testing unexpected");
- }
-
- @Override
- protected void invalidPackageGroupReferenceHook(TargetAndConfiguration node, Label label) {
- throw new RuntimeException("bad package group on " + label + " during testing unexpected");
- }
-
- @Override
- protected Target getTarget(Label label) throws NoSuchThingException {
- return packageManager.getLoadedTarget(label);
- }
- };
- TargetAndConfiguration ctNode = new TargetAndConfiguration(target);
- ListMultimap<Attribute, Dependency> depNodeNames;
- try {
- depNodeNames = resolver.dependentNodeMap(ctNode, configurations.getHostConfiguration(),
- /*aspect=*/null, AspectParameters.EMPTY,
- getConfigurableAttributeKeysForTesting(eventHandler, ctNode));
- } catch (EvalException e) {
- throw new IllegalStateException(e);
- }
-
- ImmutableMap<Dependency, ConfiguredTarget> cts = skyframeExecutor.getConfiguredTargetMap(
- eventHandler, ctNode.getConfiguration(), ImmutableSet.copyOf(depNodeNames.values()), false);
-
- ImmutableListMultimap.Builder<Attribute, ConfiguredTarget> builder =
- ImmutableListMultimap.builder();
- for (Map.Entry<Attribute, Dependency> entry : depNodeNames.entries()) {
- builder.put(entry.getKey(), cts.get(entry.getValue()));
- }
- return builder.build();
- }
-
/**
* Sets the possible artifact roots in the artifact factory. This allows the factory to resolve
* paths with unknown roots to artifacts.
@@ -862,6 +715,175 @@
}
/**
+ * Tests and clears the current thread's pending "interrupted" status, and
+ * throws InterruptedException iff it was set.
+ */
+ protected final void pollInterruptedStatus() throws InterruptedException {
+ if (Thread.interrupted()) {
+ throw new InterruptedException();
+ }
+ }
+
+ /**
+ * Drops the analysis cache. If building with Skyframe, targets in {@code topLevelTargets} may
+ * remain in the cache for use during the execution phase.
+ *
+ * @see BuildView.Options#discardAnalysisCache
+ */
+ public void clearAnalysisCache(Collection<ConfiguredTarget> topLevelTargets) {
+ skyframeBuildView.clearAnalysisCache(topLevelTargets);
+ }
+
+ // For ide_build_info
+ public ConfiguredTarget getConfiguredTargetForIdeInfo(
+ EventHandler eventHandler, Label label, BuildConfiguration configuration) {
+ return Iterables.getFirst(
+ skyframeExecutor.getConfiguredTargets(
+ eventHandler,
+ configuration,
+ ImmutableList.of(new Dependency(label, configuration)),
+ true),
+ null);
+ }
+
+ public ConfiguredTarget getConfiguredTargetForIdeInfo(
+ EventHandler eventHandler, Target target, BuildConfiguration config) {
+ return getConfiguredTargetForIdeInfo(eventHandler, target.getLabel(), config);
+ }
+
+ public Iterable<ConfiguredTarget> getDirectPrerequisitesForIdeInfo(
+ EventHandler eventHandler, ConfiguredTarget ct, BuildConfigurationCollection configurations)
+ throws InterruptedException {
+ return getDirectPrerequisitesForTesting(eventHandler, ct, configurations);
+ }
+
+ public Iterable<Dependency> getDirectPrerequisiteDependenciesForIdeInfo(
+ EventHandler eventHandler, ConfiguredTarget ct,
+ @Nullable final LoadingCache<Label, Target> targetCache,
+ BuildConfigurationCollection configurations) throws InterruptedException {
+ return getDirectPrerequisiteDependenciesForTesting(
+ eventHandler, ct, targetCache, configurations);
+ }
+
+ // For testing
+ @VisibleForTesting
+ public Iterable<ConfiguredTarget> getDirectPrerequisitesForTesting(
+ EventHandler eventHandler, ConfiguredTarget ct, BuildConfigurationCollection configurations)
+ throws InterruptedException {
+ return skyframeExecutor.getConfiguredTargets(
+ eventHandler, ct.getConfiguration(),
+ getDirectPrerequisiteDependenciesForTesting(eventHandler, ct, null, configurations), false);
+ }
+
+ @VisibleForTesting
+ public Iterable<Dependency> getDirectPrerequisiteDependenciesForTesting(
+ EventHandler eventHandler, ConfiguredTarget ct,
+ @Nullable final LoadingCache<Label, Target> targetCache,
+ BuildConfigurationCollection configurations) throws InterruptedException {
+ if (!(ct.getTarget() instanceof Rule)) {
+ return ImmutableList.of();
+ }
+
+ class SilentDependencyResolver extends DependencyResolver {
+ @Override
+ protected void invalidVisibilityReferenceHook(TargetAndConfiguration node, Label label) {
+ // The error must have been reported already during analysis.
+ }
+
+ @Override
+ protected void invalidPackageGroupReferenceHook(TargetAndConfiguration node, Label label) {
+ // The error must have been reported already during analysis.
+ }
+
+ @Override
+ protected Target getTarget(Label label) throws NoSuchThingException {
+ if (targetCache == null) {
+ return packageManager.getLoadedTarget(label);
+ }
+
+ try {
+ return targetCache.get(label);
+ } catch (ExecutionException e) {
+ // All lookups should succeed because we should not be looking up any targets in error.
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ DependencyResolver dependencyResolver = new SilentDependencyResolver();
+ TargetAndConfiguration ctgNode =
+ new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
+ return dependencyResolver.dependentNodes(ctgNode, configurations.getHostConfiguration(),
+ getConfigurableAttributeKeysForTesting(eventHandler, ctgNode));
+ }
+
+ /**
+ * Returns ConfigMatchingProvider instances corresponding to the configurable attribute keys
+ * present in this rule's attributes.
+ */
+ private Set<ConfigMatchingProvider> getConfigurableAttributeKeysForTesting(
+ EventHandler eventHandler, TargetAndConfiguration ctg) {
+ if (!(ctg.getTarget() instanceof Rule)) {
+ return ImmutableSet.of();
+ }
+ Rule rule = (Rule) ctg.getTarget();
+ ImmutableSet.Builder<ConfigMatchingProvider> keys = ImmutableSet.builder();
+ RawAttributeMapper mapper = RawAttributeMapper.of(rule);
+ for (Attribute attribute : rule.getAttributes()) {
+ for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
+ if (BuildType.Selector.isReservedLabel(label)) {
+ continue;
+ }
+ ConfiguredTarget ct = getConfiguredTargetForTesting(
+ eventHandler, label, ctg.getConfiguration());
+ keys.add(Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class)));
+ }
+ }
+ return keys.build();
+ }
+
+ private ListMultimap<Attribute, ConfiguredTarget> getPrerequisiteMapForTesting(
+ EventHandler eventHandler, ConfiguredTarget target,
+ BuildConfigurationCollection configurations) throws InterruptedException {
+ DependencyResolver resolver = new DependencyResolver() {
+ @Override
+ protected void invalidVisibilityReferenceHook(TargetAndConfiguration node, Label label) {
+ throw new RuntimeException("bad visibility on " + label + " during testing unexpected");
+ }
+
+ @Override
+ protected void invalidPackageGroupReferenceHook(TargetAndConfiguration node, Label label) {
+ throw new RuntimeException("bad package group on " + label + " during testing unexpected");
+ }
+
+ @Override
+ protected Target getTarget(Label label) throws NoSuchThingException {
+ return packageManager.getLoadedTarget(label);
+ }
+ };
+ TargetAndConfiguration ctNode = new TargetAndConfiguration(target);
+ ListMultimap<Attribute, Dependency> depNodeNames;
+ try {
+ depNodeNames = resolver.dependentNodeMap(ctNode, configurations.getHostConfiguration(),
+ /*aspect=*/null, AspectParameters.EMPTY,
+ getConfigurableAttributeKeysForTesting(eventHandler, ctNode));
+ } catch (EvalException e) {
+ throw new IllegalStateException(e);
+ }
+
+ ImmutableMap<Dependency, ConfiguredTarget> cts = skyframeExecutor.getConfiguredTargetMap(
+ eventHandler,
+ ctNode.getConfiguration(), ImmutableSet.copyOf(depNodeNames.values()), false);
+
+ ImmutableListMultimap.Builder<Attribute, ConfiguredTarget> builder =
+ ImmutableListMultimap.builder();
+ for (Map.Entry<Attribute, Dependency> entry : depNodeNames.entries()) {
+ builder.put(entry.getKey(), cts.get(entry.getValue()));
+ }
+ return builder.build();
+ }
+
+ /**
* Returns a configured target for the specified target and configuration. Returns {@code null}
* if something goes wrong.
*/
@@ -925,24 +947,4 @@
}
return null;
}
-
- /**
- * Tests and clears the current thread's pending "interrupted" status, and
- * throws InterruptedException iff it was set.
- */
- protected final void pollInterruptedStatus() throws InterruptedException {
- if (Thread.interrupted()) {
- throw new InterruptedException();
- }
- }
-
- /**
- * Drops the analysis cache. If building with Skyframe, targets in {@code topLevelTargets} may
- * remain in the cache for use during the execution phase.
- *
- * @see BuildView.Options#discardAnalysisCache
- */
- public void clearAnalysisCache(Collection<ConfiguredTarget> topLevelTargets) {
- skyframeBuildView.clearAnalysisCache(topLevelTargets);
- }
}