aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
diff options
context:
space:
mode:
authorGravatar asteinb <asteinb@google.com>2018-04-18 07:46:20 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-18 07:47:34 -0700
commit9e76d242beb562e8337caf5529f0e6a151399b28 (patch)
tree05e47c8e94e4749a69c21596af41cb76e8e79243 /src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
parent83da8ccd5716f5be19f9be8e36949c58a3f741eb (diff)
Ability to stop using ResourceContainer in various actions
Now that we support decoupled asset and resource processing in the basic pipeline, we can also support it in these actions. ResourceShrinker actions, by design, does not use assets, so the change is trivial. For the AarGenerator, things get a bit more complex: - Simplify needlessly complex code around AAR generation - Move around special resource processing to generate AAR inputs in the case where there are no local resources to go next to normal resource processing - Also, clean up that code - ResourceApk wrapper class has some fields which are non-null even in the case where resources are inherited - Always pass assets and resources seperately to the AarGenerator action RELNOTES: none PiperOrigin-RevId: 193355790
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java113
1 files changed, 97 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
index 2a43b64fc5..21c517fcb2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
@@ -16,6 +16,8 @@ package com.google.devtools.build.lib.rules.android;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.OutputGroupInfo;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
+import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.config.CompilationMode;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import javax.annotation.Nullable;
@@ -34,10 +36,17 @@ public final class ResourceApk {
@Nullable private final Artifact resourceJavaClassJar; // Class jar containing R.class files
private final ResourceDependencies resourceDeps;
private final AssetDependencies assetDeps;
- @Nullable private final ResourceContainer primaryResources;
- @Nullable private final AndroidAssets primaryAssets;
+ /**
+ * Validated Android resource information. Will be null when this class is built from transitive
+ * resources only, and will be a superset of primaryResources otherwise.
+ */
+ @Nullable private final ValidatedAndroidData validatedResources;
- @Nullable private final Artifact manifest; // The non-binary XML version of AndroidManifest.xml
+ private final AndroidResources primaryResources;
+ private final AndroidAssets primaryAssets;
+
+ private final Artifact manifest; // The non-binary XML version of AndroidManifest.xml
+ private final Artifact rTxt;
@Nullable private final Artifact resourceProguardConfig;
@Nullable private final Artifact mainDexProguardConfig;
@@ -57,21 +66,41 @@ public final class ResourceApk {
resourceDeps,
AssetDependencies.empty(),
resourceContainer,
+ resourceContainer.getAndroidResources(),
resourceContainer.getAndroidAssets(),
resourceContainer.getManifest(),
+ resourceContainer.getRTxt(),
resourceProguardConfig,
mainDexProguardConfig);
}
+ public static ResourceApk of(ValidatedAndroidResources resources, MergedAndroidAssets assets) {
+ return new ResourceApk(
+ resources.getApk(),
+ resources.getJavaSourceJar(),
+ resources.getJavaClassJar(),
+ resources.getResourceDependencies(),
+ assets.getAssetDependencies(),
+ resources,
+ resources,
+ assets,
+ resources.getManifest(),
+ resources.getRTxt(),
+ null,
+ null);
+ }
+
private ResourceApk(
@Nullable Artifact resourceApk,
@Nullable Artifact resourceJavaSrcJar,
@Nullable Artifact resourceJavaClassJar,
ResourceDependencies resourceDeps,
AssetDependencies assetDeps,
- @Nullable ResourceContainer primaryResources,
- @Nullable AndroidAssets primaryAssets,
- @Nullable Artifact manifest,
+ @Nullable ValidatedAndroidData validatedResources,
+ AndroidResources primaryResources,
+ AndroidAssets primaryAssets,
+ Artifact manifest,
+ Artifact rTxt,
@Nullable Artifact resourceProguardConfig,
@Nullable Artifact mainDexProguardConfig) {
this.resourceApk = resourceApk;
@@ -79,9 +108,11 @@ public final class ResourceApk {
this.resourceJavaClassJar = resourceJavaClassJar;
this.resourceDeps = resourceDeps;
this.assetDeps = assetDeps;
+ this.validatedResources = validatedResources;
this.primaryResources = primaryResources;
this.primaryAssets = primaryAssets;
this.manifest = manifest;
+ this.rTxt = rTxt;
this.resourceProguardConfig = resourceProguardConfig;
this.mainDexProguardConfig = mainDexProguardConfig;
}
@@ -93,9 +124,11 @@ public final class ResourceApk {
resourceJavaClassJar,
resourceDeps,
assetDeps,
+ validatedResources,
primaryResources,
primaryAssets,
manifest,
+ rTxt,
resourceProguardConfig,
mainDexProguardConfig);
}
@@ -104,14 +137,15 @@ public final class ResourceApk {
return resourceApk;
}
- public ResourceContainer getPrimaryResources() {
+ @Nullable
+ public ValidatedAndroidData getValidatedResources() {
+ return validatedResources;
+ }
+
+ public AndroidResources getPrimaryResources() {
return primaryResources;
}
- /**
- * TODO(b/77574966): Use MergedAndroidAssets rather than the base class once we have completely
- * decoupled assets and resources.
- */
public AndroidAssets getPrimaryAssets() {
return primaryAssets;
}
@@ -120,6 +154,10 @@ public final class ResourceApk {
return manifest;
}
+ public Artifact getRTxt() {
+ return rTxt;
+ }
+
public Artifact getResourceJavaSrcJar() {
return resourceJavaSrcJar;
}
@@ -128,9 +166,24 @@ public final class ResourceApk {
return resourceJavaClassJar;
}
- public static ResourceApk fromTransitiveResources(
- ResourceDependencies resourceDeps, AssetDependencies assetDeps) {
- return new ResourceApk(null, null, null, resourceDeps, assetDeps, null, null, null, null, null);
+ static ResourceApk fromTransitiveResources(
+ ResourceDependencies resourceDeps,
+ AssetDependencies assetDeps,
+ Artifact manifest,
+ Artifact rTxt) {
+ return new ResourceApk(
+ null,
+ null,
+ null,
+ resourceDeps,
+ assetDeps,
+ null,
+ AndroidResources.empty(),
+ AndroidAssets.empty(),
+ manifest,
+ rTxt,
+ null,
+ null);
}
public Artifact getResourceProguardConfig() {
@@ -160,10 +213,10 @@ public final class ResourceApk {
* and the rest will be transitive.
*/
private AndroidResourcesInfo toResourceInfo(Label label) {
- if (primaryResources == null) {
+ if (validatedResources == null) {
return resourceDeps.toInfo(label);
}
- return resourceDeps.toInfo(primaryResources);
+ return resourceDeps.toInfo(validatedResources);
}
public void addToConfiguredTargetBuilder(RuleConfiguredTargetBuilder builder, Label label) {
@@ -187,4 +240,32 @@ public final class ResourceApk {
builder.addSkylarkTransitiveInfo(
AndroidSkylarkApiProvider.NAME, new AndroidSkylarkApiProvider(resourceInfo));
}
+
+ /**
+ * Registers an action to process just the transitive resources and assets of a library.
+ *
+ * <p>Any local resources and assets will be ignored.
+ */
+ public static ResourceApk processFromTransitiveLibraryData(
+ RuleContext ruleContext,
+ ResourceDependencies resourceDeps,
+ AssetDependencies assetDeps,
+ StampedAndroidManifest manifest)
+ throws InterruptedException {
+
+ return new AndroidResourcesProcessorBuilder(ruleContext)
+ .setLibrary(true)
+ .setRTxtOut(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT))
+ .setManifestOut(
+ ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST))
+ .setSourceJarOut(
+ ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR))
+ .setJavaPackage(manifest.getPackage())
+ .withResourceDependencies(resourceDeps)
+ .withAssetDependencies(assetDeps)
+ .setDebug(ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT)
+ .setThrowOnResourceConflict(
+ AndroidCommon.getAndroidConfig(ruleContext).throwOnResourceConflict())
+ .buildWithoutLocalResources(manifest);
+ }
}