aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Marcel Hlopko <hlopko@google.com>2016-11-25 09:34:15 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-11-25 12:20:28 +0000
commitf84a5f42c8fc7389c2c33fe16713024933d3eca3 (patch)
tree05b583c50ee0085eb41d104779a3b76946f1bd0b /src/main/java
parenteb06c40d10652af258bee1a0277916007eccc69a (diff)
Do not flatten nested sets in Variables.Builder.addStringSequenceVariable
-- MOS_MIGRATED_REVID=140181324
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
index a22b2e015f..4515aaaec3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
@@ -29,6 +29,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariableValue;
import com.google.devtools.build.lib.util.Pair;
@@ -971,9 +972,9 @@ public class CcToolchainFeatures implements Serializable {
@Immutable
private static final class StringSequence implements VariableValue {
- private final ImmutableList<String> values;
+ private final Iterable<String> values;
- public StringSequence(ImmutableList<String> values) {
+ public StringSequence(Iterable<String> values) {
Preconditions.checkNotNull(values, "Cannot create StringSequence from null");
this.values = values;
}
@@ -1158,8 +1159,13 @@ public class CcToolchainFeatures implements Serializable {
return this;
}
- /** Add a sequence variable that expands {@code name} to {@code values}. */
- public Builder addStringSequenceVariable(String name, Iterable<String> values) {
+ /**
+ * Add a sequence variable that expands {@code name} to {@code values}.
+ *
+ * <p>Accepts values as ImmutableSet. As ImmutableList has smaller memory footprint, we copy
+ * the values into a new list.
+ */
+ public Builder addStringSequenceVariable(String name, ImmutableSet<String> values) {
Preconditions.checkArgument(
!variablesMap.containsKey(name), "Cannot overwrite variable '%s'", name);
ImmutableList.Builder<String> builder = ImmutableList.builder();
@@ -1169,6 +1175,33 @@ public class CcToolchainFeatures implements Serializable {
}
/**
+ * Add a sequence variable that expands {@code name} to {@code values}.
+ *
+ * <p>Accepts values as NestedSet. Nested set is stored directly, not cloned, not flattened.
+ */
+ public Builder addStringSequenceVariable(String name, NestedSet<String> values) {
+ Preconditions.checkArgument(
+ !variablesMap.containsKey(name), "Cannot overwrite variable '%s'", name);
+ variablesMap.put(name, new StringSequence(values));
+ return this;
+ }
+
+ /**
+ * Add a sequence variable that expands {@code name} to {@code values}.
+ *
+ * <p>Accepts values as Iterable. The iterable is stored directly, not cloned, not iterated.
+ * Be mindful of memory consumption of the particular Iterable. Prefer ImmutableList, or
+ * be sure that the iterable always returns the same elements in the same order, without any
+ * side effects.
+ */
+ public Builder addStringSequenceVariable(String name, Iterable<String> values) {
+ Preconditions.checkArgument(
+ !variablesMap.containsKey(name), "Cannot overwrite variable '%s'", name);
+ variablesMap.put(name, new StringSequence(values));
+ return this;
+ }
+
+ /**
* Add a variable built using {@code VariableValueBuilder} api that expands {@code name} to
* the value returned by the {@code builder}.
*/