aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2017-04-18 20:18:04 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-04-19 10:47:15 +0200
commit8b715ee304268138cf2725f6049598299cebb9ed (patch)
treefc501f3d4688b947665135e0e38151d1bb3897a1
parent5b286da29320308b9d02d4066abdf34c070ae64c (diff)
Skip params file handling for resource jar actions with short command lines
PiperOrigin-RevId: 153485708
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/ResourceJarActionBuilder.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/ResourceJarActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/ResourceJarActionBuilder.java
index 29332622a1..a549af3665 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/ResourceJarActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/ResourceJarActionBuilder.java
@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
@@ -119,6 +120,17 @@ public class ResourceJarActionBuilder {
if (!classpathResources.isEmpty()) {
command.addExecPaths("--classpath_resources", classpathResources);
}
+ // TODO(b/37444705): remove this logic and always call useParameterFile once the bug is fixed
+ // Most resource jar actions are very small and expanding the argument list for
+ // ParamFileHelper#getParamsFileMaybe is expensive, so avoid doing that work if
+ // we definitely don't need a params file.
+ // This heuristic could be much more aggressive, but we don't ever want to skip
+ // the params file in situations where it is required for --min_param_file_size.
+ if (sizeGreaterThanOrEqual(
+ Iterables.concat(messages, resources.values(), resourceJars, classpathResources), 10)
+ || ruleContext.getConfiguration().getMinParamFileSize() < 10000) {
+ builder.useParameterFile(ParameterFileType.SHELL_QUOTED);
+ }
ruleContext.registerAction(
builder
.addOutput(outputJar)
@@ -126,13 +138,16 @@ public class ResourceJarActionBuilder {
.addInputs(resources.values())
.addTransitiveInputs(resourceJars)
.addInputs(classpathResources)
- .useParameterFile(ParameterFileType.SHELL_QUOTED)
.setCommandLine(command.build())
.setProgressMessage("Building Java resource jar")
.setMnemonic("JavaResourceJar")
.build(ruleContext));
}
+ boolean sizeGreaterThanOrEqual(Iterable<?> elements, int size) {
+ return Iterables.size(Iterables.limit(elements, size)) == size;
+ }
+
private static void addAsResourcePrefixedExecPath(
PathFragment resourcePath, Artifact artifact, CustomCommandLine.Builder builder) {
PathFragment execPath = artifact.getExecPath();