From c03ca7cc8bcef66f8e077c2451e8a9f68ee4733c Mon Sep 17 00:00:00 2001 From: tomlu Date: Mon, 21 Aug 2017 19:26:41 +0200 Subject: Improve CustomCommandLine interface. In converting SpawnAction.Builder (multi-thousand line CL) users directly to CustomCommandLine I didn't like the resulting loss of readability, and the methods didn't feel very discoverable. Unless it's very convenient and readable to use CustomCommandLine, people will resort to non-memory efficient patterns by default. I'm holding that CL for this, which should offer a nicer interface. This CL removes VectorArg from the API contact surface area, instead creating 64 overloads for every valid combination of parameters. Pretty sad, but the methods dispatch straight to internal helper methods so it's mostly boilerplate to the tune of +400 LOC. Other changes: * Change ImmutableCollection -> Collection and copy the args directly into the internal args vector. Saves on collection object overhead and saves users from having to create immutable copies. * Change some names, notably add -> addAll for collection methods * Create additional missing overloads * Fix JavaDoc RELNOTES: None PiperOrigin-RevId: 165943879 --- .../lib/analysis/actions/CustomCommandLine.java | 862 ++++++++++++++++----- .../lib/analysis/actions/ParamFileHelper.java | 2 +- .../build/lib/analysis/actions/SpawnAction.java | 4 +- .../bazel/rules/python/BazelPythonSemantics.java | 2 +- .../build/lib/rules/android/AndroidBinary.java | 7 +- .../lib/rules/android/AndroidLocalTestBase.java | 11 +- .../AndroidResourceValidatorActionBuilder.java | 6 +- .../android/AndroidResourcesProcessorBuilder.java | 10 +- .../build/lib/rules/android/DexArchiveAspect.java | 7 +- .../android/RClassGeneratorActionBuilder.java | 9 +- .../rules/android/ResourceContainerConverter.java | 15 +- .../android/ResourceShrinkerActionBuilder.java | 10 +- .../RobolectricResourceSymbolsActionBuilder.java | 9 +- .../build/lib/rules/java/DeployArchiveBuilder.java | 2 +- .../build/lib/rules/java/JavaCompileAction.java | 24 +- .../lib/rules/java/JavaHeaderCompileAction.java | 10 +- .../rules/java/OneVersionCheckActionBuilder.java | 5 +- .../lib/rules/java/SingleJarActionBuilder.java | 2 +- .../build/lib/rules/objc/BundleSupport.java | 4 +- .../build/lib/rules/objc/CompilationSupport.java | 26 +- .../build/lib/rules/objc/J2ObjcAspect.java | 23 +- .../lib/rules/objc/LegacyCompilationSupport.java | 56 +- .../build/lib/rules/objc/ProtobufSupport.java | 3 +- .../lib/rules/proto/ProtoCompileActionBuilder.java | 6 +- 24 files changed, 787 insertions(+), 328 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib') 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. * - *

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}. + *

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 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 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 arguments, int argi, ImmutableList.Builder builder) { - Iterable values = (Iterable) arguments.get(argi++); - List mutatedValues = Lists.newArrayList(values); - int count = mutatedValues.size(); + final List mutatedValues; + final int count; + if (isNestedSet) { + Iterable values = (Iterable) 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 mapFn = (Function) arguments.get(argi++); for (int i = 0; i < count; ++i) { @@ -177,11 +201,11 @@ public final class CustomCommandLine extends CommandLine { return argi; } - public static Builder of(@Nullable ImmutableCollection values) { + static Builder of(@Nullable Collection values) { return new Builder<>(values); } - public static Builder of(@Nullable NestedSet values) { + static Builder of(@Nullable NestedSet values) { return new Builder<>(values); } @@ -189,22 +213,27 @@ public final class CustomCommandLine extends CommandLine { public static class Builder { @Nullable private final Iterable values; private final boolean isEmpty; + private final boolean isNestedSet; + private final int count; private String formatEach; private String beforeEach; private Function mapFn; private String joinWith; - private Builder(@Nullable ImmutableCollection values) { - this(values, values == null || values.isEmpty()); + private Builder(@Nullable Collection values) { + this(values, values == null || values.isEmpty(), false, values != null ? values.size() : 0); } private Builder(@Nullable NestedSet values) { - this(values, values == null || values.isEmpty()); + this(values, values == null || values.isEmpty(), true, -1); } - private Builder(@Nullable Iterable values, boolean isEmpty) { + private Builder( + @Nullable Iterable 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 joinWith(@CompileTimeConstant String delimiter) { + public Builder joinWith(String delimiter) { Preconditions.checkNotNull(delimiter); this.joinWith = delimiter; return this; } - /** - * Once all arguments have been evaluated, they are joined with this delimiter - * - *

Prefer use of {@link Builder#joinWith} to this method, as it will be more memory - * efficient. - */ - public Builder 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. * - *

{@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. + *

{@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. * - *

{@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} + *

{@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} * - *

{@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} + *

{@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 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. + * + *

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. * *

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 values) { - return addImmutableCollectionInternal(values); + public Builder addAll(@Nullable Collection values) { + return addCollectionInternal(values); } /** Adds the passed paths to the command line. */ - public Builder addPaths(@Nullable ImmutableCollection values) { - return addImmutableCollectionInternal(values); + public Builder addPaths(@Nullable Collection 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)}. */ - public Builder addExecPaths(@Nullable ImmutableCollection values) { - return addImmutableCollectionInternal(values); + public Builder addExecPaths(@Nullable Collection 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 Builder addAll(@Nullable Collection values, Function mapFn) { + return addVectorArgInternal(VectorArg.of(values).mapEach(mapFn)); } - /** Adds the passed strings to the command line. */ - public Builder add(@Nullable NestedSet values) { + /** + * Adds the passed strings to the command line. + * + *

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 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. - * - *

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 Builder addAll(@Nullable NestedSet values, Function mapFn) { + return addVectorArgInternal(VectorArg.of(values).mapEach(mapFn)); } /** @@ -658,9 +674,8 @@ public final class CustomCommandLine extends CommandLine { * *

If values is empty, the arg isn't added. */ - public Builder add( - @CompileTimeConstant String arg, @Nullable ImmutableCollection values) { - return addImmutableCollectionInternal(arg, values); + public Builder addAll(@CompileTimeConstant String arg, @Nullable Collection values) { + return addCollectionInternal(arg, values); } /** @@ -669,8 +684,8 @@ public final class CustomCommandLine extends CommandLine { *

If values is empty, the arg isn't added. */ public Builder addPaths( - @CompileTimeConstant String arg, @Nullable ImmutableCollection values) { - return addImmutableCollectionInternal(arg, values); + @CompileTimeConstant String arg, @Nullable Collection values) { + return addCollectionInternal(arg, values); } /** @@ -683,18 +698,20 @@ public final class CustomCommandLine extends CommandLine { *

If values is empty, the arg isn't added. */ public Builder addExecPaths( - @CompileTimeConstant String arg, @Nullable ImmutableCollection values) { - return addImmutableCollectionInternal(arg, values); + @CompileTimeConstant String arg, @Nullable Collection 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. + * + *

If values is empty, the arg isn't added. + */ + public Builder addAll( + @CompileTimeConstant String arg, + @Nullable Collection values, + Function mapFn) { + return addVectorArgInternal(arg, VectorArg.of(values).mapEach(mapFn)); } /** @@ -702,7 +719,7 @@ public final class CustomCommandLine extends CommandLine { * *

If values is empty, the arg isn't added. */ - public Builder add(@CompileTimeConstant String arg, @Nullable NestedSet values) { + public Builder addAll(@CompileTimeConstant String arg, @Nullable NestedSet 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. + * + *

If values is empty, the arg isn't added. + */ + public Builder addAll( + @CompileTimeConstant String arg, @Nullable NestedSet values, Function mapFn) { + return addVectorArgInternal(arg, VectorArg.of(values).mapEach(mapFn)); + } + + /** Adds the values joined with the supplied string. */ + public Builder addJoined(String delimiter, Collection values) { + return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the path strings joined with the supplied string. */ + public Builder addJoinedPaths(String delimiter, Collection values) { + return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the exec path strings joined with the supplied string. */ + public Builder addJoinedExecPaths(String delimiter, Collection values) { + return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the mapped values joined with the supplied string. */ + public Builder addJoined( + String delimiter, Collection values, Function mapFn) { + return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter).mapEach(mapFn)); + } + + /** Adds the values joined with the supplied string. */ + public Builder addJoined(String delimiter, NestedSet values) { + return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the path strings joined with the supplied string. */ + public Builder addJoinedPaths(String delimiter, NestedSet values) { + return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the exec path strings joined with the supplied string. */ + public Builder addJoinedExecPaths(String delimiter, NestedSet values) { + return addVectorArgInternal(VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the mapped values joined with the supplied string. */ + public Builder addJoined(String delimiter, NestedSet values, Function 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 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 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 values) { + return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the mapped values joined with the supplied string. */ + public Builder addJoined( + @CompileTimeConstant String arg, + String delimiter, + Collection values, + Function 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 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 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 values) { + return addVectorArgInternal(arg, VectorArg.of(values).joinWith(delimiter)); + } + + /** Adds the mapped values joined with the supplied string. */ + public Builder addJoined( + @CompileTimeConstant String arg, + String delimiter, + NestedSet values, + Function 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 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 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 values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr)); + } + + /** Adds the mapped values with each value formatted by the supplied format string. */ + public Builder addFormatEach( + @CompileTimeConstant String formatStr, Collection values, Function 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 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 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 values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr)); + } + + /** Adds the mapped values with each value formatted by the supplied format string. */ + public Builder addFormatEach( + @CompileTimeConstant String formatStr, NestedSet values, Function 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 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 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 values) { + return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr)); + } + + /** Adds the mapped values with each value formatted by the supplied format string. */ + public Builder addFormatEach( + @CompileTimeConstant String arg, + @CompileTimeConstant String formatStr, + Collection values, + Function 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 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 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 values) { + return addVectorArgInternal(arg, VectorArg.of(values).formatEach(formatStr)); + } + + /** Adds the mapped values with each value formatted by the supplied format string. */ + public Builder addFormatEach( + @CompileTimeConstant String arg, + @CompileTimeConstant String formatStr, + NestedSet values, + Function 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 values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter)); } /** - * Adds the expansion of the passed vector arg. - * - *

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 vectorArg) { - return addVectorArgInternal(vectorArg); + public Builder addFormatEachPathJoined( + @CompileTimeConstant String formatStr, String delimiter, Collection values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter)); } /** - * Adds the expansion of the passed vector arg's path strings. - * - *

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 vectorArg) { - return addVectorArgInternal(vectorArg); + public Builder addFormatEachExecPathJoined( + @CompileTimeConstant String formatStr, String delimiter, Collection values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter)); } /** - * Adds the expansion of the passed vector arg's exec paths. - * - *

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 vectorArg) { - return addVectorArgInternal(vectorArg); + public Builder addFormatEachJoined( + @CompileTimeConstant String formatStr, + String delimiter, + Collection values, + Function 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 values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter)); } /** - * Adds the arg followed by the expansion of the vector arg. - * - *

Please see {@link VectorArg} for more information. - * - *

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 vectorArg) { - return addVectorArgInternal(arg, vectorArg); + public Builder addFormatEachPathJoined( + @CompileTimeConstant String formatStr, String delimiter, NestedSet values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter)); } /** - * Adds the arg followed by the expansion of the vector arg's path strings. - * - *

Please see {@link VectorArg} for more information. - * - *

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 vectorArg) { - return addVectorArgInternal(arg, vectorArg); + public Builder addFormatEachExecPathJoined( + @CompileTimeConstant String formatStr, String delimiter, NestedSet values) { + return addVectorArgInternal(VectorArg.of(values).formatEach(formatStr).joinWith(delimiter)); } /** - * Adds the arg followed by the expansion of the vector arg's exec paths. - * - *

Please see {@link VectorArg} for more information. - * - *

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 vectorArg) { - return addVectorArgInternal(arg, vectorArg); + public Builder addFormatEachJoined( + @CompileTimeConstant String formatStr, + String delimiter, + NestedSet values, + Function 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 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 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 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 Builder addFormatEachJoined( + @CompileTimeConstant String arg, + @CompileTimeConstant String formatStr, + String delimiter, + Collection values, + Function 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 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 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 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 Builder addFormatEachJoined( + @CompileTimeConstant String arg, + @CompileTimeConstant String formatStr, + String delimiter, + NestedSet values, + Function 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 values) { + return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach)); + } + + /** Adds the beforeEach string and the path strings interspersed. */ + public Builder addBeforeEachPath( + @CompileTimeConstant String beforeEach, Collection 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 values) { + return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach)); + } + + /** Adds the beforeEach string and the mapped values interspersed. */ + public Builder addBeforeEach( + @CompileTimeConstant String beforeEach, Collection values, Function 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 values) { + return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach)); + } + + /** Adds the beforeEach string and the path strings interspersed. */ + public Builder addBeforeEachPath( + @CompileTimeConstant String beforeEach, NestedSet 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 values) { + return addVectorArgInternal(VectorArg.of(values).beforeEach(beforeEach)); + } + + /** Adds the beforeEach string and the values interspersed. */ + public Builder addBeforeEach( + @CompileTimeConstant String beforeEach, NestedSet values, Function 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 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 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 values) { + return addVectorArgInternal( + VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr)); + } + + /** Adds the beforeEach string and the mapped values interspersed. */ + public Builder addBeforeEachFormatted( + @CompileTimeConstant String beforeEach, + @CompileTimeConstant String formatStr, + Collection values, + Function 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 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 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 values) { + return addVectorArgInternal( + VectorArg.of(values).beforeEach(beforeEach).formatEach(formatStr)); + } + + /** Adds the beforeEach string and the mapped values interspersed. */ + public Builder addBeforeEachFormatted( + @CompileTimeConstant String beforeEach, + @CompileTimeConstant String formatStr, + NestedSet values, + Function 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 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 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 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 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.builder() - .addAll(instrumentationJars) - .add(javaBuilderJar) - .build()) - .joinWithDynamicString(pathDelimiter)) + pathDelimiter, + ImmutableList.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 resources, Iterable 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 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 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 translationFlags = ruleContext .getFragment(J2ObjcConfiguration.class) .getTranslationFlags(); - argBuilder.add(ImmutableList.copyOf(translationFlags)); + argBuilder.addAll(ImmutableList.copyOf(translationFlags)); NestedSet 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 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 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)); -- cgit v1.2.3