Wrap runtime jars and proto sources going into runfiles in a stable order nested set.
This saves memory, as the nested set would otherwise become flattened. Assuming the jars don't have duplicates files with the same root relative path in the same runfiles tree this won't make any semantic difference.
PiperOrigin-RevId: 169234428
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
index 2e50c12..65009a3 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
@@ -828,9 +828,9 @@
return this;
}
-
/**
* @deprecated Use {@link #addTransitiveArtifacts} instead, to prevent increased memory use.
+ * <p>See alse {@link Builder#addTransitiveArtifactsWrappedInStableOrder}
*/
@Deprecated
public Builder addArtifacts(NestedSet<Artifact> artifacts) {
@@ -850,6 +850,20 @@
}
/**
+ * Adds a nested set to the internal collection.
+ *
+ * <p>The nested set will become wrapped in stable order. Only use this when the set of
+ * artifacts will not have conflicting root relative paths, or the wrong artifact will end up in
+ * the runfiles tree.
+ */
+ public Builder addTransitiveArtifactsWrappedInStableOrder(NestedSet<Artifact> artifacts) {
+ NestedSet<Artifact> wrappedArtifacts =
+ NestedSetBuilder.<Artifact>stableOrder().addTransitive(artifacts).build();
+ artifactsBuilder.addTransitive(wrappedArtifacts);
+ return this;
+ }
+
+ /**
* Adds a symlink.
*/
public Builder addSymlink(PathFragment link, Artifact target) {