diff options
author | 2018-04-18 07:46:20 -0700 | |
---|---|---|
committer | 2018-04-18 07:47:34 -0700 | |
commit | 9e76d242beb562e8337caf5529f0e6a151399b28 (patch) | |
tree | 05e47c8e94e4749a69c21596af41cb76e8e79243 /src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java | |
parent | 83da8ccd5716f5be19f9be8e36949c58a3f741eb (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/AndroidLibrary.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java | 55 |
1 files changed, 12 insertions, 43 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 2fe425728f..db44618df6 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 @@ -21,7 +21,6 @@ import com.google.devtools.build.lib.analysis.OutputGroupInfo; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.config.CompilationMode; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -166,7 +165,13 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { return null; } } else { - resourceApk = ResourceApk.fromTransitiveResources(resourceDeps, assetDeps); + // Process transitive resources so we can build artifacts needed to export an aar. + resourceApk = + ResourceApk.processFromTransitiveLibraryData( + ruleContext, + resourceDeps, + assetDeps, + StampedAndroidManifest.createEmpty(ruleContext, /* exported = */ false)); } JavaTargetAttributes javaTargetAttributes = @@ -187,55 +192,19 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_CLASS_JAR); Artifact aarOut = ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_AAR); - final ResourceContainer primaryResources; final Aar aar; if (definesLocalResources) { - primaryResources = resourceApk.getPrimaryResources(); - // applicationManifest has already been checked for nullness above in this method - ApplicationManifest applicationManifest = - ApplicationManifest.fromExplicitManifest(ruleContext, resourceApk.getManifest()); - - aar = Aar.create(aarOut, applicationManifest.getManifest()); + aar = Aar.create(aarOut, resourceApk.getManifest()); addAarToProvider(aar, transitiveAars, transitiveAarArtifacts); } else { aar = null; - ApplicationManifest applicationManifest = - ApplicationManifest.generatedManifest(ruleContext) - .renamePackage(ruleContext, AndroidCommon.getJavaPackage(ruleContext)); - - String javaPackage = AndroidCommon.getJavaPackage(ruleContext); - - ResourceContainer resourceContainer = - ResourceContainer.builder() - .setLabel(ruleContext.getLabel()) - .setJavaPackageFromString(javaPackage) - .setManifest(applicationManifest.getManifest()) - .setJavaSourceJar( - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR)) - .setManifestExported(AndroidCommon.getExportsManifest(ruleContext)) - .setRTxt(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT)) - .build(); - - primaryResources = - new AndroidResourcesProcessorBuilder(ruleContext) - .setLibrary(true) - .setRTxtOut(resourceContainer.getRTxt()) - .setManifestOut( - ruleContext.getImplicitOutputArtifact( - AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST)) - .setSourceJarOut(resourceContainer.getJavaSourceJar()) - .setJavaPackage(resourceContainer.getJavaPackage()) - .withResourceDependencies(resourceApk.getResourceDependencies()) - .setDebug(ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT) - .setThrowOnResourceConflict( - ruleContext.getFragment(AndroidConfiguration.class).throwOnResourceConflict()) - .build(resourceContainer); } new AarGeneratorBuilder(ruleContext) - .withPrimary(primaryResources) - .withManifest(aar != null ? aar.getManifest() : primaryResources.getManifest()) - .withRtxt(primaryResources.getRTxt()) + .withPrimaryResources(resourceApk.getPrimaryResources()) + .withPrimaryAssets(resourceApk.getPrimaryAssets()) + .withManifest(resourceApk.getManifest()) + .withRtxt(resourceApk.getRTxt()) .withClasses(classesJar) .setAAROut(aarOut) .setProguardSpecs(proguardLibrary.collectLocalProguardSpecs()) |