Add a copy() method for Dependency.Builder.
Part of work on toolchain transitions, #10523.
PiperOrigin-RevId: 314925260
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java b/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
index 87c650e..449a425 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
@@ -58,6 +58,10 @@
/** Sets the keys of a configuration transition. */
public Builder setTransitionKey(String key) {
+ if (key.isEmpty()) {
+ // Ignore empty keys.
+ return this;
+ }
return setTransitionKeys(ImmutableList.of(key));
}
@@ -77,6 +81,25 @@
}
return dependency;
}
+
+ // Added to enable copy, below. Should not be accessible to other classes.
+ protected abstract Label getLabel();
+
+ @Nullable
+ protected abstract BuildConfiguration getConfiguration();
+
+ protected abstract AspectCollection getAspects();
+
+ protected abstract ImmutableList<String> getTransitionKeys();
+
+ /** Returns a copy of this Builder, with the values the same. */
+ public Builder copy() {
+ return Dependency.builder()
+ .setLabel(getLabel())
+ .setConfiguration(getConfiguration())
+ .setAspects(getAspects())
+ .setTransitionKeys(getTransitionKeys());
+ }
}
/** Returns a new {@link Builder} to create {@link Dependency} instances. */