Skip adding omitted vector arguments to StarlarkCommandLine when they are empty
This implementation matches how non-Starlark SpawnAction command lines are generated.
We can peek into NestedSet or List if they are empty without incurring any cost.
@@ -430,23 +430,29 @@ public abstract class Args implements CommandLineArgsApi {
String terminateWith,
Location loc)
throws EvalException {
+ validateFormatString("format_each", formatEach);
+ validateFormatString("format_joined", formatJoined);
StarlarkCustomCommandLine.VectorArg.Builder vectorArg;
if (value instanceof Depset) {
Depset starlarkNestedSet = (Depset) value;
NestedSet<?> nestedSet = starlarkNestedSet.getSet();
+ if (nestedSet.isEmpty() && omitIfEmpty) {
+ return;
+ }
if (expandDirectories) {
potentialDirectoryArtifacts.add(nestedSet);
}
vectorArg = new StarlarkCustomCommandLine.VectorArg.Builder(nestedSet);
} else {
Sequence<?> starlarkList = (Sequence) value;
+ if (starlarkList.isEmpty() && omitIfEmpty) {
+ return;
+ }
if (expandDirectories) {
scanForDirectories(starlarkList);
}
vectorArg = new StarlarkCustomCommandLine.VectorArg.Builder(starlarkList);
}
- validateFormatString("format_each", formatEach);
- validateFormatString("format_joined", formatJoined);
vectorArg
.setLocation(loc)
.setArgName(argName)
