Explicit iteration over NestedSet with toList()
This is in preparation for making NestedSet not implement Iterable.
PiperOrigin-RevId: 286170676
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java
index 7247db8..677565f 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java
@@ -39,6 +39,7 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Collection;
import java.util.LinkedHashSet;
+import java.util.List;
/**
* Utility functions for use during analysis.
@@ -73,10 +74,9 @@
// be called with Iterable<ConfiguredTarget>. Once the configured target lockdown is complete, we
// can eliminate the "extends" clauses.
/**
- * Returns the list of providers of the specified type from a set of transitive info
- * collections.
+ * Returns the list of providers of the specified type from a set of transitive info collections.
*/
- public static <C extends TransitiveInfoProvider> Iterable<C> getProviders(
+ public static <C extends TransitiveInfoProvider> List<C> getProviders(
Iterable<? extends TransitiveInfoCollection> prerequisites, Class<C> provider) {
ImmutableList.Builder<C> result = ImmutableList.builder();
for (TransitiveInfoCollection prerequisite : prerequisites) {
@@ -92,7 +92,7 @@
* Returns the list of declared providers (native and Skylark) of the specified Skylark key from a
* set of transitive info collections.
*/
- public static <T extends Info> Iterable<T> getProviders(
+ public static <T extends Info> List<T> getProviders(
Iterable<? extends TransitiveInfoCollection> prerequisites,
final NativeProvider<T> skylarkKey) {
ImmutableList.Builder<T> result = ImmutableList.builder();
@@ -109,7 +109,7 @@
* Returns the list of declared providers (native and Skylark) of the specified Skylark key from a
* set of transitive info collections.
*/
- public static <T extends Info> Iterable<T> getProviders(
+ public static <T extends Info> List<T> getProviders(
Iterable<? extends TransitiveInfoCollection> prerequisites,
final BuiltinProvider<T> skylarkKey) {
ImmutableList.Builder<T> result = ImmutableList.builder();
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java
index 9200690..662bc15 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java
@@ -203,7 +203,7 @@
toolsRunfilesBuilder.add(tool.getRunfilesSupplier());
} else {
// Map all depArtifacts to the respective label using the multimaps.
- Iterables.addAll(mapGet(tempLabelMap, label), files);
+ mapGet(tempLabelMap, label).addAll(files.toList());
}
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 4593bc5..b1b13d0 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -1070,8 +1070,8 @@
* Returns all the providers of the specified type that are listed under the specified attribute
* of this target in the BUILD file.
*/
- public <C extends TransitiveInfoProvider> Iterable<C> getPrerequisites(String attributeName,
- Mode mode, final Class<C> classType) {
+ public <C extends TransitiveInfoProvider> List<C> getPrerequisites(
+ String attributeName, Mode mode, final Class<C> classType) {
AnalysisUtils.checkProvider(classType);
return AnalysisUtils.getProviders(getPrerequisites(attributeName, mode), classType);
}
@@ -1080,7 +1080,7 @@
* Returns all the declared providers (native and Skylark) for the specified constructor under the
* specified attribute of this target in the BUILD file.
*/
- public <T extends Info> Iterable<T> getPrerequisites(
+ public <T extends Info> List<T> getPrerequisites(
String attributeName, Mode mode, final NativeProvider<T> skylarkKey) {
return AnalysisUtils.getProviders(getPrerequisites(attributeName, mode), skylarkKey);
}
@@ -1089,7 +1089,7 @@
* Returns all the declared providers (native and Skylark) for the specified constructor under the
* specified attribute of this target in the BUILD file.
*/
- public <T extends Info> Iterable<T> getPrerequisites(
+ public <T extends Info> List<T> getPrerequisites(
String attributeName, Mode mode, final BuiltinProvider<T> skylarkKey) {
return AnalysisUtils.getProviders(getPrerequisites(attributeName, mode), skylarkKey);
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
index 41c9d7d..759bf0b 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java
@@ -139,7 +139,7 @@
ConfiguredTargetKey.of(
targetAndData.getConfiguredTarget(), targetAndData.getConfiguration());
postedAfterBuilder.add(BuildEventId.targetConfigured(aliasLabel));
- for (Cause cause : getRootCauses()) {
+ for (Cause cause : getRootCauses().toList()) {
postedAfterBuilder.add(BuildEventId.fromCause(cause));
}
this.postedAfter = postedAfterBuilder.build();
@@ -211,7 +211,7 @@
ConfiguredTargetAndData ct,
NestedSet<Cause> rootCauses,
NestedSet<ArtifactsInOutputGroup> outputs) {
- Preconditions.checkArgument(!Iterables.isEmpty(rootCauses));
+ Preconditions.checkArgument(!rootCauses.isEmpty());
return new TargetCompleteEvent(
ct, rootCauses, CompletionContext.FAILED_COMPLETION_CTX, outputs, false);
}
@@ -235,14 +235,14 @@
}
/** Get the root causes of the target. May be empty. */
- public Iterable<Cause> getRootCauses() {
+ public NestedSet<Cause> getRootCauses() {
return rootCauses;
}
public Iterable<Artifact> getLegacyFilteredImportantArtifacts() {
// TODO(ulfjack): This duplicates code in ArtifactsToBuild.
NestedSetBuilder<Artifact> builder = new NestedSetBuilder<>(outputs.getOrder());
- for (ArtifactsInOutputGroup artifactsInOutputGroup : outputs) {
+ for (ArtifactsInOutputGroup artifactsInOutputGroup : outputs.toList()) {
if (artifactsInOutputGroup.areImportant()) {
builder.addTransitive(artifactsInOutputGroup.getArtifacts());
}
@@ -260,7 +260,7 @@
@Override
public Collection<BuildEventId> getChildrenEvents() {
ImmutableList.Builder<BuildEventId> childrenBuilder = ImmutableList.builder();
- for (Cause cause : getRootCauses()) {
+ for (Cause cause : getRootCauses().toList()) {
childrenBuilder.add(BuildEventId.fromCause(cause));
}
if (isTest) {
@@ -347,10 +347,10 @@
@Override
public Collection<LocalFile> referencedLocalFiles() {
ImmutableList.Builder<LocalFile> builder = ImmutableList.builder();
- for (ArtifactsInOutputGroup group : outputs) {
+ for (ArtifactsInOutputGroup group : outputs.toList()) {
if (group.areImportant()) {
completionContext.visitArtifacts(
- filterFilesets(group.getArtifacts()),
+ filterFilesets(group.getArtifacts().toList()),
new ArtifactReceiver() {
@Override
public void accept(Artifact artifact) {
@@ -368,7 +368,7 @@
}
}
if (baselineCoverageArtifacts != null) {
- for (Artifact artifact : baselineCoverageArtifacts) {
+ for (Artifact artifact : baselineCoverageArtifacts.toList()) {
builder.add(
new LocalFile(
completionContext.pathResolver().toPath(artifact), LocalFileType.COVERAGE_OUTPUT));
@@ -417,7 +417,7 @@
@Override
public ReportedArtifacts reportedArtifacts() {
ImmutableSet.Builder<NestedSet<Artifact>> builder = ImmutableSet.builder();
- for (ArtifactsInOutputGroup artifactsInGroup : outputs) {
+ for (ArtifactsInOutputGroup artifactsInGroup : outputs.toList()) {
if (artifactsInGroup.areImportant()) {
builder.add(artifactsInGroup.getArtifacts());
}
@@ -439,7 +439,7 @@
private Iterable<OutputGroup> getOutputFilesByGroup(ArtifactGroupNamer namer) {
ImmutableList.Builder<OutputGroup> groups = ImmutableList.builder();
- for (ArtifactsInOutputGroup artifactsInOutputGroup : outputs) {
+ for (ArtifactsInOutputGroup artifactsInOutputGroup : outputs.toList()) {
if (!artifactsInOutputGroup.areImportant()) {
continue;
}