aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-10-21 14:24:18 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-10-21 14:39:39 +0000
commit687550660db90b007741e1f67a8092b08945f8e3 (patch)
treeb761daca94396629023f627302505f77d11790a4 /src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
parent4d7fae3bfcc579676d7b2454ab8a38743aa4c635 (diff)
Trying again with checking for the presence of the "resources" attribute and deduplication of transitive and direct dependencies in the AndroidProcessingAction.
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=105960655
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
index 876d796fc8..6c8fd51b0b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
@@ -49,7 +49,6 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.TriState;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
-import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.MultidexMode;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CppHelper;
@@ -97,11 +96,19 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
AndroidCommon androidCommon = new AndroidCommon(
ruleContext, javaCommon, true /* asNeverLink */, true /* exportDeps */);
try {
- RuleConfiguredTargetBuilder builder =
- init(ruleContext, filesBuilder,
- AndroidCommon.getTransitiveResourceContainers(ruleContext, true),
- javaCommon, androidCommon, javaSemantics, androidSemantics,
- ImmutableList.<String>of("deps"));
+ ResourceDependencies resourceDeps = LocalResourceContainer.definesAndroidResources(
+ ruleContext.attributes())
+ ? ResourceDependencies.fromRuleDeps(ruleContext)
+ : ResourceDependencies.fromRuleResourceAndDeps(ruleContext);
+ RuleConfiguredTargetBuilder builder = init(
+ ruleContext,
+ filesBuilder,
+ resourceDeps,
+ javaCommon,
+ androidCommon,
+ javaSemantics,
+ androidSemantics,
+ ImmutableList.<String>of("deps"));
if (builder == null) {
return null;
}
@@ -116,7 +123,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
private static RuleConfiguredTargetBuilder init(
RuleContext ruleContext,
NestedSetBuilder<Artifact> filesBuilder,
- NestedSet<ResourceContainer> resourceContainers,
+ ResourceDependencies resourceDeps,
JavaCommon javaCommon,
AndroidCommon androidCommon,
JavaSemantics javaSemantics,
@@ -183,11 +190,11 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
throw new RuleConfigurationException();
}
applicationManifest = androidSemantics.getManifestForRule(ruleContext)
- .mergeWith(ruleContext, resourceContainers);
+ .mergeWith(ruleContext, resourceDeps);
resourceApk = applicationManifest.packWithDataAndResources(
ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK),
ruleContext,
- resourceContainers,
+ resourceDeps,
null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ruleContext.getTokenizedStringListAttr("resource_configuration_filters"),
@@ -201,7 +208,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
.packWithDataAndResources(ruleContext
.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK),
ruleContext,
- resourceContainers,
+ resourceDeps,
null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ruleContext.getTokenizedStringListAttr("resource_configuration_filters"),
@@ -215,7 +222,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
.createSplitManifest(ruleContext, "android_resources", false)
.packWithDataAndResources(getDxArtifact(ruleContext, "android_resources.ap_"),
ruleContext,
- resourceContainers,
+ resourceDeps,
null, /* Artifact rTxt */
null, /* Artifact symbolsTxt */
ruleContext.getTokenizedStringListAttr("resource_configuration_filters"),
@@ -229,13 +236,13 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
// Retrieve the resources from the resources attribute on the android_binary rule
// and recompile them if necessary.
applicationManifest = ApplicationManifest.fromResourcesRule(ruleContext).mergeWith(
- ruleContext, resourceContainers);
+ ruleContext, resourceDeps);
// Always recompiling resources causes AndroidTest to fail in certain circumstances.
- if (shouldRegenerate(ruleContext, resourceContainers)) {
+ if (shouldRegenerate(ruleContext, resourceDeps)) {
resourceApk = applicationManifest.packWithResources(
ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK),
ruleContext,
- resourceContainers,
+ resourceDeps,
true,
getProguardConfigArtifact(ruleContext, ""));
} else {
@@ -248,7 +255,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
ruleContext.getImplicitOutputArtifact(
AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK),
ruleContext,
- resourceContainers,
+ resourceDeps,
false,
getProguardConfigArtifact(ruleContext, "incremental"));
@@ -256,7 +263,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
.createSplitManifest(ruleContext, "android_resources", false)
.packWithResources(getDxArtifact(ruleContext, "android_resources.ap_"),
ruleContext,
- resourceContainers,
+ resourceDeps,
false,
getProguardConfigArtifact(ruleContext, "incremental_split"));
}
@@ -1272,8 +1279,8 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
* </ul>
*/
public static boolean shouldRegenerate(RuleContext ruleContext,
- Iterable<ResourceContainer> resourceContainers) {
- return Iterables.size(resourceContainers) > 1
+ ResourceDependencies resourceDeps) {
+ return Iterables.size(resourceDeps.getResources()) > 1
|| ruleContext.attributes().isAttributeValueExplicitlySpecified("densities")
|| ruleContext.attributes().isAttributeValueExplicitlySpecified(
"resource_configuration_filters")