aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
diff options
context:
space:
mode:
authorGravatar Andrew Pellegrini <apell@google.com>2015-08-31 21:08:30 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-09-01 00:20:05 +0000
commitd23b7fbd47850ee7e8c9c5987eff328c0721d206 (patch)
treefc52f949b37a38ec4cdd57ed16e0199dbf897590 /src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
parenta7deb78dfbee2b5daa2208c3ff1d50b747de07aa (diff)
Switches AndroidRobolectricTest to using .aars to provide transitive resources to the test runner instead of ResourceContainers. Update AndroidLibraryAarProvider to contain transitive closure of .aars. Provides an ~4x speed improvement in test startup time.
NEW: Switched to ordered maps in CompositeLibraryAndroidManifestLocator to prevent manifest ordering flakiness bug. Switched to ImmutableSetMultimap in CompositeLibraryAndroidManifestLocator to prevent IllegalArgumentExceptions from duplicate package aliases and added test. RELNOTES: android_resources is no longer allowed as a dep for android_robolectric_test. -- MOS_MIGRATED_REVID=101972311
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
index 827586db41..4747929e40 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
@@ -30,6 +30,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.rules.android.AndroidLibraryAarProvider.Aar;
import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceType;
import com.google.devtools.build.lib.rules.cpp.LinkerInput;
@@ -68,6 +69,7 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
checkIdlRootImport(ruleContext);
NestedSet<AndroidResourcesProvider.ResourceContainer> transitiveResources =
collectTransitiveResources(ruleContext);
+ NestedSetBuilder<Aar> transitiveAars = collectTransitiveAars(ruleContext);
NestedSet<LinkerInput> transitiveNativeLibraries =
AndroidCommon.collectTransitiveNativeLibraries(deps);
NestedSet<Artifact> transitiveProguardConfigs =
@@ -123,6 +125,8 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
.setAAROut(aarOut)
.build(ruleContext);
+ Aar aar = new Aar(aarOut, applicationManifest.getManifest());
+
RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
androidCommon.addTransitiveInfoProviders(builder);
androidSemantics.addTransitiveInfoProviders(
@@ -141,8 +145,8 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
.add(AndroidCcLinkParamsProvider.class,
new AndroidCcLinkParamsProvider(androidCommon.getCcLinkParamsStore()))
.add(ProguardSpecProvider.class, new ProguardSpecProvider(transitiveProguardConfigs))
- .add(AndroidLibraryAarProvider.class, new AndroidLibraryAarProvider(aarOut,
- applicationManifest.getManifest()))
+ .add(AndroidLibraryAarProvider.class, new AndroidLibraryAarProvider(aar,
+ transitiveAars.add(aar).build()))
.addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL, transitiveProguardConfigs)
.build();
} catch (RuleConfigurationException e) {
@@ -196,8 +200,10 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
if (AndroidCommon.getAndroidResources(ruleContext) != null) {
primaryResources = Iterables.getOnlyElement(
AndroidCommon.getAndroidResources(ruleContext).getTransitiveAndroidResources());
+
+ Aar aar = new Aar(aarOut, primaryResources.getManifest());
targetBuilder.add(AndroidLibraryAarProvider.class, new AndroidLibraryAarProvider(
- aarOut, primaryResources.getManifest()));
+ aar, transitiveAars.add(aar).build()));
} else {
// there are no local resources and resources attribute was not specified either
ApplicationManifest applicationManifest =
@@ -238,6 +244,9 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT)
.setWorkingDirectory(ruleContext.getUniqueDirectory("_resources"))
.build(ruleContext);
+
+ targetBuilder.add(AndroidLibraryAarProvider.class, new AndroidLibraryAarProvider(
+ null, transitiveAars.build()));
}
new AarGeneratorBuilder(ruleContext)
@@ -342,6 +351,15 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
return builder.build();
}
+ private NestedSetBuilder<Aar> collectTransitiveAars(RuleContext ruleContext) {
+ NestedSetBuilder<Aar> builder = NestedSetBuilder.naiveLinkOrder();
+ for (AndroidLibraryAarProvider library :
+ ruleContext.getPrerequisites("deps", Mode.TARGET, AndroidLibraryAarProvider.class)) {
+ builder.addTransitive(library.getTransitiveAars());
+ }
+ return builder;
+ }
+
private boolean hasExplicitlySpecifiedIdlImportRoot(RuleContext ruleContext) {
return ruleContext.getRule().isAttributeValueExplicitlySpecified("idl_import_root");
}