aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-06-29 21:43:28 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-30 13:00:30 +0200
commit8b295441b9944eb9b4418c426742caac7ab018c7 (patch)
treee5f94c8612bec8a7c9495bd0bfd44a4e5fd6e3e1 /src/main
parentcae82e617422da5cd61e95a249f4fd44a2d3b0de (diff)
Decrease memory used by SpawnAction's param file builder.
The previous implementation stores a copy of the param file's path fragment with an '@' prepended. This can add up if you have a lot of params files, but can be avoided by deferring that string expansion. PiperOrigin-RevId: 160559793
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLine.java27
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java7
2 files changed, 31 insertions, 3 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 e6f9792637..601229bd14 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
@@ -18,6 +18,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
@@ -196,6 +197,21 @@ public final class CustomCommandLine extends CommandLine {
}
}
+ private static final class ParamFileArgument extends ArgvFragment {
+ private final String paramFilePrefix;
+ private final PathFragment path;
+
+ private ParamFileArgument(String paramFilePrefix, PathFragment path) {
+ this.paramFilePrefix = paramFilePrefix;
+ this.path = path;
+ }
+
+ @Override
+ void eval(ImmutableList.Builder<String> builder) {
+ builder.add(paramFilePrefix + path);
+ }
+ }
+
/**
* An argument object that evaluates to a formatted string for {@link TreeFileArtifact} exec
* paths, enclosing the associated string format template and {@link TreeFileArtifact}s.
@@ -555,6 +571,17 @@ public final class CustomCommandLine extends CommandLine {
}
/**
+ * Adds a param file as an argument.
+ *
+ * @param paramFilePrefix The character that denotes a param file, commonly '@'
+ * @param paramFile The param file artifact
+ */
+ public Builder addParamFile(String paramFilePrefix, Artifact paramFile) {
+ arguments.add(new ParamFileArgument(paramFilePrefix, paramFile.getExecPath()));
+ return this;
+ }
+
+ /**
* Adds a formatted string containing the exec path of a placeholder TreeArtifact. When the
* command line is used in an action template, the placeholder will be replaced by the exec path
* of a {@link TreeFileArtifact} inside the TreeArtifact at execution time for each expanded
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 d1253c98e0..7a3e16b207 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
@@ -89,9 +89,10 @@ public final class ParamFileHelper {
*/
public static CommandLine createWithParamsFile(
List<String> executableArgs, ParamFileInfo paramFileInfo, Artifact parameterFile) {
- String pathWithFlag = paramFileInfo.getFlag() + parameterFile.getExecPathString();
- Iterable<String> commandArgv = Iterables.concat(executableArgs, ImmutableList.of(pathWithFlag));
- return CommandLine.of(commandArgv);
+ return CustomCommandLine.builder()
+ .add(executableArgs)
+ .addParamFile(paramFileInfo.getFlag(), parameterFile)
+ .build();
}
/**