aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java862
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/RobolectricResourceSymbolsActionBuilder.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/OneVersionCheckActionBuilder.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java23
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java56
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java757
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java101
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java5
28 files changed, 1410 insertions, 570 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java
index 02998a11c4..20680b621a 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java
@@ -17,10 +17,10 @@ package com.google.devtools.build.lib.analysis.actions;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
@@ -33,7 +33,10 @@ import com.google.devtools.build.lib.util.LazyString;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.errorprone.annotations.CompileTimeConstant;
+import com.google.errorprone.annotations.FormatMethod;
+import com.google.errorprone.annotations.FormatString;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -95,20 +98,24 @@ public final class CustomCommandLine extends CommandLine {
/**
* An ArgvFragment that expands a collection of objects in a user-specified way.
*
- * <p>To construct one, use {@link VectorArg#of} with your collection of objects, and configure
- * the returned object depending on how you want the expansion to take place. Finally, pass it to
- * {@link CustomCommandLine.Builder#addExecPaths(VectorArg.Builder}.
+ * <p>Used to cut down on code duplication between the many overloads of add*.
*/
- public static final class VectorArg implements ArgvFragment {
+ private static final class VectorArg implements ArgvFragment {
private static Interner<VectorArg> interner = BlazeInterners.newStrongInterner();
+ private final boolean isNestedSet;
private final boolean hasMapEach;
private final boolean hasFormatEach;
private final boolean hasBeforeEach;
private final boolean hasJoinWith;
private VectorArg(
- boolean hasMapEach, boolean hasFormatEach, boolean hasBeforeEach, boolean hasJoinWith) {
+ boolean isNestedSet,
+ boolean hasMapEach,
+ boolean hasFormatEach,
+ boolean hasBeforeEach,
+ boolean hasJoinWith) {
+ this.isNestedSet = isNestedSet;
this.hasMapEach = hasMapEach;
this.hasFormatEach = hasFormatEach;
this.hasBeforeEach = hasBeforeEach;
@@ -118,13 +125,20 @@ public final class CustomCommandLine extends CommandLine {
private static void push(List<Object> arguments, Builder<?> argv) {
VectorArg vectorArg =
new VectorArg(
+ argv.isNestedSet,
argv.mapFn != null,
argv.formatEach != null,
argv.beforeEach != null,
argv.joinWith != null);
vectorArg = interner.intern(vectorArg);
arguments.add(vectorArg);
- arguments.add(argv.values);
+ if (vectorArg.isNestedSet) {
+ arguments.add(argv.values);
+ } else {
+ // Simply expand any ordinary collection into the argv
+ arguments.add(argv.count);
+ Iterables.addAll(arguments, argv.values);
+ }
if (vectorArg.hasMapEach) {
arguments.add(argv.mapFn);
}
@@ -142,9 +156,19 @@ public final class CustomCommandLine extends CommandLine {
@SuppressWarnings("unchecked")
@Override
public int eval(List<Object> arguments, int argi, ImmutableList.Builder<String> builder) {
- Iterable<Object> values = (Iterable<Object>) arguments.get(argi++);
- List<Object> mutatedValues = Lists.newArrayList(values);
- int count = mutatedValues.size();
+ final List<Object> mutatedValues;
+ final int count;
+ if (isNestedSet) {
+ Iterable<Object> values = (Iterable<Object>) arguments.get(argi++);
+ mutatedValues = Lists.newArrayList(values);
+ count = mutatedValues.size();
+ } else {
+ count = (Integer) arguments.get(argi++);
+ mutatedValues = new ArrayList<>(count);
+ for (int i = 0; i < count; ++i) {
+ mutatedValues.add(arguments.get(argi++));
+ }
+ }
if (hasMapEach) {
Function<Object, String> mapFn = (Function<Object, String>) arguments.get(argi++);
for (int i = 0; i < count; ++i) {
@@ -177,11 +201,11 @@ public final class CustomCommandLine extends CommandLine {
return argi;
}
- public static <T> Builder<T> of(@Nullable ImmutableCollection<T> values) {
+ static <T> Builder<T> of(@Nullable Collection<T> values) {
return new Builder<>(values);
}
- public static <T> Builder<T> of(@Nullable NestedSet<T> values) {
+ static <T> Builder<T> of(@Nullable NestedSet<T> values) {
return new Builder<>(values);
}
@@ -189,22 +213,27 @@ public final class CustomCommandLine extends CommandLine {
public static class Builder<T> {
@Nullable private final Iterable<T> values;
private final boolean isEmpty;
+ private final boolean isNestedSet;
+ private final int count;
private String formatEach;
private String beforeEach;
private Function<T, String> mapFn;
private String joinWith;
- private Builder(@Nullable ImmutableCollection<T> values) {
- this(values, values == null || values.isEmpty());
+ private Builder(@Nullable Collection<T> values) {
+ this(values, values == null || values.isEmpty(), false, values != null ? values.size() : 0);
}
private Builder(@Nullable NestedSet<T> values) {
- this(values, values == null || values.isEmpty());
+ this(values, values == null || values.isEmpty(), true, -1);
}
- private Builder(@Nullable Iterable<T> values, boolean isEmpty) {
+ private Builder(
+ @Nullable Iterable<T> values, boolean isEmpty, boolean isNestedSet, int count) {
this.values = values;
this.isEmpty = isEmpty;
+ this.isNestedSet = isNestedSet;
+ this.count = count;
}
/** Each argument is formatted via {@link String#format}. */
@@ -232,23 +261,12 @@ public final class CustomCommandLine extends CommandLine {
}
/** Once all arguments have been evaluated, they are joined with this delimiter */
- public Builder<T> joinWith(@CompileTimeConstant String delimiter) {
+ public Builder<T> joinWith(String delimiter) {
Preconditions.checkNotNull(delimiter);
this.joinWith = delimiter;
return this;
}
- /**
- * Once all arguments have been evaluated, they are joined with this delimiter
- *
- * <p>Prefer use of {@link Builder#joinWith} to this method, as it will be more memory
- * efficient.
- */
- public Builder<T> joinWithDynamicString(String delimiter) {
- Preconditions.checkNotNull(delimiter);
- this.joinWith = delimiter;
- return this;
- }
}
@Override
@@ -260,7 +278,8 @@ public final class CustomCommandLine extends CommandLine {
return false;
}
VectorArg vectorArg = (VectorArg) o;
- return hasMapEach == vectorArg.hasMapEach
+ return isNestedSet == vectorArg.isNestedSet
+ && hasMapEach == vectorArg.hasMapEach
&& hasFormatEach == vectorArg.hasFormatEach
&& hasBeforeEach == vectorArg.hasBeforeEach
&& hasJoinWith == vectorArg.hasJoinWith;
@@ -268,7 +287,7 @@ public final class CustomCommandLine extends CommandLine {
@Override
public int hashCode() {
- return Objects.hashCode(hasMapEach, hasFormatEach, hasBeforeEach, hasJoinWith);
+ return Objects.hashCode(isNestedSet, hasMapEach, hasFormatEach, hasBeforeEach, hasJoinWith);
}
}
@@ -419,18 +438,19 @@ public final class CustomCommandLine extends CommandLine {
/**
* A Builder class for CustomCommandLine with the appropriate methods.
*
- * <p>{@link Iterable} instances passed to {@code add*} methods will be stored internally as
- * collections that are known to be immutable copies. This means that any {@link Iterable} that is
- * not a {@link NestedSet} or {@link ImmutableList} may be copied.
+ * <p>{@link Collection} instances passed to {@code add*} methods will copied internally. If you
+ * have a {@link NestedSet}, these should never be flattened to a collection before being passed
+ * to the command line.
*
- * <p>{@code addFormatEach*} methods take an {@link Iterable} but use these as arguments to
- * {@link String#format(String, Object...)} with a certain constant format string. For instance,
- * if {@code format} is {@code "-I%s"}, then the final arguments may be
- * {@code -Ifoo -Ibar -Ibaz}
+ * <p>{@code addFormatEach*} methods take a {@link Collection} or {@link NestedSet} but use these
+ * as arguments to {@link String#format(String, Object...)} with a certain constant format string.
+ * For instance, if {@code format} is {@code "-I%s"}, then the final arguments may be {@code -Ifoo
+ * -Ibar -Ibaz}
*
- * <p>{@code addBeforeEach*} methods take an {@link Iterable} but insert a certain {@link String}
- * once before each element in the string, meaning the total number of elements added is twice the
- * length of the {@link Iterable}. For instance: {@code -f foo -f bar -f baz}
+ * <p>{@code addBeforeEach*} methods take a {@link Collection} or {@link NestedSet } but insert a
+ * certain {@link String} once before each element in the string, meaning the total number of
+ * elements added is twice the length of the {@link Iterable}. For instance: {@code -f foo -f bar
+ * -f baz}
*/
public static final class Builder {
// In order to avoid unnecessary wrapping, we keep raw objects here, but these objects are
@@ -438,6 +458,10 @@ public final class CustomCommandLine extends CommandLine {
// toString() results.
private final List<Object> arguments = new ArrayList<>();
+ public boolean isEmpty() {
+ return arguments.isEmpty();
+ }
+
/**
* Adds a constant-value string.
*
@@ -502,13 +526,6 @@ public final class CustomCommandLine extends CommandLine {
return addObjectInternal(value);
}
- private Builder addObjectInternal(@Nullable Object value) {
- if (value != null) {
- arguments.add(value);
- }
- return this;
- }
-
/**
* Adds a string argument to the command line.
*
@@ -559,29 +576,56 @@ public final class CustomCommandLine extends CommandLine {
return addObjectInternal(arg, value);
}
- /** Adds the arg and the passed value if the value is non-null. */
- private Builder addObjectInternal(@CompileTimeConstant String arg, @Nullable Object value) {
- Preconditions.checkNotNull(arg);
- if (value != null) {
- arguments.add(arg);
- addObjectInternal(value);
- }
+ /** Calls {@link String#format} at command line expansion time. */
+ @FormatMethod
+ public Builder addFormatted(@FormatString String formatStr, Object... args) {
+ Preconditions.checkNotNull(formatStr);
+ FormatArg.push(arguments, formatStr, args);
return this;
}
+ /** Concatenates the passed prefix string and the string. */
+ public Builder addPrefixed(@CompileTimeConstant String prefix, @Nullable String arg) {
+ return addPrefixedInternal(prefix, arg);
+ }
+
+ /** Concatenates the passed prefix string and the label using {@link Label#getCanonicalForm}. */
+ public Builder addPrefixedLabel(@CompileTimeConstant String prefix, @Nullable Label arg) {
+ return addPrefixedInternal(prefix, arg);
+ }
+
+ /** Concatenates the passed prefix string and the path. */
+ public Builder addPrefixedPath(@CompileTimeConstant String prefix, @Nullable PathFragment arg) {
+ return addPrefixedInternal(prefix, arg);
+ }
+
+ /** Concatenates the passed prefix string and the artifact's exec path. */
+ public Builder addPrefixedExecPath(@CompileTimeConstant String prefix, @Nullable Artifact arg) {
+ return addPrefixedInternal(prefix, arg);
+ }
+
+ /**
+ * Concatenates the passed prefix string and the object's string representation.
+ *
+ * <p>Prefer {@link Builder#addPrefixed}, as it will be more memory efficient.
+ */
+ Builder addWithDynamicPrefix(String prefix, @Nullable Object arg) {
+ return addPrefixedInternal(prefix, arg);
+ }
+
/**
* Adds the passed strings to the command line.
*
* <p>If you are converting long lists or nested sets of a different type to string lists,
- * please try to use {@link Builder#addExecPaths(VectorArg.Builder)} instead of this method.
+ * please try to use a different method that supports what you are trying to do directly.
*/
- public Builder add(@Nullable ImmutableCollection<String> values) {
- return addImmutableCollectionInternal(values);
+ public Builder addAll(@Nullable Collection<String> values) {
+ return addCollectionInternal(values);
}
/** Adds the passed paths to the command line. */
- public Builder addPaths(@Nullable ImmutableCollection<PathFragment> values) {
- return addImmutableCollectionInternal(values);
+ public Builder addPaths(@Nullable Collection<PathFragment> values) {
+ return addCollectionInternal(values);
}
/**
@@ -591,19 +635,22 @@ public final class CustomCommandLine extends CommandLine {
* out how to avoid flattening the set and use {@link
* Builder#addExecPaths(NestedSet<Artifact>)}.
*/
- public Builder addExecPaths(@Nullable ImmutableCollection<Artifact> values) {
- return addImmutableCollectionInternal(values);
+ public Builder addExecPaths(@Nullable Collection<Artifact> values) {
+ return addCollectionInternal(values);
}
- private Builder addImmutableCollectionInternal(@Nullable ImmutableCollection<?> values) {
- if (values != null) {
- arguments.add(values);
- }
- return this;
+ /** Adds the passed mapped values to the command line. */
+ public <T> Builder addAll(@Nullable Collection<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).mapEach(mapFn));
}
- /** Adds the passed strings to the command line. */
- public Builder add(@Nullable NestedSet<String> values) {
+ /**
+ * Adds the passed strings to the command line.
+ *
+ * <p>If you are converting long lists or nested sets of a different type to string lists,
+ * please try to use a different method that supports what you are trying to do directly.
+ */
+ public Builder addAll(@Nullable NestedSet<String> values) {
return addNestedSetInternal(values);
}
@@ -617,40 +664,9 @@ public final class CustomCommandLine extends CommandLine {
return addNestedSetInternal(values);
}
- private Builder addNestedSetInternal(@Nullable NestedSet<?> values) {
- if (values != null) {
- arguments.add(values);
- }
- return this;
- }
-
- /** Calls {@link String#format} at command line expansion time. */
- public Builder addFormatted(@CompileTimeConstant String formatStr, Object... args) {
- Preconditions.checkNotNull(formatStr);
- FormatArg.push(arguments, formatStr, args);
- return this;
- }
-
- /** Cancatenates the passed prefix string and the object's string representation. */
- public Builder addWithPrefix(@CompileTimeConstant String prefix, @Nullable Object arg) {
- Preconditions.checkNotNull(prefix);
- if (arg != null) {
- PrefixArg.push(arguments, prefix, arg);
- }
- return this;
- }
-
- /**
- * Cancatenates the passed prefix string and the object's string representation.
- *
- * <p>Prefer {@link Builder#addWithPrefix}, as it will be more memory efficient.
- */
- public Builder addWithDynamicPrefix(String prefix, @Nullable Object arg) {
- Preconditions.checkNotNull(prefix);
- if (arg != null) {
- PrefixArg.push(arguments, prefix, arg);
- }
- return this;
+ /** Adds the passed mapped values to the command line. */
+ public <T> Builder addAll(@Nullable NestedSet<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).mapEach(mapFn));
}
/**
@@ -658,9 +674,8 @@ public final class CustomCommandLine extends CommandLine {
*
* <p>If values is empty, the arg isn't added.
*/
- public Builder add(
- @CompileTimeConstant String arg, @Nullable ImmutableCollection<String> values) {
- return addImmutableCollectionInternal(arg, values);
+ public Builder addAll(@CompileTimeConstant String arg, @Nullable Collection<String> values) {
+ return addCollectionInternal(arg, values);
}
/**
@@ -669,8 +684,8 @@ public final class CustomCommandLine extends CommandLine {
* <p>If values is empty, the arg isn't added.
*/
public Builder addPaths(
- @CompileTimeConstant String arg, @Nullable ImmutableCollection<PathFragment> values) {
- return addImmutableCollectionInternal(arg, values);
+ @CompileTimeConstant String arg, @Nullable Collection<PathFragment> values) {
+ return addCollectionInternal(arg, values);
}
/**
@@ -683,18 +698,20 @@ public final class CustomCommandLine extends CommandLine {
* <p>If values is empty, the arg isn't added.
*/
public Builder addExecPaths(
- @CompileTimeConstant String arg, @Nullable ImmutableCollection<Artifact> values) {
- return addImmutableCollectionInternal(arg, values);
+ @CompileTimeConstant String arg, @Nullable Collection<Artifact> values) {
+ return addCollectionInternal(arg, values);
}
- private Builder addImmutableCollectionInternal(
- @CompileTimeConstant String arg, @Nullable ImmutableCollection<?> values) {
- Preconditions.checkNotNull(arg);
- if (values != null && !values.isEmpty()) {
- arguments.add(arg);
- addImmutableCollectionInternal(values);
- }
- return this;
+ /**
+ * Adds the arg followed by the passed mapped values.
+ *
+ * <p>If values is empty, the arg isn't added.
+ */
+ public <T> Builder addAll(
+ @CompileTimeConstant String arg,
+ @Nullable Collection<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(arg, VectorArg.of(values).mapEach(mapFn));
}
/**
@@ -702,7 +719,7 @@ public final class CustomCommandLine extends CommandLine {
*
* <p>If values is empty, the arg isn't added.
*/
- public Builder add(@CompileTimeConstant String arg, @Nullable NestedSet<String> values) {
+ public Builder addAll(@CompileTimeConstant String arg, @Nullable NestedSet<String> values) {
return addNestedSetInternal(arg, values);
}
@@ -726,93 +743,508 @@ public final class CustomCommandLine extends CommandLine {
return addNestedSetInternal(arg, values);
}
- private Builder addNestedSetInternal(
- @CompileTimeConstant String arg, @Nullable NestedSet<?> values) {
- Preconditions.checkNotNull(arg);
- if (values != null && !values.isEmpty()) {
- arguments.add(arg);
- addNestedSetInternal(values);
- }
- return this;
+ /**
+ * Adds the arg followed by the mapped values.
+ *
+ * <p>If values is empty, the arg isn't added.
+ */
+ public <T> Builder addAll(
+ @CompileTimeConstant String arg, @Nullable NestedSet<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(arg, VectorArg.of(values).mapEach(mapFn));
+ }
+
+ /** Adds the values joined with the supplied string. */
+ public Builder addJoined(String delimiter, Collection<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the path strings joined with the supplied string. */
+ public Builder addJoinedPaths(String delimiter, Collection<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the exec path strings joined with the supplied string. */
+ public Builder addJoinedExecPaths(String delimiter, Collection<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the mapped values joined with the supplied string. */
+ public <T> Builder addJoined(
+ String delimiter, Collection<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter).mapEach(mapFn));
+ }
+
+ /** Adds the values joined with the supplied string. */
+ public Builder addJoined(String delimiter, NestedSet<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the path strings joined with the supplied string. */
+ public Builder addJoinedPaths(String delimiter, NestedSet<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the exec path strings joined with the supplied string. */
+ public Builder addJoinedExecPaths(String delimiter, NestedSet<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the mapped values joined with the supplied string. */
+ public <T> Builder addJoined(String delimiter, NestedSet<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter).mapEach(mapFn));
+ }
+
+ /** Adds the values joined with the supplied string. */
+ public Builder addJoined(
+ @CompileTimeConstant String arg, String delimiter, Collection<String> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the path strings joined with the supplied string. */
+ public Builder addJoinedPaths(
+ @CompileTimeConstant String arg, String delimiter, Collection<PathFragment> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the exec path strings joined with the supplied string. */
+ public Builder addJoinedExecPaths(
+ @CompileTimeConstant String arg, String delimiter, Collection<Artifact> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the mapped values joined with the supplied string. */
+ public <T> Builder addJoined(
+ @CompileTimeConstant String arg,
+ String delimiter,
+ Collection<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter).mapEach(mapFn));
+ }
+
+ /** Adds the values joined with the supplied string. */
+ public Builder addJoined(
+ @CompileTimeConstant String arg, String delimiter, NestedSet<String> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the path strings joined with the supplied string. */
+ public Builder addJoinedPaths(
+ @CompileTimeConstant String arg, String delimiter, NestedSet<PathFragment> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the exec path strings joined with the supplied string. */
+ public Builder addJoinedExecPaths(
+ @CompileTimeConstant String arg, String delimiter, NestedSet<Artifact> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter));
+ }
+
+ /** Adds the mapped values joined with the supplied string. */
+ public <T> Builder addJoined(
+ @CompileTimeConstant String arg,
+ String delimiter,
+ NestedSet<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter).mapEach(mapFn));
+ }
+
+ /** Adds the values with each value formatted by the supplied format string. */
+ public Builder addFormatEach(@CompileTimeConstant String formatStr, Collection<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachPath(
+ @CompileTimeConstant String formatStr, Collection<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the exec path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachExecPath(
+ @CompileTimeConstant String formatStr, Collection<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the mapped values with each value formatted by the supplied format string. */
+ public <T> Builder addFormatEach(
+ @CompileTimeConstant String formatStr, Collection<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).mapEach(mapFn));
+ }
+
+ /** Adds the values with each value formatted by the supplied format string. */
+ public Builder addFormatEach(@CompileTimeConstant String formatStr, NestedSet<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachPath(
+ @CompileTimeConstant String formatStr, NestedSet<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the exec path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachExecPath(
+ @CompileTimeConstant String formatStr, NestedSet<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the mapped values with each value formatted by the supplied format string. */
+ public <T> Builder addFormatEach(
+ @CompileTimeConstant String formatStr, NestedSet<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).mapEach(mapFn));
+ }
+
+ /** Adds the values with each value formatted by the supplied format string. */
+ public Builder addFormatEach(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ Collection<String> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachPath(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ Collection<PathFragment> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the exec path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachExecPath(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ Collection<Artifact> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the mapped values with each value formatted by the supplied format string. */
+ public <T> Builder addFormatEach(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ Collection<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr).mapEach(mapFn));
+ }
+
+ /** Adds the values with each value formatted by the supplied format string. */
+ public Builder addFormatEach(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ NestedSet<String> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachPath(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ NestedSet<PathFragment> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the exec path strings with each path formatted by the supplied format string. */
+ public Builder addFormatEachExecPath(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ NestedSet<Artifact> values) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr));
+ }
+
+ /** Adds the mapped values with each value formatted by the supplied format string. */
+ public <T> Builder addFormatEach(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ NestedSet<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr).mapEach(mapFn));
+ }
+
+ /** Adds the values with each value formatted by the supplied format string, then joined. */
+ public Builder addFormatEachJoined(
+ @CompileTimeConstant String formatStr, String delimiter, Collection<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
}
/**
- * Adds the expansion of the passed vector arg.
- *
- * <p>Please see {@link VectorArg} for more information.
+ * Adds the path strings with each path formatted by the supplied format string, then joined.
*/
- public Builder add(VectorArg.Builder<String> vectorArg) {
- return addVectorArgInternal(vectorArg);
+ public Builder addFormatEachPathJoined(
+ @CompileTimeConstant String formatStr, String delimiter, Collection<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
}
/**
- * Adds the expansion of the passed vector arg's path strings.
- *
- * <p>Please see {@link VectorArg} for more information.
+ * Adds the exec path strings with each path formatted by the supplied format string, then
+ * joined.
*/
- public Builder addPaths(VectorArg.Builder<PathFragment> vectorArg) {
- return addVectorArgInternal(vectorArg);
+ public Builder addFormatEachExecPathJoined(
+ @CompileTimeConstant String formatStr, String delimiter, Collection<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
}
/**
- * Adds the expansion of the passed vector arg's exec paths.
- *
- * <p>Please see {@link VectorArg} for more information.
+ * Adds the mapped values with each value formatted by the supplied format string, then joined.
*/
- public Builder addExecPaths(VectorArg.Builder<Artifact> vectorArg) {
- return addVectorArgInternal(vectorArg);
+ public <T> Builder addFormatEachJoined(
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ Collection<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(
+ VectorArg.of(values).formatEach(formatStr).joinWith(delimiter).mapEach(mapFn));
}
- private Builder addVectorArgInternal(VectorArg.Builder<?> vectorArg) {
- if (!vectorArg.isEmpty) {
- VectorArg.push(arguments, vectorArg);
- }
- return this;
+ /** Adds the values with each value formatted by the supplied format string, then joined. */
+ public Builder addFormatEachJoined(
+ @CompileTimeConstant String formatStr, String delimiter, NestedSet<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
}
/**
- * Adds the arg followed by the expansion of the vector arg.
- *
- * <p>Please see {@link VectorArg} for more information.
- *
- * <p>If values is empty, the arg isn't added.
+ * Adds the path strings with each path formatted by the supplied format string, then joined.
*/
- public Builder add(@CompileTimeConstant String arg, VectorArg.Builder<String> vectorArg) {
- return addVectorArgInternal(arg, vectorArg);
+ public Builder addFormatEachPathJoined(
+ @CompileTimeConstant String formatStr, String delimiter, NestedSet<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
}
/**
- * Adds the arg followed by the expansion of the vector arg's path strings.
- *
- * <p>Please see {@link VectorArg} for more information.
- *
- * <p>If values is empty, the arg isn't added.
+ * Adds the exec path strings with each path formatted by the supplied format string, then
+ * joined.
*/
- public Builder addPaths(
- @CompileTimeConstant String arg, VectorArg.Builder<PathFragment> vectorArg) {
- return addVectorArgInternal(arg, vectorArg);
+ public Builder addFormatEachExecPathJoined(
+ @CompileTimeConstant String formatStr, String delimiter, NestedSet<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
}
/**
- * Adds the arg followed by the expansion of the vector arg's exec paths.
- *
- * <p>Please see {@link VectorArg} for more information.
- *
- * <p>If values is empty, the arg isn't added.
+ * Adds the mapped values with each value formatted by the supplied format string, then joined.
*/
- public Builder addExecPaths(
- @CompileTimeConstant String arg, VectorArg.Builder<Artifact> vectorArg) {
- return addVectorArgInternal(arg, vectorArg);
+ public <T> Builder addFormatEachJoined(
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ NestedSet<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(
+ VectorArg.of(values).formatEach(formatStr).joinWith(delimiter).mapEach(mapFn));
}
- private Builder addVectorArgInternal(
- @CompileTimeConstant String arg, VectorArg.Builder<?> vectorArg) {
- Preconditions.checkNotNull(arg);
- if (!vectorArg.isEmpty) {
- arguments.add(arg);
- addVectorArgInternal(vectorArg);
- }
- return this;
+ /** Adds the values with each value formatted by the supplied format string, then joined. */
+ public Builder addFormatEachJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ Collection<String> values) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
+ }
+
+ /**
+ * Adds the path strings with each path formatted by the supplied format string, then joined.
+ */
+ public Builder addFormatEachPathJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ Collection<PathFragment> values) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
+ }
+
+ /**
+ * Adds the exec path strings with each path formatted by the supplied format string, then
+ * joined.
+ */
+ public Builder addFormatEachExecPathJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ Collection<Artifact> values) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
+ }
+
+ /**
+ * Adds the mapped values with each value formatted by the supplied format string, then joined.
+ */
+ public <T> Builder addFormatEachJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ Collection<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter).mapEach(mapFn));
+ }
+
+ /** Adds the values with each value formatted by the supplied format string, then joined. */
+ public Builder addFormatEachJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ NestedSet<String> values) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
+ }
+
+ /**
+ * Adds the path strings with each path formatted by the supplied format string, then joined.
+ */
+ public Builder addFormatEachPathJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ NestedSet<PathFragment> values) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
+ }
+
+ /**
+ * Adds the exec path strings with each path formatted by the supplied format string, then
+ * joined.
+ */
+ public Builder addFormatEachExecPathJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ NestedSet<Artifact> values) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter));
+ }
+
+ /**
+ * Adds the mapped values with each value formatted by the supplied format string, then joined.
+ */
+ public <T> Builder addFormatEachJoined(
+ @CompileTimeConstant String arg,
+ @CompileTimeConstant String formatStr,
+ String delimiter,
+ NestedSet<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(
+ arg, VectorArg.of(values).formatEach(formatStr).joinWith(delimiter).mapEach(mapFn));
+ }
+
+ /** Adds the beforeEach string and the values interspersed. */
+ public Builder addBeforeEach(
+ @CompileTimeConstant String beforeEach, Collection<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach));
+ }
+
+ /** Adds the beforeEach string and the path strings interspersed. */
+ public Builder addBeforeEachPath(
+ @CompileTimeConstant String beforeEach, Collection<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach));
+ }
+
+ /** Adds the beforeEach string and the exec path strings interspersed. */
+ public Builder addBeforeEachExecPath(
+ @CompileTimeConstant String beforeEach, Collection<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach));
+ }
+
+ /** Adds the beforeEach string and the mapped values interspersed. */
+ public <T> Builder addBeforeEach(
+ @CompileTimeConstant String beforeEach, Collection<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach).mapEach(mapFn));
+ }
+
+ /** Adds the beforeEach string and the values interspersed. */
+ public Builder addBeforeEach(@CompileTimeConstant String beforeEach, NestedSet<String> values) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach));
+ }
+
+ /** Adds the beforeEach string and the path strings interspersed. */
+ public Builder addBeforeEachPath(
+ @CompileTimeConstant String beforeEach, NestedSet<PathFragment> values) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach));
+ }
+
+ /** Adds the beforeEach string and the exec path strings interspersed. */
+ public Builder addBeforeEachExecPath(
+ @CompileTimeConstant String beforeEach, NestedSet<Artifact> values) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach));
+ }
+
+ /** Adds the beforeEach string and the values interspersed. */
+ public <T> Builder addBeforeEach(
+ @CompileTimeConstant String beforeEach, NestedSet<T> values, Function<T, String> mapFn) {
+ return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach).mapEach(mapFn));
+ }
+
+ /** Adds the beforeEach string and the values interspersed. */
+ public Builder addBeforeEachFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ Collection<String> values) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr));
+ }
+
+ /** Adds the beforeEach string and the path strings interspersed. */
+ public Builder addBeforeEachPathFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ Collection<PathFragment> values) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr));
+ }
+
+ /** Adds the beforeEach string and the exec path strings interspersed. */
+ public Builder addBeforeEachExecPathFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ Collection<Artifact> values) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr));
+ }
+
+ /** Adds the beforeEach string and the mapped values interspersed. */
+ public <T> Builder addBeforeEachFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ Collection<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr).mapEach(mapFn));
+ }
+
+ /** Adds the beforeEach string and the values interspersed. */
+ public Builder addBeforeEachFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ NestedSet<String> values) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr));
+ }
+
+ /** Adds the beforeEach string and the path strings interspersed. */
+ public Builder addBeforeEachPathFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ NestedSet<PathFragment> values) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr));
+ }
+
+ /** Adds the beforeEach string and the exec path strings interspersed. */
+ public Builder addBeforeEachExecPathFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ NestedSet<Artifact> values) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr));
+ }
+
+ /** Adds the beforeEach string and the mapped values interspersed. */
+ public <T> Builder addBeforeEachFormatted(
+ @CompileTimeConstant String beforeEach,
+ @CompileTimeConstant String formatStr,
+ NestedSet<T> values,
+ Function<T, String> mapFn) {
+ return addVectorArgInternal(
+ VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr).mapEach(mapFn));
}
public Builder addCustomMultiArgv(@Nullable CustomMultiArgv arg) {
@@ -871,8 +1303,80 @@ public final class CustomCommandLine extends CommandLine {
return new CustomCommandLine(arguments);
}
- public boolean isEmpty() {
- return arguments.isEmpty();
+ private Builder addObjectInternal(@Nullable Object value) {
+ if (value != null) {
+ arguments.add(value);
+ }
+ return this;
+ }
+
+ /** Adds the arg and the passed value if the value is non-null. */
+ private Builder addObjectInternal(@CompileTimeConstant String arg, @Nullable Object value) {
+ Preconditions.checkNotNull(arg);
+ if (value != null) {
+ arguments.add(arg);
+ addObjectInternal(value);
+ }
+ return this;
+ }
+
+ private Builder addPrefixedInternal(String prefix, @Nullable Object arg) {
+ Preconditions.checkNotNull(prefix);
+ if (arg != null) {
+ PrefixArg.push(arguments, prefix, arg);
+ }
+ return this;
+ }
+
+ private Builder addCollectionInternal(@Nullable Collection<?> values) {
+ if (values != null) {
+ addVectorArgInternal(VectorArg.of(values));
+ }
+ return this;
+ }
+
+ private Builder addCollectionInternal(
+ @CompileTimeConstant String arg, @Nullable Collection<?> values) {
+ Preconditions.checkNotNull(arg);
+ if (values != null && !values.isEmpty()) {
+ arguments.add(arg);
+ addCollectionInternal(values);
+ }
+ return this;
+ }
+
+ private Builder addNestedSetInternal(@Nullable NestedSet<?> values) {
+ if (values != null) {
+ arguments.add(values);
+ }
+ return this;
+ }
+
+ private Builder addNestedSetInternal(
+ @CompileTimeConstant String arg, @Nullable NestedSet<?> values) {
+ Preconditions.checkNotNull(arg);
+ if (values != null && !values.isEmpty()) {
+ arguments.add(arg);
+ addNestedSetInternal(values);
+ }
+ return this;
+ }
+
+ private Builder addVectorArgInternal(VectorArg.Builder<?> vectorArg) {
+ if (!vectorArg.isEmpty) {
+ VectorArg.push(arguments, vectorArg);
+ }
+ return this;
+ }
+
+ private Builder addVectorArgInternal(
+ @CompileTimeConstant String arg, VectorArg.Builder<?> vectorArg) {
+ Preconditions.checkNotNull(arg);
+ if (!vectorArg.isEmpty) {
+ arguments.add(arg);
+ addVectorArgInternal(vectorArg);
+ }
+ return this;
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java
index 820a9ae457..9803d05ddb 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java
@@ -87,7 +87,7 @@ public final class ParamFileHelper {
public static CommandLine createWithParamsFile(
ImmutableList<String> executableArgs, ParamFileInfo paramFileInfo, Artifact parameterFile) {
return CustomCommandLine.builder()
- .add(executableArgs)
+ .addAll(executableArgs)
// This is actually a constant, but there is no way to suppress the warning
.addWithDynamicPrefix(paramFileInfo.getFlag(), parameterFile)
.build();
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
index 9e9ff3d436..a1db0e05f0 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
@@ -1058,7 +1058,7 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie
*/
public Builder addArguments(String... arguments) {
Preconditions.checkState(commandLine == null);
- commandLineBuilder.add(ImmutableList.copyOf(arguments));
+ commandLineBuilder.addAll(ImmutableList.copyOf(arguments));
return this;
}
@@ -1070,7 +1070,7 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie
if (arguments instanceof NestedSet) {
commandLineBuilder.addExecPaths((NestedSet) arguments);
} else {
- commandLineBuilder.add(ImmutableList.copyOf(arguments));
+ commandLineBuilder.addAll(ImmutableList.copyOf(arguments));
}
return this;
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
index 8ef53e5587..b48d800150 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
@@ -275,7 +275,7 @@ public class BazelPythonSemantics implements PythonSemantics {
PathFragment workspaceName = runfilesSupport.getWorkspaceName();
CustomCommandLine.Builder argv = new CustomCommandLine.Builder();
inputsBuilder.add(templateMain);
- argv.addWithPrefix("__main__.py=", templateMain);
+ argv.addPrefixedExecPath("__main__.py=", templateMain);
// Creating __init__.py files under each directory
argv.add("__init__.py=");
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
index 1beadb87b7..c6f99e0cef 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
@@ -46,7 +46,6 @@ import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.CommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -1342,7 +1341,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
CommandLine mergeCommandLine =
CustomCommandLine.builder()
- .addExecPaths(VectorArg.of(shardDexes).beforeEach("--input_zip"))
+ .addBeforeEachExecPath("--input_zip", shardDexes)
.addExecPath("--output_zip", classesDex)
.build();
ruleContext.registerAction(
@@ -1566,7 +1565,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
CustomCommandLine.Builder shardCommandLine =
CustomCommandLine.builder()
- .addExecPaths(VectorArg.of(shards).beforeEach("--output_jar"))
+ .addBeforeEachExecPath("--output_jar", shards)
.addExecPath("--output_resources", javaResourceJar);
if (mainDexList != null) {
@@ -1621,7 +1620,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
} else {
classpath = classpath.stream().map(derivedJarFunction::apply).collect(toImmutableList());
}
- shardCommandLine.addExecPaths(VectorArg.of(classpath).beforeEach("--input_jar"));
+ shardCommandLine.addBeforeEachExecPath("--input_jar", classpath);
shardAction.addInputs(classpath);
if (inclusionFilterJar != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java
index bac612c6c1..c28b32e0ae 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBase.java
@@ -34,7 +34,6 @@ import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.RunfilesSupport;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.android.AndroidLibraryAarProvider.Aar;
@@ -241,14 +240,12 @@ public abstract class AndroidLocalTestBase implements RuleConfiguredTargetFactor
CustomCommandLine.Builder cmdLineArgs = CustomCommandLine.builder();
if (!transitiveAars.isEmpty()) {
- cmdLineArgs.add(
- "--android_libraries",
- VectorArg.of(transitiveAars).joinWith(",").mapEach(AndroidLocalTestBase::aarCmdLineArg));
+ cmdLineArgs.addJoined(
+ "--android_libraries", ",", transitiveAars, AndroidLocalTestBase::aarCmdLineArg);
}
if (!strictAars.isEmpty()) {
- cmdLineArgs.add(
- "--strict_libraries",
- VectorArg.of(strictAars).joinWith(",").mapEach(AndroidLocalTestBase::aarCmdLineArg));
+ cmdLineArgs.addJoined(
+ "--strict_libraries", ",", strictAars, AndroidLocalTestBase::aarCmdLineArg);
}
RunfilesSupport runfilesSupport =
RunfilesSupport.withExecutable(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
index ccd4e4ee39..9117465a22 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
@@ -23,7 +23,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.ActionConstructionContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import java.util.ArrayList;
import java.util.List;
@@ -165,9 +164,8 @@ public class AndroidResourceValidatorActionBuilder {
builder
.add("--libraries")
- .addExecPaths(
- VectorArg.of(ImmutableList.copyOf(libraries))
- .joinWithDynamicString(context.getConfiguration().getHostPathSeparator()));
+ .addJoinedExecPaths(
+ context.getConfiguration().getHostPathSeparator(), ImmutableList.copyOf(libraries));
inputs.addAll(libraries);
builder.addExecPath("--compiled", compiledSymbols);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
index dd28572c62..5492df07ec 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
@@ -22,7 +22,6 @@ import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.ActionConstructionContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.Builder;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidAaptVersion;
@@ -459,19 +458,16 @@ public class AndroidResourcesProcessorBuilder {
}
ImmutableList<String> filteredResources = resourceFilter.getResourcesToIgnoreInExecution();
if (!filteredResources.isEmpty()) {
- builder.add("--prefilteredResources", VectorArg.of(filteredResources).joinWith(","));
+ builder.addJoined("--prefilteredResources", ",", filteredResources);
}
if (!uncompressedExtensions.isEmpty()) {
- builder.add(
- "--uncompressedExtensions",
- VectorArg.of(ImmutableList.copyOf(uncompressedExtensions)).joinWith(","));
+ builder.addJoined("--uncompressedExtensions", ",", uncompressedExtensions);
}
if (!crunchPng) {
builder.add("--useAaptCruncher=no");
}
if (!assetsToIgnore.isEmpty()) {
- builder.add(
- "--assetsToIgnore", VectorArg.of(ImmutableList.copyOf(assetsToIgnore)).joinWith(","));
+ builder.addJoined("--assetsToIgnore", ",", assetsToIgnore);
}
if (debug) {
builder.add("--debug");
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
index 8d0e87b66e..095d1d8f43 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
@@ -43,7 +43,6 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.analysis.WrappingProvider;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.Builder;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.cmdline.Label;
@@ -375,8 +374,8 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
new Builder()
.addExecPath("--input", jar)
.addExecPath("--output", result)
- .addExecPaths(VectorArg.of(classpath).beforeEach("--classpath_entry"))
- .addExecPaths(VectorArg.of(bootclasspath).beforeEach("--bootclasspath_entry"))
+ .addBeforeEachExecPath("--classpath_entry", classpath)
+ .addBeforeEachExecPath("--bootclasspath_entry", bootclasspath)
.build();
// Just use params file, since classpaths can get long
@@ -429,7 +428,7 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
new Builder()
.addExecPath("--input_jar", jar)
.addExecPath("--output_zip", dexArchive)
- .add(ImmutableList.copyOf(incrementalDexopts))
+ .addAll(ImmutableList.copyOf(incrementalDexopts))
.build();
Artifact paramFile =
ruleContext.getDerivedArtifact(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java
index 3d68a65203..4835d09ebb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/RClassGeneratorActionBuilder.java
@@ -23,7 +23,6 @@ import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
@@ -103,11 +102,9 @@ public class RClassGeneratorActionBuilder {
// TODO(corysmith): Remove NestedSet as we are already flattening it.
Iterable<ResourceContainer> depResources = dependencies.getResources();
if (!Iterables.isEmpty(depResources)) {
- builder.add(
- VectorArg.of(
- ImmutableList.copyOf(
- Iterables.transform(depResources, chooseDepsToArg(version))))
- .beforeEach("--library"));
+ builder.addBeforeEach(
+ "--library",
+ ImmutableList.copyOf(Iterables.transform(depResources, chooseDepsToArg(version))));
inputs.addTransitive(
NestedSetBuilder.wrap(
Order.NAIVE_LINK_ORDER,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
index 760e2f3880..041059e9a4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
@@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
@@ -241,18 +240,12 @@ public class ResourceContainerConverter {
if (dependencies != null) {
if (!dependencies.getTransitiveResources().isEmpty()) {
- cmdBuilder.add(
- "--data",
- VectorArg.of(dependencies.getTransitiveResources())
- .joinWithDynamicString(toArg.listSeparator())
- .mapEach(toArg));
+ cmdBuilder.addJoined(
+ "--data", toArg.listSeparator(), dependencies.getTransitiveResources(), toArg);
}
if (!dependencies.getDirectResources().isEmpty()) {
- cmdBuilder.add(
- "--directData",
- VectorArg.of(dependencies.getDirectResources())
- .joinWithDynamicString(toArg.listSeparator())
- .mapEach(toArg));
+ cmdBuilder.addJoined(
+ "--directData", toArg.listSeparator(), dependencies.getDirectResources(), toArg);
}
// This flattens the nested set. Since each ResourceContainer needs to be transformed into
// Artifacts, and the NestedSetBuilder.wrap doesn't support lazy Iterator evaluation
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
index 3e4519bcc3..fb0c79d19f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
@@ -20,7 +20,6 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.CompilationMode;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
@@ -171,13 +170,10 @@ public class ResourceShrinkerActionBuilder {
inputs.add(sdk.getAndroidJar());
if (!uncompressedExtensions.isEmpty()) {
- commandLine.add(
- "--uncompressedExtensions",
- VectorArg.of(ImmutableList.copyOf(uncompressedExtensions)).joinWith(","));
+ commandLine.addJoined("--uncompressedExtensions", ",", uncompressedExtensions);
}
if (!assetsToIgnore.isEmpty()) {
- commandLine.add(
- "--assetsToIgnore", VectorArg.of(ImmutableList.copyOf(assetsToIgnore)).joinWith(","));
+ commandLine.addJoined("--assetsToIgnore", ",", assetsToIgnore);
}
if (ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT) {
commandLine.add("--debug");
@@ -217,7 +213,7 @@ public class ResourceShrinkerActionBuilder {
ImmutableList<String> resourcePackages =
getResourcePackages(primaryResources, dependencyResources);
- commandLine.add("--resourcePackages", VectorArg.of(resourcePackages).joinWith(","));
+ commandLine.addJoined("--resourcePackages", ",", resourcePackages);
commandLine.addExecPath("--shrunkResourceApk", resourceApkOut);
outputs.add(resourceApkOut);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/RobolectricResourceSymbolsActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/RobolectricResourceSymbolsActionBuilder.java
index 37e16721f8..fa537bfa95 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/RobolectricResourceSymbolsActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/RobolectricResourceSymbolsActionBuilder.java
@@ -20,7 +20,6 @@ import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
@@ -86,11 +85,11 @@ public class RobolectricResourceSymbolsActionBuilder {
inputs.add(sdk.getAndroidJar());
if (!Iterables.isEmpty(dependencies.getResources())) {
- builder.add(
+ builder.addJoined(
"--data",
- VectorArg.of(dependencies.getResources())
- .joinWithDynamicString(RESOURCE_CONTAINER_TO_ARG.listSeparator())
- .mapEach(RESOURCE_CONTAINER_TO_ARG));
+ RESOURCE_CONTAINER_TO_ARG.listSeparator(),
+ dependencies.getResources(),
+ RESOURCE_CONTAINER_TO_ARG);
}
// This flattens the nested set.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java
index dd11104253..c7ff2908a9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/DeployArchiveBuilder.java
@@ -181,7 +181,7 @@ public class DeployArchiveBuilder {
if (!deployManifestLines.isEmpty()) {
args.add("--deploy_manifest_lines");
- args.add(deployManifestLines);
+ args.addAll(deployManifestLines);
}
if (buildInfoFiles != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java
index d60bca2bf0..567e66e438 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java
@@ -43,7 +43,6 @@ import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomMultiArgv;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -425,17 +424,16 @@ public final class JavaCompileAction extends SpawnAction {
checkNotNull(javaBuilderJar);
CustomCommandLine.Builder builder =
- CustomCommandLine.builder().addPath(javaExecutable).add(javaBuilderJvmFlags);
+ CustomCommandLine.builder().addPath(javaExecutable).addAll(javaBuilderJvmFlags);
if (!instrumentationJars.isEmpty()) {
builder
- .addExecPaths(
+ .addJoinedExecPaths(
"-cp",
- VectorArg.of(
- ImmutableList.<Artifact>builder()
- .addAll(instrumentationJars)
- .add(javaBuilderJar)
- .build())
- .joinWithDynamicString(pathDelimiter))
+ pathDelimiter,
+ ImmutableList.<Artifact>builder()
+ .addAll(instrumentationJars)
+ .add(javaBuilderJar)
+ .build())
.addDynamicString(javaBuilderMainClass);
} else {
// If there are no instrumentation jars, use simpler '-jar' option to launch JavaBuilder.
@@ -697,10 +695,10 @@ public final class JavaCompileAction extends SpawnAction {
result.addExecPaths("--processorpath", processorPath);
}
if (!processorNames.isEmpty()) {
- result.add("--processors", ImmutableList.copyOf(processorNames));
+ result.addAll("--processors", ImmutableList.copyOf(processorNames));
}
if (!processorFlags.isEmpty()) {
- result.add("--javacopts", ImmutableList.copyOf(processorFlags));
+ result.addAll("--javacopts", ImmutableList.copyOf(processorFlags));
}
if (!sourceJars.isEmpty()) {
result.addExecPaths("--source_jars", ImmutableList.copyOf(sourceJars));
@@ -709,7 +707,7 @@ public final class JavaCompileAction extends SpawnAction {
result.addExecPaths("--sources", sourceFiles);
}
if (!javacOpts.isEmpty()) {
- result.add("--javacopts", ImmutableList.copyOf(javacOpts));
+ result.addAll("--javacopts", ImmutableList.copyOf(javacOpts));
}
if (ruleKind != null) {
result.add("--rule_kind", ruleKind);
@@ -722,7 +720,7 @@ public final class JavaCompileAction extends SpawnAction {
} else {
// @-prefixed strings will be assumed to be filenames and expanded by
// {@link JavaLibraryBuildRequest}, so add an extra &at; to escape it.
- result.addWithPrefix("@", targetLabel);
+ result.addPrefixedLabel("@", targetLabel);
}
}
if (testOnly) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
index 109a20004d..6f9fe8e11f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
@@ -505,7 +505,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
return CustomCommandLine.builder()
.addPath(JavaCommon.getHostJavaExecutable(ruleContext))
.add("-Xverify:none")
- .add(javaToolchain.getJvmOptions())
+ .addAll(javaToolchain.getJvmOptions())
.addExecPath("-jar", javaToolchain.getHeaderCompiler());
}
@@ -531,7 +531,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
result.addExecPaths("--source_jars", ImmutableList.copyOf(sourceJars));
}
- result.add("--javacopts", javacOpts);
+ result.addAll("--javacopts", javacOpts);
if (ruleKind != null) {
result.add("--rule_kind", ruleKind);
@@ -544,7 +544,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
} else {
// @-prefixed strings will be assumed to be params filenames and expanded,
// so add an extra @ to escape it.
- result.addWithPrefix("@", targetLabel);
+ result.addPrefixedLabel("@", targetLabel);
}
}
result.addExecPaths("--classpath", classpathEntries);
@@ -556,10 +556,10 @@ public class JavaHeaderCompileAction extends SpawnAction {
CustomCommandLine.Builder result = CustomCommandLine.builder();
baseCommandLine(result, classpathEntries);
if (!processorNames.isEmpty()) {
- result.add("--processors", ImmutableList.copyOf(processorNames));
+ result.addAll("--processors", ImmutableList.copyOf(processorNames));
}
if (!processorFlags.isEmpty()) {
- result.add("--javacopts", ImmutableList.copyOf(processorFlags));
+ result.addAll("--javacopts", ImmutableList.copyOf(processorFlags));
}
if (!processorPath.isEmpty()) {
result.addExecPaths("--processorpath", processorPath);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/OneVersionCheckActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/OneVersionCheckActionBuilder.java
index 8daf0e7295..fa643bd421 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/OneVersionCheckActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/OneVersionCheckActionBuilder.java
@@ -20,7 +20,6 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
@@ -92,8 +91,8 @@ public final class OneVersionCheckActionBuilder {
if (enforcementLevel == OneVersionEnforcementLevel.WARNING) {
oneVersionArgsBuilder.add("--succeed_on_found_violations");
}
- oneVersionArgsBuilder.add("--inputs", VectorArg.of(jarsToCheck).mapEach(
- OneVersionCheckActionBuilder::jarAndTargetArg));
+ oneVersionArgsBuilder.addAll(
+ "--inputs", jarsToCheck, OneVersionCheckActionBuilder::jarAndTargetArg);
CustomCommandLine oneVersionArgs = oneVersionArgsBuilder.build();
ruleContext.registerAction(
new SpawnAction.Builder()
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java
index 8b3e64c7a4..155d4359d9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java
@@ -93,7 +93,7 @@ public final class SingleJarActionBuilder {
Map<PathFragment, Artifact> resources, Iterable<Artifact> resourceJars) {
CustomCommandLine.Builder args = CustomCommandLine.builder();
args.addExecPath("--output", outputJar);
- args.add(SOURCE_JAR_COMMAND_LINE_ARGS);
+ args.addAll(SOURCE_JAR_COMMAND_LINE_ARGS);
args.addExecPaths("--sources", ImmutableList.copyOf(resourceJars));
if (!resources.isEmpty()) {
args.add("--resources");
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java
index 805f90f68f..b96f37d418 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java
@@ -447,8 +447,8 @@ final class BundleSupport {
}
return commandLine
- .add(ImmutableList.copyOf(PathFragment.safePathStrings(provider.get(XCASSETS_DIR))))
- .add(ImmutableList.copyOf(extraActoolArgs))
+ .addAll(ImmutableList.copyOf(PathFragment.safePathStrings(provider.get(XCASSETS_DIR))))
+ .addAll(ImmutableList.copyOf(extraActoolArgs))
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index 9882ea4a0d..c9716a5902 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -55,7 +55,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -1078,16 +1077,12 @@ public abstract class CompilationSupport {
.addExecPath("--output_archive", prunedJ2ObjcArchive)
.addExecPath("--dummy_archive", dummyArchive)
.addExecPath("--xcrunwrapper", xcrunwrapper(ruleContext).getExecutable())
- .addExecPaths(
- "--dependency_mapping_files",
- VectorArg.of(j2ObjcDependencyMappingFiles).joinWith(","))
- .addExecPaths(
- "--header_mapping_files", VectorArg.of(j2ObjcHeaderMappingFiles).joinWith(","))
- .addExecPaths(
- "--archive_source_mapping_files",
- VectorArg.of(j2ObjcArchiveSourceMappingFiles).joinWith(","))
+ .addJoinedExecPaths("--dependency_mapping_files", ",", j2ObjcDependencyMappingFiles)
+ .addJoinedExecPaths("--header_mapping_files", ",", j2ObjcHeaderMappingFiles)
+ .addJoinedExecPaths(
+ "--archive_source_mapping_files", ",", j2ObjcArchiveSourceMappingFiles)
.add("--entry_classes")
- .add(VectorArg.of(entryClasses).joinWith(","))
+ .addJoined(",", entryClasses)
.build();
ruleContext.registerAction(
@@ -1168,7 +1163,7 @@ public abstract class CompilationSupport {
ImmutableList<String> extraFlags, Artifact unstrippedArtifact, Artifact strippedArtifact) {
return CustomCommandLine.builder()
.add(STRIP)
- .add(extraFlags)
+ .addAll(extraFlags)
.addExecPath("-o", strippedArtifact)
.addPath(unstrippedArtifact.getExecPath())
.build();
@@ -1397,16 +1392,13 @@ public abstract class CompilationSupport {
XcodeConfig.getXcodeVersion(ruleContext).toStringWithMinimumComponents(2))
.add("--");
for (ObjcHeaderThinningInfo info : infos) {
- cmdLine.addPaths(
- VectorArg.of(
- ImmutableList.of(
- info.sourceFile.getExecPath(), info.headersListFile.getExecPath()))
- .joinWith(":"));
+ cmdLine.addFormatted(
+ "%s:%s", info.sourceFile.getExecPath(), info.headersListFile.getExecPath());
builder.addInput(info.sourceFile).addOutput(info.headersListFile);
}
ruleContext.registerAction(
builder
- .setCommandLine(cmdLine.add("--").add(args).build())
+ .setCommandLine(cmdLine.add("--").addAll(args).build())
.addInputs(compilationArtifacts.getPrivateHdrs())
.addTransitiveInputs(attributes.hdrs())
.addTransitiveInputs(objcProvider.get(ObjcProvider.HEADER))
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
index 0d018df6d2..3bdb5d48c0 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
@@ -34,7 +34,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -493,21 +492,19 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
ImmutableList.Builder<Artifact> sourceJarOutputFiles = ImmutableList.builder();
if (!Iterables.isEmpty(sourceJars)) {
sourceJarOutputFiles.addAll(sourceJarOutputs(ruleContext));
- argBuilder.addExecPaths(
- "--src_jars", VectorArg.of(ImmutableList.copyOf(sourceJars)).joinWith(","));
- argBuilder.add(sourceJarFlags(ruleContext));
+ argBuilder.addJoinedExecPaths("--src_jars", ",", ImmutableList.copyOf(sourceJars));
+ argBuilder.addAll(sourceJarFlags(ruleContext));
}
Iterable<String> translationFlags = ruleContext
.getFragment(J2ObjcConfiguration.class)
.getTranslationFlags();
- argBuilder.add(ImmutableList.copyOf(translationFlags));
+ argBuilder.addAll(ImmutableList.copyOf(translationFlags));
NestedSet<Artifact> depsHeaderMappingFiles =
depJ2ObjcMappingFileProvider.getHeaderMappingFiles();
if (!depsHeaderMappingFiles.isEmpty()) {
- argBuilder.addExecPaths(
- "--header-mapping", VectorArg.of(depsHeaderMappingFiles).joinWith(","));
+ argBuilder.addJoinedExecPaths("--header-mapping", ",", depsHeaderMappingFiles);
}
boolean experimentalJ2ObjcHeaderMap =
@@ -519,7 +516,7 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
NestedSet<Artifact> depsClassMappingFiles = depJ2ObjcMappingFileProvider.getClassMappingFiles();
if (!depsClassMappingFiles.isEmpty()) {
- argBuilder.addExecPaths("--mapping", VectorArg.of(depsClassMappingFiles).joinWith(","));
+ argBuilder.addJoinedExecPaths("--mapping", ",", depsClassMappingFiles);
}
Artifact archiveSourceMappingFile = j2ObjcOutputArchiveSourceMappingFile(ruleContext);
@@ -541,7 +538,7 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
NestedSet<Artifact> compileTimeJars =
compArgsProvider.getRecursiveJavaCompilationArgs().getCompileTimeJars();
if (!compileTimeJars.isEmpty()) {
- argBuilder.addExecPaths("-classpath", VectorArg.of(compileTimeJars).joinWith(":"));
+ argBuilder.addJoinedExecPaths("-classpath", ":", compileTimeJars);
}
argBuilder.addExecPaths(ImmutableList.copyOf(sources));
@@ -587,12 +584,12 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
if (experimentalJ2ObjcHeaderMap) {
CustomCommandLine.Builder headerMapCommandLine = CustomCommandLine.builder();
if (!Iterables.isEmpty(sources)) {
- headerMapCommandLine.addExecPaths(
- "--source_files", VectorArg.of(ImmutableList.copyOf(sources)).joinWith(","));
+ headerMapCommandLine.addJoinedExecPaths(
+ "--source_files", ",", ImmutableList.copyOf(sources));
}
if (!Iterables.isEmpty(sourceJars)) {
- headerMapCommandLine.addExecPaths(
- "--source_jars", VectorArg.of(ImmutableList.copyOf(sourceJars)).joinWith(","));
+ headerMapCommandLine.addJoinedExecPaths(
+ "--source_jars", ",", ImmutableList.copyOf(sourceJars));
}
headerMapCommandLine.addExecPath("--output_mapping_file", outputHeaderMappingFile);
ruleContext.registerAction(new SpawnAction.Builder()
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
index b5e312e7c5..dc7326d56e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
@@ -50,7 +50,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate;
import com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -300,20 +299,20 @@ public class LegacyCompilationSupport extends CompilationSupport {
}
commandLine
- .add(ImmutableList.copyOf(compileFlagsForClang(appleConfiguration)))
- .add(commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration))
- .add(objcConfiguration.getCoptsForCompilationMode())
- .addPaths(
- VectorArg.of(ObjcCommon.userHeaderSearchPaths(objcProvider, buildConfiguration))
- .beforeEach("-iquote"))
- .addExecPaths(VectorArg.of(ImmutableList.copyOf(pchFile.asSet())).beforeEach("-include"))
- .addPaths(VectorArg.of(ImmutableList.copyOf(priorityHeaders)).beforeEach("-I"))
- .addPaths(VectorArg.of(objcProvider.get(INCLUDE)).beforeEach("-I"))
- .addPaths(VectorArg.of(objcProvider.get(INCLUDE_SYSTEM)).beforeEach("-isystem"))
- .add(ImmutableList.copyOf(otherFlags))
- .add(VectorArg.of(objcProvider.get(DEFINE)).formatEach("-D%s"))
- .add(coverageFlags)
- .add(ImmutableList.copyOf(getCompileRuleCopts()));
+ .addAll(ImmutableList.copyOf(compileFlagsForClang(appleConfiguration)))
+ .addAll(
+ commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration))
+ .addAll(objcConfiguration.getCoptsForCompilationMode())
+ .addBeforeEachPath(
+ "-iquote", ObjcCommon.userHeaderSearchPaths(objcProvider, buildConfiguration))
+ .addBeforeEachExecPath("-include", pchFile.asSet())
+ .addBeforeEachPath("-I", ImmutableList.copyOf(priorityHeaders))
+ .addBeforeEachPath("-I", objcProvider.get(INCLUDE))
+ .addBeforeEachPath("-isystem", objcProvider.get(INCLUDE_SYSTEM))
+ .addAll(ImmutableList.copyOf(otherFlags))
+ .addFormatEach("-D%s", objcProvider.get(DEFINE))
+ .addAll(coverageFlags)
+ .addAll(ImmutableList.copyOf(getCompileRuleCopts()));
// Add input source file arguments
commandLine.add("-c");
@@ -703,7 +702,7 @@ public class LegacyCompilationSupport extends CompilationSupport {
commandLine.add("-filelist", inputFileList.getExecPathString());
AppleBitcodeMode bitcodeMode = appleConfiguration.getBitcodeMode();
- commandLine.add(bitcodeMode.getCompileAndLinkFlags());
+ commandLine.addAll(bitcodeMode.getCompileAndLinkFlags());
if (bitcodeMode == AppleBitcodeMode.EMBEDDED) {
commandLine.add("-Xlinker").add("-bitcode_verify");
@@ -716,7 +715,8 @@ public class LegacyCompilationSupport extends CompilationSupport {
}
commandLine
- .add(commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration))
+ .addAll(
+ commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration))
.add("-Xlinker")
.add("-objc_abi_version")
.add("-Xlinker")
@@ -728,24 +728,20 @@ public class LegacyCompilationSupport extends CompilationSupport {
.add("-Xlinker")
.add("@executable_path/Frameworks")
.add("-fobjc-link-runtime")
- .add(DEFAULT_LINKER_FLAGS)
- .add(
- VectorArg.of(ImmutableList.copyOf(frameworkNames(objcProvider)))
- .beforeEach("-framework"))
- .add(
- VectorArg.of(SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK)))
- .beforeEach("-weak_framework"))
- .add(VectorArg.of(libraryNames).formatEach("-l%s"))
+ .addAll(DEFAULT_LINKER_FLAGS)
+ .addBeforeEach("-framework", frameworkNames(objcProvider))
+ .addBeforeEach("-weak_framework", SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK)))
+ .addFormatEach("-l%s", libraryNames)
.addExecPath("-o", linkedBinary)
- .addExecPaths(VectorArg.of(forceLinkArtifacts).beforeEach("-force_load"))
- .add(ImmutableList.copyOf(extraLinkArgs))
- .add(objcProvider.get(ObjcProvider.LINKOPT));
+ .addBeforeEachExecPath("-force_load", forceLinkArtifacts)
+ .addAll(ImmutableList.copyOf(extraLinkArgs))
+ .addAll(objcProvider.get(ObjcProvider.LINKOPT));
if (buildConfiguration.isCodeCoverageEnabled()) {
if (buildConfiguration.isLLVMCoverageMapFormatEnabled()) {
- commandLine.add(LINKER_LLVM_COVERAGE_FLAGS);
+ commandLine.addAll(LINKER_LLVM_COVERAGE_FLAGS);
} else {
- commandLine.add(LINKER_COVERAGE_FLAGS);
+ commandLine.addAll(LINKER_COVERAGE_FLAGS);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java
index abaed048bb..e9b666a526 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java
@@ -28,7 +28,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.Builder;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -478,7 +477,7 @@ final class ProtobufSupport {
.addDynamicString(getGenfilesPathString())
.add("--proto-root-dir")
.add(".")
- .addExecPaths(VectorArg.of(portableProtoFilters).beforeEach("--config"))
+ .addBeforeEachExecPath("--config", portableProtoFilters)
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
index 86415309d5..13300208e2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
@@ -301,7 +301,7 @@ public class ProtoCompileActionBuilder {
result.addLazyString(new LazyLangPluginFlag(langPrefix, langPluginParameter1));
}
- result.add(ruleContext.getFragment(ProtoConfiguration.class).protocOpts());
+ result.addAll(ruleContext.getFragment(ProtoConfiguration.class).protocOpts());
boolean areDepsStrict = areDepsStrict(ruleContext);
@@ -326,7 +326,7 @@ public class ProtoCompileActionBuilder {
}
if (additionalCommandLineArguments != null) {
- result.add(ImmutableList.copyOf(additionalCommandLineArguments));
+ result.addAll(ImmutableList.copyOf(additionalCommandLineArguments));
}
return result;
@@ -586,7 +586,7 @@ public class ProtoCompileActionBuilder {
}
}
- cmdLine.add(protocOpts);
+ cmdLine.addAll(protocOpts);
// Add include maps
cmdLine.addCustomMultiArgv(new ProtoCommandLineArgv(protosInDirectDeps, transitiveSources));
diff --git a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
index 6b1b9e6e9c..96da8ef7ab 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
@@ -14,23 +14,23 @@
package com.google.devtools.build.lib.actions;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.devtools.build.lib.analysis.actions.CustomCommandLine.builder;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
-import com.google.common.testing.NullPointerTester;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType;
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomMultiArgv;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.testutil.Scratch;
+import com.google.devtools.build.lib.util.LazyString;
import com.google.devtools.build.lib.vfs.PathFragment;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -56,113 +56,592 @@ public class CustomCommandLineTest {
}
@Test
- public void testStringArgs() {
- CustomCommandLine cl = CustomCommandLine.builder().add("--arg1").add("--arg2").build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("--arg1", "--arg2"));
- }
+ public void testScalarAdds() throws Exception {
+ assertThat(builder().add("--arg").build().arguments()).containsExactly("--arg").inOrder();
+ assertThat(builder().addDynamicString("--arg").build().arguments())
+ .containsExactly("--arg")
+ .inOrder();
+ assertThat(builder().addLabel(Label.parseAbsolute("//a:b")).build().arguments())
+ .containsExactly("//a:b")
+ .inOrder();
+ assertThat(builder().addPath(PathFragment.create("path")).build().arguments())
+ .containsExactly("path")
+ .inOrder();
+ assertThat(builder().addExecPath(artifact1).build().arguments())
+ .containsExactly("dir/file1.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addLazyString(
+ new LazyString() {
+ @Override
+ public String toString() {
+ return "foo";
+ }
+ })
+ .build()
+ .arguments())
+ .containsExactly("foo")
+ .inOrder();
- @Test
- public void testLabelArgs() throws LabelSyntaxException {
- CustomCommandLine cl =
- CustomCommandLine.builder().addLabel(Label.parseAbsolute("//a:b")).build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("//a:b"));
+ assertThat(builder().add("--arg", "val").build().arguments())
+ .containsExactly("--arg", "val")
+ .inOrder();
+ assertThat(builder().addLabel("--arg", Label.parseAbsolute("//a:b")).build().arguments())
+ .containsExactly("--arg", "//a:b")
+ .inOrder();
+ assertThat(builder().addPath("--arg", PathFragment.create("path")).build().arguments())
+ .containsExactly("--arg", "path")
+ .inOrder();
+ assertThat(builder().addExecPath("--arg", artifact1).build().arguments())
+ .containsExactly("--arg", "dir/file1.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addLazyString(
+ "--arg",
+ new LazyString() {
+ @Override
+ public String toString() {
+ return "foo";
+ }
+ })
+ .build()
+ .arguments())
+ .containsExactly("--arg", "foo")
+ .inOrder();
}
@Test
- public void testStringsArgs() {
- CustomCommandLine cl = CustomCommandLine.builder().add("--arg",
- ImmutableList.of("a", "b")).build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("--arg", "a", "b"));
+ public void testAddFormatted() throws Exception {
+ assertThat(builder().addFormatted("%s%s", "hello", "world").build().arguments())
+ .containsExactly("helloworld")
+ .inOrder();
}
@Test
- public void testArtifactJoinStringArgs() {
- CustomCommandLine cl =
- CustomCommandLine.builder()
- .add("--path", VectorArg.of(ImmutableList.of("foo", "bar")).joinWith(":"))
- .build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("--path", "foo:bar"));
+ public void testAddPrefixed() throws Exception {
+ assertThat(builder().addPrefixed("prefix-", "foo").build().arguments())
+ .containsExactly("prefix-foo")
+ .inOrder();
+ assertThat(
+ builder().addPrefixedLabel("prefix-", Label.parseAbsolute("//a:b")).build().arguments())
+ .containsExactly("prefix-//a:b")
+ .inOrder();
+ assertThat(
+ builder().addPrefixedPath("prefix-", PathFragment.create("path")).build().arguments())
+ .containsExactly("prefix-path")
+ .inOrder();
+ assertThat(builder().addPrefixedExecPath("prefix-", artifact1).build().arguments())
+ .containsExactly("prefix-dir/file1.txt")
+ .inOrder();
}
@Test
- public void testJoinValues() {
- CustomCommandLine cl =
- CustomCommandLine.builder()
- .add(
- "--path",
- VectorArg.of(ImmutableList.of("foo", "bar", "baz"))
- .joinWith(":")
- .mapEach(String::toUpperCase))
- .build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("--path", "FOO:BAR:BAZ"));
- }
+ public void testVectorAdds() throws Exception {
+ assertThat(builder().addAll(list("val1", "val2")).build().arguments())
+ .containsExactly("val1", "val2")
+ .inOrder();
+ assertThat(builder().addAll(nestedSet("val1", "val2")).build().arguments())
+ .containsExactly("val1", "val2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addPaths(list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("path1", "path2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addPaths(nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("path1", "path2")
+ .inOrder();
+ assertThat(builder().addExecPaths(list(artifact1, artifact2)).build().arguments())
+ .containsExactly("dir/file1.txt", "dir/file2.txt")
+ .inOrder();
+ assertThat(builder().addExecPaths(nestedSet(artifact1, artifact2)).build().arguments())
+ .containsExactly("dir/file1.txt", "dir/file2.txt")
+ .inOrder();
+ assertThat(builder().addAll(list(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("1", "2")
+ .inOrder();
+ assertThat(builder().addAll(nestedSet(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("1", "2")
+ .inOrder();
- @Test
- public void testArtifactExecPathArgs() {
- CustomCommandLine cl = CustomCommandLine.builder().addExecPath("--path", artifact1).build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("--path", "dir/file1.txt"));
+ assertThat(builder().addAll("--arg", list("val1", "val2")).build().arguments())
+ .containsExactly("--arg", "val1", "val2")
+ .inOrder();
+ assertThat(builder().addAll("--arg", nestedSet("val1", "val2")).build().arguments())
+ .containsExactly("--arg", "val1", "val2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addPaths("--arg", list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "path1", "path2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addPaths(
+ "--arg", nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "path1", "path2")
+ .inOrder();
+ assertThat(builder().addExecPaths("--arg", list(artifact1, artifact2)).build().arguments())
+ .containsExactly("--arg", "dir/file1.txt", "dir/file2.txt")
+ .inOrder();
+ assertThat(builder().addExecPaths("--arg", nestedSet(artifact1, artifact2)).build().arguments())
+ .containsExactly("--arg", "dir/file1.txt", "dir/file2.txt")
+ .inOrder();
+ assertThat(builder().addAll("--arg", list(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("--arg", "1", "2")
+ .inOrder();
+ assertThat(
+ builder().addAll("--arg", nestedSet(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("--arg", "1", "2")
+ .inOrder();
}
@Test
- public void testArtifactExecPathsArgs() {
- CustomCommandLine cl =
- CustomCommandLine.builder()
- .addExecPaths("--path", ImmutableList.of(artifact1, artifact2))
- .build();
- assertThat(cl.arguments())
- .isEqualTo(ImmutableList.of("--path", "dir/file1.txt", "dir/file2.txt"));
- }
+ public void testAddJoined() throws Exception {
+ assertThat(builder().addJoined(":", list("val1", "val2")).build().arguments())
+ .containsExactly("val1:val2")
+ .inOrder();
+ assertThat(builder().addJoined(":", nestedSet("val1", "val2")).build().arguments())
+ .containsExactly("val1:val2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoinedPaths(
+ ":", list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("path1:path2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoinedPaths(
+ ":", nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("path1:path2")
+ .inOrder();
+ assertThat(builder().addJoinedExecPaths(":", list(artifact1, artifact2)).build().arguments())
+ .containsExactly("dir/file1.txt:dir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder().addJoinedExecPaths(":", nestedSet(artifact1, artifact2)).build().arguments())
+ .containsExactly("dir/file1.txt:dir/file2.txt")
+ .inOrder();
+ assertThat(builder().addJoined(":", list(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("1:2")
+ .inOrder();
+ assertThat(
+ builder().addJoined(":", nestedSet(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("1:2")
+ .inOrder();
- @Test
- public void testNestedSetArtifactExecPathsArgs() {
- CustomCommandLine cl =
- CustomCommandLine.builder()
- .addExecPaths(
- NestedSetBuilder.<Artifact>stableOrder().add(artifact1).add(artifact2).build())
- .build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("dir/file1.txt", "dir/file2.txt"));
+ assertThat(builder().addJoined("--arg", ":", list("val1", "val2")).build().arguments())
+ .containsExactly("--arg", "val1:val2")
+ .inOrder();
+ assertThat(builder().addJoined("--arg", ":", nestedSet("val1", "val2")).build().arguments())
+ .containsExactly("--arg", "val1:val2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoinedPaths(
+ "--arg", ":", list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "path1:path2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoinedPaths(
+ "--arg",
+ ":",
+ nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "path1:path2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoinedExecPaths("--arg", ":", list(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "dir/file1.txt:dir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoinedExecPaths("--arg", ":", nestedSet(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "dir/file1.txt:dir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoined("--arg", ":", list(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("--arg", "1:2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addJoined("--arg", ":", nestedSet(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("--arg", "1:2")
+ .inOrder();
}
@Test
- public void testArtifactJoinExecPathArgs() {
- CustomCommandLine cl =
- CustomCommandLine.builder()
- .addExecPaths(
- "--path", VectorArg.of(ImmutableList.of(artifact1, artifact2)).joinWith(":"))
- .build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("--path", "dir/file1.txt:dir/file2.txt"));
+ public void testAddFormatEach() throws Exception {
+ assertThat(builder().addFormatEach("-D%s", list("val1", "val2")).build().arguments())
+ .containsExactly("-Dval1", "-Dval2")
+ .inOrder();
+ assertThat(builder().addFormatEach("-D%s", nestedSet("val1", "val2")).build().arguments())
+ .containsExactly("-Dval1", "-Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPath(
+ "-D%s", list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-Dpath1", "-Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPath(
+ "-D%s", nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-Dpath1", "-Dpath2")
+ .inOrder();
+ assertThat(
+ builder().addFormatEachExecPath("-D%s", list(artifact1, artifact2)).build().arguments())
+ .containsExactly("-Ddir/file1.txt", "-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachExecPath("-D%s", nestedSet(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("-Ddir/file1.txt", "-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder().addFormatEach("-D%s", list(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("-D1", "-D2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEach("-D%s", nestedSet(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("-D1", "-D2")
+ .inOrder();
+
+ assertThat(builder().addFormatEach("--arg", "-D%s", list("val1", "val2")).build().arguments())
+ .containsExactly("--arg", "-Dval1", "-Dval2")
+ .inOrder();
+ assertThat(
+ builder().addFormatEach("--arg", "-D%s", nestedSet("val1", "val2")).build().arguments())
+ .containsExactly("--arg", "-Dval1", "-Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPath(
+ "--arg",
+ "-D%s",
+ list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Dpath1", "-Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPath(
+ "--arg",
+ "-D%s",
+ nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Dpath1", "-Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachExecPath("--arg", "-D%s", list(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Ddir/file1.txt", "-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachExecPath("--arg", "-D%s", nestedSet(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Ddir/file1.txt", "-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEach("--arg", "-D%s", list(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-D1", "-D2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEach("--arg", "-D%s", nestedSet(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-D1", "-D2")
+ .inOrder();
}
@Test
- public void testPathArgs() {
- CustomCommandLine cl = CustomCommandLine.builder().addPath(artifact1.getExecPath()).build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("dir/file1.txt"));
+ public void testAddFormatEachJoined() throws Exception {
+ assertThat(builder().addFormatEachJoined("-D%s", ":", list("val1", "val2")).build().arguments())
+ .containsExactly("-Dval1:-Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachJoined("-D%s", ":", nestedSet("val1", "val2"))
+ .build()
+ .arguments())
+ .containsExactly("-Dval1:-Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPathJoined(
+ "-D%s", ":", list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-Dpath1:-Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPathJoined(
+ "-D%s",
+ ":", nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-Dpath1:-Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachExecPathJoined("-D%s", ":", list(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("-Ddir/file1.txt:-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachExecPathJoined("-D%s", ":", nestedSet(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("-Ddir/file1.txt:-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachJoined("-D%s", ":", list(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("-D1:-D2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachJoined("-D%s", ":", nestedSet(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("-D1:-D2")
+ .inOrder();
+
+ assertThat(
+ builder()
+ .addFormatEachJoined("--arg", "-D%s", ":", list("val1", "val2"))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Dval1:-Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachJoined("--arg", "-D%s", ":", nestedSet("val1", "val2"))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Dval1:-Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPathJoined(
+ "--arg",
+ "-D%s",
+ ":",
+ list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Dpath1:-Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachPathJoined(
+ "--arg",
+ "-D%s",
+ ":",
+ nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Dpath1:-Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachExecPathJoined("--arg", "-D%s", ":", list(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Ddir/file1.txt:-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachExecPathJoined("--arg", "-D%s", ":", nestedSet(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-Ddir/file1.txt:-Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachJoined("--arg", "-D%s", ":", list(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-D1:-D2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addFormatEachJoined("--arg", "-D%s", ":", nestedSet(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("--arg", "-D1:-D2")
+ .inOrder();
}
@Test
- public void testJoinPathArgs() {
- CustomCommandLine cl =
- CustomCommandLine.builder()
- .addPaths(
- VectorArg.of(ImmutableList.of(artifact1.getExecPath(), artifact2.getExecPath()))
- .joinWith(":"))
- .build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("dir/file1.txt:dir/file2.txt"));
+ public void testAddBeforeEach() throws Exception {
+ assertThat(builder().addBeforeEach("-D", list("val1", "val2")).build().arguments())
+ .containsExactly("-D", "val1", "-D", "val2")
+ .inOrder();
+ assertThat(builder().addBeforeEach("-D", nestedSet("val1", "val2")).build().arguments())
+ .containsExactly("-D", "val1", "-D", "val2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachPath(
+ "-D", list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-D", "path1", "-D", "path2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachPath(
+ "-D", nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-D", "path1", "-D", "path2")
+ .inOrder();
+ assertThat(
+ builder().addBeforeEachExecPath("-D", list(artifact1, artifact2)).build().arguments())
+ .containsExactly("-D", "dir/file1.txt", "-D", "dir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachExecPath("-D", nestedSet(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("-D", "dir/file1.txt", "-D", "dir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder().addBeforeEach("-D", list(foo("1"), foo("2")), Foo::str).build().arguments())
+ .containsExactly("-D", "1", "-D", "2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEach("-D", nestedSet(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("-D", "1", "-D", "2")
+ .inOrder();
}
@Test
- public void testPathsArgs() {
- CustomCommandLine cl =
- CustomCommandLine.builder()
- .addFormatted("%s:%s", artifact1.getExecPath(), artifact1.getRootRelativePath())
- .build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("dir/file1.txt:dir/file1.txt"));
+ public void testAddBeforeEachFormatted() throws Exception {
+ assertThat(
+ builder().addBeforeEachFormatted("-D", "D%s", list("val1", "val2")).build().arguments())
+ .containsExactly("-D", "Dval1", "-D", "Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachFormatted("-D", "D%s", nestedSet("val1", "val2"))
+ .build()
+ .arguments())
+ .containsExactly("-D", "Dval1", "-D", "Dval2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachPathFormatted(
+ "-D", "D%s", list(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-D", "Dpath1", "-D", "Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachPathFormatted(
+ "-D",
+ "D%s",
+ nestedSet(PathFragment.create("path1"), PathFragment.create("path2")))
+ .build()
+ .arguments())
+ .containsExactly("-D", "Dpath1", "-D", "Dpath2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachExecPathFormatted("-D", "D%s", list(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("-D", "Ddir/file1.txt", "-D", "Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachExecPathFormatted("-D", "D%s", nestedSet(artifact1, artifact2))
+ .build()
+ .arguments())
+ .containsExactly("-D", "Ddir/file1.txt", "-D", "Ddir/file2.txt")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachFormatted("-D", "D%s", list(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("-D", "D1", "-D", "D2")
+ .inOrder();
+ assertThat(
+ builder()
+ .addBeforeEachFormatted("-D", "D%s", nestedSet(foo("1"), foo("2")), Foo::str)
+ .build()
+ .arguments())
+ .containsExactly("-D", "D1", "-D", "D2")
+ .inOrder();
}
@Test
public void testCustomMultiArgs() {
CustomCommandLine cl =
- CustomCommandLine.builder()
+ builder()
.addCustomMultiArgv(
new CustomMultiArgv() {
@Override
@@ -171,22 +650,22 @@ public class CustomCommandLineTest {
}
})
.build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of("--arg1", "--arg2"));
+ assertThat(cl.arguments()).containsExactly("--arg1", "--arg2").inOrder();
}
@Test
public void testCombinedArgs() {
CustomCommandLine cl =
- CustomCommandLine.builder()
+ builder()
.add("--arg")
- .add("--args", ImmutableList.of("abc"))
+ .addAll("--args", ImmutableList.of("abc"))
.addExecPaths("--path1", ImmutableList.of(artifact1))
.addExecPath("--path2", artifact2)
.build();
assertThat(cl.arguments())
- .isEqualTo(
- ImmutableList.of(
- "--arg", "--args", "abc", "--path1", "dir/file1.txt", "--path2", "dir/file2.txt"));
+ .containsExactly(
+ "--arg", "--args", "abc", "--path1", "dir/file1.txt", "--path2", "dir/file2.txt")
+ .inOrder();
}
@Test
@@ -195,78 +674,57 @@ public class CustomCommandLineTest {
assertThat(treeArtifact).isNotNull();
CustomCommandLine cl =
- CustomCommandLine.builder()
+ builder()
.addDynamicString(null)
.addLabel(null)
.addPath(null)
.addExecPath(null)
.addLazyString(null)
- .add("foo", (String) null)
+ .add("foo", null)
.addLabel("foo", null)
.addPath("foo", null)
.addExecPath("foo", null)
.addLazyString("foo", null)
- .add((ImmutableList<String>) null)
- .add(ImmutableList.of())
+ .addPrefixed("prefix", null)
+ .addPrefixedLabel("prefix", null)
+ .addPrefixedPath("prefix", null)
+ .addPrefixedExecPath("prefix", null)
+ .addAll((ImmutableList<String>) null)
+ .addAll(ImmutableList.of())
.addPaths((ImmutableList<PathFragment>) null)
.addPaths(ImmutableList.of())
.addExecPaths((ImmutableList<Artifact>) null)
.addExecPaths(ImmutableList.of())
- .add((NestedSet<String>) null)
- .add(NestedSetBuilder.emptySet(Order.STABLE_ORDER))
+ .addAll((ImmutableList<Foo>) null, Foo::str)
+ .addAll(ImmutableList.of(), Foo::str)
+ .addAll((NestedSet<String>) null)
+ .addAll(NestedSetBuilder.emptySet(Order.STABLE_ORDER))
.addPaths((NestedSet<PathFragment>) null)
.addPaths(NestedSetBuilder.emptySet(Order.STABLE_ORDER))
.addExecPaths((NestedSet<Artifact>) null)
.addExecPaths(NestedSetBuilder.emptySet(Order.STABLE_ORDER))
- .add("foo", (ImmutableList<String>) null)
- .add("foo", ImmutableList.of())
+ .addAll((NestedSet<Foo>) null, Foo::str)
+ .addAll(NestedSetBuilder.emptySet(Order.STABLE_ORDER), Foo::str)
+ .addAll("foo", (ImmutableList<String>) null)
+ .addAll("foo", ImmutableList.of())
.addPaths("foo", (ImmutableList<PathFragment>) null)
.addPaths("foo", ImmutableList.of())
+ .addAll("foo", (ImmutableList<Foo>) null, Foo::str)
+ .addAll("foo", ImmutableList.of(), Foo::str)
.addExecPaths("foo", (ImmutableList<Artifact>) null)
.addExecPaths("foo", ImmutableList.of())
- .add("foo", (NestedSet<String>) null)
- .add("foo", NestedSetBuilder.emptySet(Order.STABLE_ORDER))
+ .addAll("foo", (NestedSet<String>) null)
+ .addAll("foo", NestedSetBuilder.emptySet(Order.STABLE_ORDER))
.addPaths("foo", (NestedSet<PathFragment>) null)
.addPaths("foo", NestedSetBuilder.emptySet(Order.STABLE_ORDER))
.addExecPaths("foo", (NestedSet<Artifact>) null)
.addExecPaths("foo", NestedSetBuilder.emptySet(Order.STABLE_ORDER))
- .add(VectorArg.of((ImmutableList<String>) null))
- .add(VectorArg.of(ImmutableList.of()))
- .addPaths(VectorArg.of((ImmutableList<PathFragment>) null))
- .addPaths(VectorArg.of(ImmutableList.of()))
- .addExecPaths(VectorArg.of((ImmutableList<Artifact>) null))
- .addExecPaths(VectorArg.of(ImmutableList.of()))
- .add("foo", VectorArg.of((ImmutableList<String>) null))
- .add("foo", VectorArg.of(ImmutableList.of()))
- .addPaths("foo", VectorArg.of((ImmutableList<PathFragment>) null))
- .addPaths("foo", VectorArg.of(ImmutableList.of()))
- .addExecPaths("foo", VectorArg.of((ImmutableList<Artifact>) null))
- .addExecPaths("foo", VectorArg.of(ImmutableList.of()))
+ .addAll("foo", (NestedSet<Foo>) null, Foo::str)
+ .addAll("foo", NestedSetBuilder.emptySet(Order.STABLE_ORDER), Foo::str)
+ .addCustomMultiArgv(null)
.addPlaceholderTreeArtifactExecPath("foo", null)
- .addCustomMultiArgv((CustomMultiArgv) null)
.build();
assertThat(cl.arguments()).isEmpty();
-
- CustomCommandLine.Builder obj = CustomCommandLine.builder();
- Class<CustomCommandLine.Builder> clazz = CustomCommandLine.Builder.class;
- NullPointerTester npt =
- new NullPointerTester()
- .setDefault(Artifact.class, artifact1)
- .setDefault(String.class, "foo")
- .setDefault(PathFragment[].class, new PathFragment[] {PathFragment.create("foo")});
-
- npt.testMethod(obj, clazz.getMethod("add", String.class, String.class));
- npt.testMethod(
- obj, clazz.getMethod("addPlaceholderTreeArtifactExecPath", String.class, Artifact.class));
- npt.testMethod(obj, clazz.getMethod("addExpandedTreeArtifactExecPaths", Artifact.class));
-
- npt.setDefault(Iterable.class, ImmutableList.of("foo"));
-
- npt.setDefault(Iterable.class, ImmutableList.of(artifact1));
-
- npt.setDefault(Iterable.class, ImmutableList.of(PathFragment.create("foo")));
- npt.setDefault(Artifact.class, treeArtifact);
- npt.testMethod(obj, clazz.getMethod("addExpandedTreeArtifactExecPaths", Artifact.class));
}
@Test
@@ -274,10 +732,11 @@ public class CustomCommandLineTest {
Artifact treeArtifactOne = createTreeArtifact("myArtifact/treeArtifact1");
Artifact treeArtifactTwo = createTreeArtifact("myArtifact/treeArtifact2");
- CustomCommandLine commandLineTemplate = CustomCommandLine.builder()
- .addPlaceholderTreeArtifactExecPath("--argOne", treeArtifactOne)
- .addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo)
- .build();
+ CustomCommandLine commandLineTemplate =
+ builder()
+ .addPlaceholderTreeArtifactExecPath("--argOne", treeArtifactOne)
+ .addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo)
+ .build();
TreeFileArtifact treeFileArtifactOne = createTreeFileArtifact(
treeArtifactOne, "children/child1");
@@ -301,10 +760,11 @@ public class CustomCommandLineTest {
Artifact treeArtifactOne = createTreeArtifact("myArtifact/treeArtifact1");
Artifact treeArtifactTwo = createTreeArtifact("myArtifact/treeArtifact2");
- CustomCommandLine commandLineTemplate = CustomCommandLine.builder()
- .addPlaceholderTreeArtifactExecPath("--argOne", treeArtifactOne)
- .addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo)
- .build();
+ CustomCommandLine commandLineTemplate =
+ builder()
+ .addPlaceholderTreeArtifactExecPath("--argOne", treeArtifactOne)
+ .addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo)
+ .build();
try {
commandLineTemplate.arguments();
@@ -312,7 +772,6 @@ public class CustomCommandLineTest {
} catch (NullPointerException e) {
// expected
}
-
}
private Artifact createTreeArtifact(String rootRelativePath) {
@@ -331,4 +790,28 @@ public class CustomCommandLineTest {
inputTreeArtifact,
PathFragment.create(parentRelativePath));
}
+
+ private static <T> ImmutableList<T> list(T... objects) {
+ return ImmutableList.<T>builder().addAll(Arrays.asList(objects)).build();
+ }
+
+ private static <T> NestedSet<T> nestedSet(T... objects) {
+ return NestedSetBuilder.<T>stableOrder().addAll(Arrays.asList(objects)).build();
+ }
+
+ private static Foo foo(String str) {
+ return new Foo(str);
+ }
+
+ private static class Foo {
+ private final String str;
+
+ Foo(String str) {
+ this.str = str;
+ }
+
+ static String str(Foo foo) {
+ return foo.str;
+ }
+ }
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java
deleted file mode 100644
index c30b0a503b..0000000000
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.analysis.actions;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.Builder;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class CustomCommandLineTest extends BuildViewTestCase {
-
- @Test
- public void testAddBeforeEachPath() {
- CustomCommandLine commandLine =
- new Builder()
- .add("foo")
- .addPaths(
- VectorArg.of(
- ImmutableList.of(
- PathFragment.create("/path1"), PathFragment.create("/path2")))
- .beforeEach("-I"))
- .add("bar")
- .addPaths(VectorArg.of(ImmutableList.<PathFragment>of()).beforeEach("-I"))
- .add("baz")
- .build();
- assertThat(commandLine.arguments())
- .containsExactly("foo", "-I", "/path1", "-I", "/path2", "bar", "baz")
- .inOrder();
- }
-
- @Test
- public void testAddBeforeEach() {
- CustomCommandLine commandLine =
- new Builder()
- .add("foo")
- .add(VectorArg.of(ImmutableList.<String>of()).beforeEach("-D"))
- .add("bar")
- .add(
- VectorArg.of(ImmutableList.of("DEBUG=42", "ENABLE_QUANTUM", "__OBJC__"))
- .beforeEach("-D"))
- .add("baz")
- .build();
- assertThat(commandLine.arguments())
- .containsExactly(
- "foo", "bar", "-D", "DEBUG=42", "-D", "ENABLE_QUANTUM", "-D", "__OBJC__", "baz")
- .inOrder();
- }
-
- @Test
- public void testAddBeforeEachExecPath() throws Exception {
- CustomCommandLine commandLine =
- new Builder()
- .add("foo")
- .addExecPaths(
- VectorArg.of(
- ImmutableList.of(
- getSourceArtifact("pkg/util.a"), getSourceArtifact("pkg2/extra.a")))
- .beforeEach("-l"))
- .add("bar")
- .addExecPaths(VectorArg.of(ImmutableList.<Artifact>of()).beforeEach("-l"))
- .add("baz")
- .build();
- assertThat(commandLine.arguments())
- .containsExactly("foo", "-l", "pkg/util.a", "-l", "pkg2/extra.a", "bar", "baz")
- .inOrder();
- }
-
- @Test
- public void testAddFormatEach() {
- CustomCommandLine commandLine =
- new Builder()
- .add("foo")
- .add(VectorArg.of(ImmutableList.<String>of()).formatEach("-X'%s'"))
- .add("bar")
- .add(VectorArg.of(ImmutableList.of("42", "1011")).formatEach("-X'%s'"))
- .add("baz")
- .build();
- assertThat(commandLine.arguments())
- .containsExactly("foo", "bar", "-X'42'", "-X'1011'", "baz")
- .inOrder();
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java
index 2f789a5d0d..2e84fe7cd4 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java
@@ -133,7 +133,7 @@ public class ParamFileWriteActionTest extends BuildViewTestCase {
return CustomCommandLine.builder()
.add("--flag1")
.add("--flag2")
- .add("--flag3", ImmutableList.of("value1", "value2"))
+ .addAll("--flag3", ImmutableList.of("value1", "value2"))
.build();
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
index 24a977c1db..bbe7aef649 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
@@ -67,7 +67,6 @@ import com.google.devtools.build.lib.analysis.RunfilesSupport;
import com.google.devtools.build.lib.analysis.actions.BinaryFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.Builder;
-import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
@@ -2162,7 +2161,7 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase {
.add("--minimum-deployment-target", minimumOsVersion.toString())
.add("--module")
.add("x")
- .add(VectorArg.of(targetDevices).beforeEach("--target-device"))
+ .addBeforeEach("--target-device", targetDevices)
.add("x/1.storyboard")
.build()
.arguments())
@@ -2185,7 +2184,7 @@ public abstract class ObjcRuleTestCase extends BuildViewTestCase {
.add("--minimum-deployment-target", minimumOsVersion.toString())
.add("--module")
.add("x")
- .add(VectorArg.of(targetDevices).beforeEach("--target-device"))
+ .addBeforeEach("--target-device", targetDevices)
.add("x/ja.lproj/loc.storyboard")
.build()
.arguments())