aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-08-15 17:57:39 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-08-16 11:05:17 +0200
commit7481de4637998750a0f0eda2e39d09a5a9f84be9 (patch)
treec1b70e92a488ed963f2822335f9812a481613329 /src/main/java/com/google/devtools/build/lib
parente29cb64e2b47d90f734beb4319d1ac708cb039a6 (diff)
android_library can be used in the resources attribute
This allows us to perform a more gradual migration away from the android_resources rule. Specifically, rather than move all android_resources targets and simultaneously move all resources attributes, we can now first transform all android_resources rules into android_library rules, and then afterwards migrate dependencies on those rules from resources into deps. This allows a two-part migration. The resources attribute, once allowed to take android_library targets, should continue to work exactly as before. There is one change in behavior - for this to work, android_library targets now need to build an output APK during resource processing. This APK will be removed once the resources attribute is removed. Once the migration is complete, the resources attribute will be removed completely. RELNOTES: none PiperOrigin-RevId: 165313447
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java7
3 files changed, 21 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
index 37a42e1584..40ae0972e8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceValidatorActionBuilder.java
@@ -56,6 +56,7 @@ public class AndroidResourceValidatorActionBuilder {
private Artifact aapt2SourceJarOut;
private Artifact aapt2RTxtOut;
private Artifact compiledSymbols;
+ private Artifact apkOut;
/** @param ruleContext The RuleContext that was used to create the SpawnAction.Builder. */
public AndroidResourceValidatorActionBuilder(RuleContext ruleContext) {
@@ -131,6 +132,11 @@ public class AndroidResourceValidatorActionBuilder {
return this;
}
+ public AndroidResourceValidatorActionBuilder setApkOut(Artifact apkOut) {
+ this.apkOut = apkOut;
+ return this;
+ }
+
/**
* This creates a static library using aapt2. It also generates a source jar and R.txt from aapt.
*
@@ -254,6 +260,11 @@ public class AndroidResourceValidatorActionBuilder {
builder.add("--srcJarOutput", sourceJarOut);
outs.add(sourceJarOut);
+ if (apkOut != null) {
+ builder.add("--packagePath", apkOut);
+ outs.add(apkOut);
+ }
+
SpawnAction.Builder spawnActionBuilder = new SpawnAction.Builder();
// Create the spawn action.
ruleContext.registerAction(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
index 88a6e27636..4e1fe7ffdc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
@@ -84,6 +84,10 @@ public final class AndroidRuleClasses {
JavaSemantics.JAVA_LIBRARY_CLASS_JAR;
public static final SafeImplicitOutputsFunction ANDROID_LIBRARY_AAR =
fromTemplates("%{name}.aar");
+ // TODO(b/30307842): Remove this once it is no longer needed for resources migration.
+ public static final SafeImplicitOutputsFunction ANDROID_LIBRARY_APK =
+ fromTemplates("%{name}_files/library.ap_");
+
/**
* Source Jar for {@link #ANDROID_RESOURCES_CLASS_JAR}, which should be the same as
* {@link #ANDROID_JAVA_SOURCE_JAR}.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
index a40afd09dc..01031e9dee 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
@@ -505,7 +505,11 @@ public final class ApplicationManifest {
.setAssetsAndResourcesFrom(data)
.setManifest(getManifest())
.setSymbols(symbols)
- .setRTxt(rTxt);
+ .setRTxt(rTxt)
+ // Request an APK so it can be inherited when a library is used in a binary's
+ // resources attr.
+ // TODO(b/30307842): Remove this once it is no longer needed for resources migration.
+ .setApk(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_APK));
if (targetAaptVersion == AndroidAaptVersion.AAPT2) {
@@ -631,6 +635,7 @@ public final class ApplicationManifest {
.withPrimary(merged)
.setRTxtOut(merged.getRTxt())
.setSourceJarOut(merged.getJavaSourceJar())
+ .setApkOut(resourceContainer.getApk())
// aapt2 related artifacts. Will be generated if the targetAaptVersion is AAPT2.
.withDependencies(resourceDeps)
.setCompiledSymbols(merged.getCompiledSymbols())