Skip to content

Commit

Permalink
Propagate tags for the AndroidBinary actions
Browse files Browse the repository at this point in the history
    Tags are not propagated from targets to actions for Android rules. bazelbuild/bazel#8830

    This PR adds basic propagation of tags from the android_binary target it's actions.

    Testing with aquery with the Android repo:

    ```
    bazel aquery 'mnemonic(RClassGenerator, //apps/foo)'
    bazel aquery 'mnemonic(JavaDeployJar, //apps/foo)'
    bazel aquery 'mnemonic(ApkBuilder, //apps/foo)'
    ```

    Closes #13093.

    PiperOrigin-RevId: 360836954
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent afcbfc5 commit e4f1299
Show file tree
Hide file tree
Showing 6 changed files with 519 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ static Artifact createMainDexListAction(
Artifact jar,
@Nullable Artifact mainDexProguardSpec,
@Nullable Artifact proguardOutputMap)
throws InterruptedException, RuleErrorException {
throws InterruptedException {
AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext);
// Create the main dex classes list.
Artifact mainDexList = AndroidBinary.getDxArtifact(ruleContext, "main_dex_list.txt");
Expand All @@ -1841,11 +1841,6 @@ static Artifact createMainDexListAction(
// legacy_main_dex_list_generator is provided, use that tool instead.
// TODO(b/147692286): Remove the old main-dex list generation that relied on ProGuard.
if (legacyMainDexListGenerator == null) {
if (sdk.getShrinkedAndroidJar() == null) {
ruleContext.throwWithRuleError(
"In \"legacy\" multidex mode, either legacy_main_dex_list_generator or "
+ "shrinked_android_jar must be set in the android_sdk.");
}
// Process the input jar through Proguard into an intermediate, streamlined jar.
Artifact strippedJar = AndroidBinary.getDxArtifact(ruleContext, "main_dex_intermediate.jar");
SpawnAction.Builder streamlinedBuilder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public void registerAction(SpawnAction.Builder spawnActionBuilder) {
registerAction(spawnActionBuilder.build(ruleContext));
}

/** Registers an action. */
public void registerAction(ActionAnalysisMetadata action) {
ruleContext.registerAction(action);
/** Registers one or more actions. */
public void registerAction(ActionAnalysisMetadata... actions) {
ruleContext.registerAction(actions);
}

public Artifact createOutputArtifact(SafeImplicitOutputsFunction function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class ApkActionsBuilder {
private Artifact signingLineage;
private String artifactLocation;
private Artifact v4SignatureFile;
private boolean deterministicSigning;

private final String apkName;

Expand Down Expand Up @@ -154,11 +153,6 @@ public ApkActionsBuilder setArtifactLocationDirectory(String artifactLocation) {
return this;
}

public ApkActionsBuilder setDeterministicSigning(boolean deterministicSigning) {
this.deterministicSigning = deterministicSigning;
return this;
}

/** Registers the actions needed to build the requested APKs in the rule context. */
public void registerActions(RuleContext ruleContext) {
// If the caller did not request an unsigned APK, we still need to construct one so that
Expand Down Expand Up @@ -347,18 +341,6 @@ private void signApk(
actionBuilder.addInput(signingLineage);
commandLine.add("--lineage").addExecPath(signingLineage);
}

if (deterministicSigning) {
// Enable deterministic DSA signing to keep the output of apksigner deterministic.
// This requires including BouncyCastleProvider as a Security provider, since the standard
// JDK Security providers do not include support for deterministic DSA signing.
// Since this adds BouncyCastleProvider to the end of the Provider list, any non-DSA signing
// algorithms (such as RSA) invoked by apksigner will still use the standard JDK
// implementations and not Bouncy Castle.
commandLine.add("--deterministic-dsa-signing", "true");
commandLine.add("--provider-class", "org.bouncycastle.jce.provider.BouncyCastleProvider");
}

for (int i = 0; i < signingKeys.size(); i++) {
if (i > 0) {
commandLine.add("--next-signer");
Expand Down
Loading

0 comments on commit e4f1299

Please sign in to comment.