Skip to content

Commit

Permalink
Skip params file handling for resource jar actions with short command…
Browse files Browse the repository at this point in the history
… lines

PiperOrigin-RevId: 153485708
  • Loading branch information
cushon authored and aehlig committed Apr 19, 2017
1 parent 5b286da commit 8b715ee
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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;
Expand Down Expand Up @@ -119,20 +120,34 @@ public void build(JavaSemantics semantics, RuleContext ruleContext) {
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)
.addInputs(messages)
.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();
Expand Down

0 comments on commit 8b715ee

Please sign in to comment.