Skip to content

Commit

Permalink
Allow proguard whitelister to be a deploy jar
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 342357126
  • Loading branch information
cushon authored and copybara-github committed Nov 14, 2020
1 parent 3edc5af commit 4e71d54
Showing 1 changed file with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public NestedSet<Artifact> collectProguardSpecs(Iterable<String> attributes) {
return specsBuilder.build();
}
for (Artifact specToValidate : localSpecs) {
specsBuilder.add(validateProguardSpec(proguardAllowlister, specToValidate));
specsBuilder.add(validateProguardSpec(ruleContext, proguardAllowlister, specToValidate));
}
}

Expand Down Expand Up @@ -109,7 +109,7 @@ private NestedSet<Artifact> collectProguardSpecsFromAttribute(String attributeNa
* validated Proguard spec, ready to be exported.
*/
private Artifact validateProguardSpec(
FilesToRunProvider proguardAllowlister, Artifact specToValidate) {
RuleContext ruleContext, FilesToRunProvider proguardAllowlister, Artifact specToValidate) {
// If we're validating j/a/b/testapp/proguard.cfg, the output will be:
// j/a/b/testapp/proguard.cfg_valid
Artifact output =
Expand All @@ -119,19 +119,29 @@ private Artifact validateProguardSpec(
.getRootRelativePath()
.replaceName(specToValidate.getFilename() + "_valid"),
ruleContext.getBinOrGenfilesDirectory());
ruleContext.registerAction(
new SpawnAction.Builder()
.addInput(specToValidate)
.addOutput(output)
.setExecutable(proguardAllowlister)
.setProgressMessage("Validating proguard configuration")
.setMnemonic("ValidateProguard")
.addCommandLine(
CustomCommandLine.builder()
.addExecPath("--path", specToValidate)
.addExecPath("--output", output)
.build())
.build(ruleContext));
SpawnAction.Builder builder =
new SpawnAction.Builder().addInput(specToValidate).addOutput(output);
if (proguardAllowlister.getExecutable().getExtension().equals("jar")) {
builder
.setJarExecutable(
JavaCommon.getHostJavaExecutable(ruleContext),
proguardAllowlister.getExecutable(),
JavaToolchainProvider.from(ruleContext).getJvmOptions())
.addTransitiveInputs(JavaRuntimeInfo.forHost(ruleContext).javaBaseInputsMiddleman());
} else {
// TODO(b/170769708): remove this branch and require java_toolchain.proguard_allowlister to
// always be a _deploy.jar
builder.setExecutable(proguardAllowlister);
}
builder
.setProgressMessage("Validating proguard configuration")
.setMnemonic("ValidateProguard")
.addCommandLine(
CustomCommandLine.builder()
.addExecPath("--path", specToValidate)
.addExecPath("--output", output)
.build());
ruleContext.registerAction(builder.build(ruleContext));
return output;
}
}

0 comments on commit 4e71d54

Please sign in to comment.