diff options
author | asteinb <asteinb@google.com> | 2018-04-18 08:31:50 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-18 08:33:49 -0700 |
commit | 380f5dd96e97ff9c1c8ceb1104322ba6e303e067 (patch) | |
tree | b4c8c9055683547884c39dd9f827fea471566cb4 /src/main/java | |
parent | 9e76d242beb562e8337caf5529f0e6a151399b28 (diff) |
Wire up decoupled data pipeline in android_library
The decoupled pipeline is safely hidden behind a flag. Since we temporarily
have two different pipelines, this temporarily make AndroidLibrary messier, but
it will end up much cleaner once the old pipeline is removed.
The new pipeline should not be turned on until other Android rules are updated
to support it (next few changes).
RELNOTES: none
PiperOrigin-RevId: 193361608
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java | 23 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java | 53 |
2 files changed, 56 insertions, 20 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java index 28aec1f271..e8249eb7fe 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java @@ -785,6 +785,19 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { ) public AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel; + @Option( + name = "android_decouple_data_processing", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = { + OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION, + OptionEffectTag.ACTION_COMMAND_LINES + }, + help = + "If true, Android data (assets, resources, and manifests) will be processed seperately " + + "when possible. Otherwise, they will all be processed together.") + public boolean decoupleDataProcessing; + @Override public FragmentOptions getHost() { Options host = (Options) super.getHost(); @@ -862,6 +875,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { private final boolean skipParsingAction; private final boolean fixedResourceNeverlinking; private final AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel; + private final boolean decoupleDataProcessing; AndroidConfiguration(Options options) throws InvalidConfigurationException { this.sdk = options.sdk; @@ -899,6 +913,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.skipParsingAction = options.skipParsingAction; this.fixedResourceNeverlinking = options.fixedResourceNeverlinking; this.robolectricTestDeprecationLevel = options.robolectricTestDeprecationLevel; + this.decoupleDataProcessing = options.decoupleDataProcessing; if (incrementalDexingShardsAfterProguard < 0) { throw new InvalidConfigurationException( @@ -948,7 +963,8 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { boolean useParallelDex2Oat, boolean skipParsingAction, boolean fixedResourceNeverlinking, - AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel) { + AndroidRobolectricTestDeprecationLevel robolectricTestDeprecationLevel, + boolean decoupleDataProcessing) { this.sdk = sdk; this.cpu = cpu; this.useIncrementalNativeLibs = useIncrementalNativeLibs; @@ -981,6 +997,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.skipParsingAction = skipParsingAction; this.fixedResourceNeverlinking = fixedResourceNeverlinking; this.robolectricTestDeprecationLevel = robolectricTestDeprecationLevel; + this.decoupleDataProcessing = decoupleDataProcessing; } public String getCpu() { @@ -1128,6 +1145,10 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { return robolectricTestDeprecationLevel; } + public boolean decoupleDataProcessing() { + return decoupleDataProcessing; + } + @Override public void addGlobalMakeVariables(ImmutableMap.Builder<String, String> globalMakeEnvBuilder) { globalMakeEnvBuilder.put("ANDROID_CPU", cpu); 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 db44618df6..f94a3811ae 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 @@ -130,6 +130,8 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { javaSemantics.checkRule(ruleContext, javaCommon); AndroidCommon androidCommon = new AndroidCommon(javaCommon); + AndroidConfiguration androidConfig = AndroidCommon.getAndroidConfig(ruleContext); + boolean definesLocalResources = AndroidResources.definesAndroidResources(ruleContext.attributes()); if (definesLocalResources) { @@ -139,28 +141,42 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { // TODO(b/69668042): Always correctly apply neverlinking for resources boolean isNeverLink = JavaCommon.isNeverLink(ruleContext) - && (definesLocalResources - || ruleContext.getFragment(AndroidConfiguration.class).fixedResourceNeverlinking()); + && (definesLocalResources || androidConfig.fixedResourceNeverlinking()); ResourceDependencies resourceDeps = ResourceDependencies.fromRuleDeps(ruleContext, isNeverLink); AssetDependencies assetDeps = AssetDependencies.fromRuleDeps(ruleContext, isNeverLink); final ResourceApk resourceApk; if (definesLocalResources) { - ApplicationManifest applicationManifest = - androidSemantics - .getManifestForRule(ruleContext) - .renamePackage(ruleContext, AndroidCommon.getJavaPackage(ruleContext)); - resourceApk = - applicationManifest.packLibraryWithDataAndResources( - ruleContext, - resourceDeps, - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_MERGED_SYMBOLS), - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP), - DataBinding.isEnabled(ruleContext) - ? DataBinding.getLayoutInfoFile(ruleContext) - : null); + if (androidConfig.decoupleDataProcessing()) { + StampedAndroidManifest manifest = + AndroidManifest.from(ruleContext, androidSemantics).stamp(ruleContext); + + ValidatedAndroidResources resources = + AndroidResources.from(ruleContext, "resource_files") + .process(ruleContext, manifest, isNeverLink); + + MergedAndroidAssets assets = + AndroidAssets.from(ruleContext).process(ruleContext, isNeverLink); + + resourceApk = ResourceApk.of(resources, assets); + } else { + ApplicationManifest applicationManifest = + androidSemantics + .getManifestForRule(ruleContext) + .renamePackage(ruleContext, AndroidCommon.getJavaPackage(ruleContext)); + resourceApk = + applicationManifest.packLibraryWithDataAndResources( + ruleContext, + resourceDeps, + ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT), + ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_MERGED_SYMBOLS), + ruleContext.getImplicitOutputArtifact( + AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), + ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP), + DataBinding.isEnabled(ruleContext) + ? DataBinding.getLayoutInfoFile(ruleContext) + : null); + } if (ruleContext.hasErrors()) { return null; } @@ -208,8 +224,7 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { .withClasses(classesJar) .setAAROut(aarOut) .setProguardSpecs(proguardLibrary.collectLocalProguardSpecs()) - .setThrowOnResourceConflict( - ruleContext.getFragment(AndroidConfiguration.class).throwOnResourceConflict()) + .setThrowOnResourceConflict(androidConfig.throwOnResourceConflict()) .build(ruleContext); RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext); |