From 8b715ee304268138cf2725f6049598299cebb9ed Mon Sep 17 00:00:00 2001 From: cushon Date: Tue, 18 Apr 2017 20:18:04 +0200 Subject: Skip params file handling for resource jar actions with short command lines PiperOrigin-RevId: 153485708 --- .../build/lib/rules/java/ResourceJarActionBuilder.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/google/devtools') 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(); -- cgit v1.2.3