aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-10-15 16:21:25 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-10-16 07:39:08 +0000
commit65425810207c9fd6892abfaa95da65e25db5e515 (patch)
treeceb20dee92f422c533a8ed632b92d626f44bb9b6 /src/main/java/com/google/devtools/build/lib/rules/android/ResourceApk.java
parentc1caffaabd028493188b7e3419bedf3a9506dfee (diff)
Change the resource dependency handling to separate between the transitive and direct resources from libraries.
This slightly increases the complexity of resource propagation. The initial algorithm was to simply merge all transitive ResourceContainers together with any new ResourceContainer and propagate them via the AndroidResourcesProvider. The new algorithm is encapsulated inside a new ResourceDependencies class which works as follows: 1. Collect resources from the deps into transitive and direct NestedSets 2. If a rule provides a ResourceContainer, merge the transitive and direct into a new transitive set 3. Export the provider This results having a rule without resources "forward" the merged sets of transitive and direct resources to the next rule. -- MOS_MIGRATED_REVID=105515074
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.java40
1 files changed, 30 insertions, 10 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 920f4cd68f..8a14507c95 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
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.rules.android;
import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
@@ -31,7 +31,7 @@ public class ResourceApk {
// to do this.
@Nullable private final Artifact resourceApk; // The .ap_ file
@Nullable private final Artifact resourceJavaSrcJar; // Source jar containing R.java and friends
- private final NestedSet<ResourceContainer> transitiveResources;
+ private final ResourceDependencies resourceDeps;
@Nullable private final ResourceContainer primaryResource;
@Nullable private final Artifact manifest; // The non-binary XML version of AndroidManifest.xml
@Nullable private final Artifact resourceProguardConfig;
@@ -40,14 +40,14 @@ public class ResourceApk {
public ResourceApk(
@Nullable Artifact resourceApk,
@Nullable Artifact resourceJavaSrcJar,
- NestedSet<ResourceContainer> transitiveResources,
+ ResourceDependencies resourceDeps,
@Nullable ResourceContainer primaryResource,
@Nullable Artifact manifest,
@Nullable Artifact resourceProguardConfig,
boolean legacy) {
this.resourceApk = resourceApk;
this.resourceJavaSrcJar = resourceJavaSrcJar;
- this.transitiveResources = transitiveResources;
+ this.resourceDeps = resourceDeps;
this.primaryResource = primaryResource;
this.manifest = manifest;
this.resourceProguardConfig = resourceProguardConfig;
@@ -74,16 +74,36 @@ public class ResourceApk {
return legacy;
}
- public NestedSet<ResourceContainer> getTransitiveResources() {
- return transitiveResources;
- }
-
public static ResourceApk fromTransitiveResources(
- NestedSet<ResourceContainer> transitiveResources) {
- return new ResourceApk(null, null, transitiveResources, null, null, null, false);
+ ResourceDependencies resourceDeps) {
+ return new ResourceApk(null, null, resourceDeps, null, null, null, false);
}
public Artifact getResourceProguardConfig() {
return resourceProguardConfig;
}
+
+ public ResourceDependencies getResourceDependencies() {
+ return resourceDeps;
+ }
+
+ /**
+ * Creates an provider from the resources in the ResourceApk.
+ *
+ * <p>If the ResourceApk was created from transitive resources, the provider will effectively
+ * contain the "forwarded" resources: The merged transitive and merged direct dependencies of this
+ * library.
+ *
+ * <p>If the ResourceApk was generated from a "resources" attribute, it will contain the
+ * "resources" container in the direct dependencies and the rest as transitive.
+ *
+ * <p>If the ResourceApk was generated from local resources, that will be the direct dependencies and
+ * the rest will be transitive.
+ */
+ public AndroidResourcesProvider toResourceProvider(Label label) {
+ if (primaryResource == null) {
+ return resourceDeps.toProvider(label);
+ }
+ return resourceDeps.toProvider(label, primaryResource);
+ }
}