use of com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder in project bazel by bazelbuild.
the class AndroidBinary method singleJarSpawnActionBuilder.
// Adds the appropriate SpawnAction options depending on if SingleJar is a jar or not.
private static SpawnAction.Builder singleJarSpawnActionBuilder(RuleContext ruleContext) {
Artifact singleJar = JavaToolchainProvider.fromRuleContext(ruleContext).getSingleJar();
SpawnAction.Builder builder = new SpawnAction.Builder();
if (singleJar.getFilename().endsWith(".jar")) {
builder.setJarExecutable(ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable(), singleJar, JavaToolchainProvider.fromRuleContext(ruleContext).getJvmOptions()).addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext));
} else {
builder.setExecutable(singleJar);
}
return builder;
}
use of com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder in project bazel by bazelbuild.
the class ProguardHelper method createProguardAction.
/**
* Creates an action to run Proguard over the given {@code programJar} with various other given
* inputs to produce {@code proguardOutputJar}. If requested explicitly, or implicitly with
* --java_optimization_mode, the action also produces a mapping file (which shows what methods and
* classes in the output Jar correspond to which methods and classes in the input). The "pair"
* returned by this method indicates whether a mapping is being produced.
*
* <p>See the Proguard manual for the meaning of the various artifacts in play.
*
* @param proguard Proguard executable to use
* @param proguardSpecs Proguard specification files to pass to Proguard
* @param proguardMapping optional mapping file for Proguard to apply
* @param libraryJars any other Jar files that the {@code programJar} will run against
* @param mappingRequested whether to ask Proguard to output a mapping file (a mapping will be
* produced anyway if --java_optimization_mode includes obfuscation)
* @param optimizationPasses if not null specifies to break proguard up into multiple passes with
* the given number of optimization passes.
* @param proguardOutputMap mapping generated by Proguard if requested. could be null.
* @param useSingleJarForProguardLibraryJars whether to combine all library jars into a single jar
* file before processing with Proguard
*/
public static ProguardOutput createProguardAction(RuleContext ruleContext, FilesToRunProvider proguard, Artifact programJar, ImmutableList<Artifact> proguardSpecs, @Nullable Artifact proguardSeeds, @Nullable Artifact proguardUsage, @Nullable Artifact proguardMapping, Iterable<Artifact> libraryJars, Artifact proguardOutputJar, JavaSemantics semantics, @Nullable Integer optimizationPasses, @Nullable Artifact proguardOutputMap, boolean useSingleJarForProguardLibraryJars) throws InterruptedException {
JavaOptimizationMode optMode = getJavaOptimizationMode(ruleContext);
Preconditions.checkArgument(optMode != JavaOptimizationMode.NOOP);
Preconditions.checkArgument(optMode != JavaOptimizationMode.LEGACY || !proguardSpecs.isEmpty());
ProguardOutput output = getProguardOutputs(proguardOutputJar, proguardSeeds, proguardUsage, ruleContext, semantics, proguardOutputMap);
if (useSingleJarForProguardLibraryJars && Iterables.size(libraryJars) > 1) {
JavaTargetAttributes attributes = new JavaTargetAttributes.Builder(semantics).build();
Artifact combinedLibraryJar = getProguardTempArtifact(ruleContext, optMode.name().toLowerCase(), "combined_library_jars.jar");
new DeployArchiveBuilder(semantics, ruleContext).setOutputJar(combinedLibraryJar).setAttributes(attributes).addRuntimeJars(libraryJars).build();
libraryJars = ImmutableList.of(combinedLibraryJar);
}
if (optimizationPasses == null) {
// Run proguard as a single step.
Builder builder = makeBuilder(proguard, programJar, proguardSpecs, proguardMapping, libraryJars, output.getOutputJar(), output.getMapping(), output.getProtoMapping(), output.getSeeds(), output.getUsage(), output.getConstantStringObfuscatedMapping(), output.getConfig()).setProgressMessage("Trimming binary with Proguard").addOutput(proguardOutputJar);
ruleContext.registerAction(builder.build(ruleContext));
} else {
// Optimization passes have been specified, so run proguard in multiple phases.
Artifact lastStageOutput = getProguardTempArtifact(ruleContext, optMode.name().toLowerCase(), "proguard_preoptimization.jar");
ruleContext.registerAction(makeBuilder(proguard, programJar, proguardSpecs, proguardMapping, libraryJars, output.getOutputJar(), /* proguardOutputMap */
null, /* proguardOutputProtoMap */
null, // ProGuard only prints seeds during INITIAL and NORMAL runtypes.
output.getSeeds(), /* proguardUsage */
null, /* constantStringObfuscatedMapping */
null, /* proguardConfigOutput */
null).setProgressMessage("Trimming binary with Proguard: Verification/Shrinking Pass").addArgument("-runtype INITIAL").addArgument("-nextstageoutput").addOutputArgument(lastStageOutput).build(ruleContext));
for (int i = 0; i < optimizationPasses; i++) {
Artifact optimizationOutput = getProguardTempArtifact(ruleContext, optMode.name().toLowerCase(), "proguard_optimization_" + (i + 1) + ".jar");
ruleContext.registerAction(makeBuilder(proguard, programJar, proguardSpecs, proguardMapping, libraryJars, output.getOutputJar(), /* proguardOutputMap */
null, /* proguardOutputProtoMap */
null, /* proguardSeeds */
null, /* proguardUsage */
null, /* constantStringObfuscatedMapping */
null, /* proguardConfigOutput */
null).setProgressMessage("Trimming binary with Proguard: Optimization Pass " + (i + 1)).addArgument("-runtype OPTIMIZATION").addArgument("-laststageoutput").addInputArgument(lastStageOutput).addArgument("-nextstageoutput").addOutputArgument(optimizationOutput).build(ruleContext));
lastStageOutput = optimizationOutput;
}
Builder builder = makeBuilder(proguard, programJar, proguardSpecs, proguardMapping, libraryJars, output.getOutputJar(), output.getMapping(), output.getProtoMapping(), // runtype FINAL does not produce seeds.
null, /* proguardSeeds */
output.getUsage(), output.getConstantStringObfuscatedMapping(), output.getConfig()).setProgressMessage("Trimming binary with Proguard: Obfuscation and Final Output Pass").addArgument("-runtype FINAL").addArgument("-laststageoutput").addInputArgument(lastStageOutput).addOutput(proguardOutputJar);
ruleContext.registerAction(builder.build(ruleContext));
}
return output;
}
Aggregations