diff options
author | Googler <noreply@google.com> | 2017-11-21 10:48:16 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-21 10:50:20 -0800 |
commit | 59d2ece50d7998e355afff8fd7cabd4215fc070d (patch) | |
tree | 4fb6faa733c951e4a5ad83b11e239feaec52950f /src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java | |
parent | 1c2d2bd3b1c3b5d9929b6cac90c3b73fceca41ef (diff) |
Add option to enable resource cycle shrinking.
This will instruct AAPT2 to produce conditional keep rules to allow for more aggressive code and resource shrinking.
RELNOTES[NEW]: Add --experimental_android_resource_cycle_shrinking option to allow for more aggressive code and resource shrinking.
PiperOrigin-RevId: 176530749
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.java | 17 |
1 files changed, 15 insertions, 2 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 1bfcac40af..4d389e94d8 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 @@ -217,6 +217,8 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { configurationMap, cppSemantics); + boolean shrinkResources = shouldShrinkResources(ruleContext); + // TODO(bazel-team): Resolve all the different cases of resource handling so this conditional // can go away: recompile from android_resources, and recompile from android_binary attributes. ApplicationManifest applicationManifest; @@ -250,6 +252,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { ruleContext.attributes().get("crunch_png", Type.BOOLEAN), ProguardHelper.getProguardConfigArtifact(ruleContext, ""), createMainDexProguardSpec(ruleContext), + shouldShrinkResourceCycles(ruleContext, shrinkResources), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST), ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP), DataBinding.isEnabled(ruleContext) @@ -294,8 +297,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { } - boolean shrinkResources = shouldShrinkResources(ruleContext); - // Remove the library resource JARs from the binary's runtime classpath. // Resource classes from android_library dependencies are replaced by the binary's resource // class. We remove them only at the top level so that resources included by a library that is @@ -785,6 +786,18 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { return (state == TriState.YES); } + /** Returns {@code true} if resource shrinking should be performed. */ + private static boolean shouldShrinkResourceCycles( + RuleContext ruleContext, boolean shrinkResources) throws RuleErrorException { + boolean global = + ruleContext.getFragment(AndroidConfiguration.class).useAndroidResourceCycleShrinking(); + if (global && !shrinkResources) { + throw ruleContext.throwWithRuleError( + "resource cycle shrinking can only be enabled when resource shrinking is enabled"); + } + return global; + } + private static ResourceApk shrinkResources( RuleContext ruleContext, ResourceApk resourceApk, |