aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-09-30 00:14:44 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-10-02 10:31:50 +0200
commitf79ea7444787db886118491b4301df110f9022d9 (patch)
tree27436cd028d562db2b7a8fa5a25aa6b9fc0129fd /src/main/java/com
parent9a54b435b44c00d5a70e3d6a2a9a3949e3d00548 (diff)
PiperOrigin-RevId: 170539405
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ApkActionsBuilder.java27
2 files changed, 22 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
index c1b8bd27aa..5f31cc2791 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
@@ -84,6 +84,7 @@ public final class AndroidBinaryOnlyRule implements RuleDefinition {
.exec()
.value(env.getToolsLabel(AndroidRuleClasses.MANIFEST_MERGE_TOOL_LABEL)))
.removeAttribute("data")
+ .advertiseProvider(ApkProvider.class)
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApkActionsBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApkActionsBuilder.java
index 8391c5efa1..8d9d95c59a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ApkActionsBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApkActionsBuilder.java
@@ -47,6 +47,7 @@ public class ApkActionsBuilder {
private Artifact signedApk;
private boolean zipalignApk = false;
private Artifact signingKey;
+ private String artifactLocation;
private final String apkName;
@@ -134,6 +135,12 @@ public class ApkActionsBuilder {
return this;
}
+ /** Sets the output APK instead of creating with a static/standard path. */
+ public ApkActionsBuilder setArtifactLocationDirectory(String artifactLocation) {
+ this.artifactLocation = artifactLocation;
+ return this;
+ }
+
/** Registers the actions needed to build the requested APKs in the rule context. */
public void registerActions(RuleContext ruleContext) {
boolean useSingleJarApkBuilder =
@@ -144,7 +151,7 @@ public class ApkActionsBuilder {
Artifact intermediateUnsignedApk =
unsignedApk != null
? unsignedApk
- : AndroidBinary.getDxArtifact(ruleContext, "unsigned_" + signedApk.getFilename());
+ : getApkArtifact(ruleContext, "unsigned_" + signedApk.getFilename());
if (useSingleJarApkBuilder) {
buildApk(ruleContext, intermediateUnsignedApk);
} else {
@@ -156,8 +163,7 @@ public class ApkActionsBuilder {
// Zipalignment is performed before signing. So if a zipaligned APK is requested, we need an
// intermediate zipaligned-but-not-signed apk artifact.
if (zipalignApk) {
- apkToSign =
- AndroidBinary.getDxArtifact(ruleContext, "zipaligned_" + signedApk.getFilename());
+ apkToSign = getApkArtifact(ruleContext, "zipaligned_" + signedApk.getFilename());
zipalignApk(ruleContext, intermediateUnsignedApk, apkToSign);
}
signApk(ruleContext, apkToSign, signedApk);
@@ -235,8 +241,8 @@ public class ApkActionsBuilder {
/** Registers generating actions for {@code outApk} that build an unsigned APK using SingleJar. */
private void buildApk(RuleContext ruleContext, Artifact outApk) {
- Artifact compressedApk =
- AndroidBinary.getDxArtifact(ruleContext, "compressed_" + outApk.getFilename());
+ Artifact compressedApk = getApkArtifact(ruleContext, "compressed_" + outApk.getFilename());
+
SpawnAction.Builder compressedApkActionBuilder =
new SpawnAction.Builder()
.setMnemonic("ApkBuilder")
@@ -295,7 +301,7 @@ public class ApkActionsBuilder {
if (javaResourceZip != null) {
// The javaResourceZip contains many files that are unwanted in the APK such as .class files.
Artifact extractedJavaResourceZip =
- AndroidBinary.getDxArtifact(ruleContext, "extracted_" + javaResourceZip.getFilename());
+ getApkArtifact(ruleContext, "extracted_" + javaResourceZip.getFilename());
ruleContext.registerAction(
new SpawnAction.Builder()
.setExecutable(resourceExtractor)
@@ -413,4 +419,13 @@ public class ApkActionsBuilder {
builder.setExecutable(singleJar);
}
}
+
+ private Artifact getApkArtifact(RuleContext ruleContext, String baseName) {
+ if (artifactLocation != null) {
+ return ruleContext.getUniqueDirectoryArtifact(artifactLocation, baseName,
+ ruleContext.getBinOrGenfilesDirectory());
+ } else {
+ return AndroidBinary.getDxArtifact(ruleContext, baseName);
+ }
+ }
}