diff options
author | Lukacs Berki <lberki@google.com> | 2015-09-24 08:19:30 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2015-09-24 14:21:53 +0000 |
commit | d6f6b7dac79d122ba81d7e2b0f53feac7b225f1d (patch) | |
tree | 5c0b422fac65faa0643404fea5c08b2a45ac9dbf /src/main/java/com | |
parent | 574646c670ddee337258718303dedde30e546fbe (diff) |
Add a main_dex_proguard_specs attribute to android_binary that lets users specify which classes should go into the main dex.
This mode uses Proguard to determine the dependencies of these classes, which means that no error-prone manual listing required like in multidex="manual" mode.
RELNOTES: android_binary now has a main_dex_proguard_specs attribute to specify which classes should be in the main dex.
--
MOS_MIGRATED_REVID=103824119
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java | 29 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java | 7 |
2 files changed, 31 insertions, 5 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 81db9ac7cf..e0a057fe97 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 @@ -121,6 +121,15 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { JavaSemantics javaSemantics, AndroidSemantics androidSemantics, List<String> depsAttributes) throws InterruptedException { + + if (getMultidexMode(ruleContext) != MultidexMode.LEGACY + && ruleContext.attributes().isAttributeValueExplicitlySpecified( + "main_dex_proguard_specs")) { + ruleContext.attributeError("main_dex_proguard_specs", "The 'main_dex_proguard_specs' " + + "attribute is only allowed if 'multidex' is set to 'legacy'"); + return null; + } + // TODO(bazel-team): Find a way to simplify this code. // treeKeys() means that the resulting map sorts the entries by key, which is necessary to // ensure determinism. @@ -1005,7 +1014,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { // Process the input jar through Proguard into an intermediate, streamlined jar. Artifact strippedJar = AndroidBinary.getDxArtifact(ruleContext, "main_dex_intermediate.jar"); AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext); - ruleContext.registerAction(new SpawnAction.Builder() + SpawnAction.Builder streamlinedBuilder = new SpawnAction.Builder() .addOutput(strippedJar) .setExecutable(sdk.getProguard()) .setProgressMessage("Generating streamlined input jar for main dex classes list") @@ -1021,10 +1030,20 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { .addArgument("-forceprocessing") .addArgument("-dontoptimize") .addArgument("-dontobfuscate") - .addArgument("-dontpreverify") - .addArgument("-include") - .addInputArgument(sdk.getMainDexClasses()) - .build(ruleContext)); + .addArgument("-dontpreverify"); + + List<Artifact> specs = ruleContext.getPrerequisiteArtifacts( + "main_dex_proguard_specs", Mode.TARGET).list(); + if (specs.isEmpty()) { + specs = ImmutableList.of(sdk.getMainDexClasses()); + } + + for (Artifact spec : specs) { + streamlinedBuilder.addArgument("-include"); + streamlinedBuilder.addInputArgument(spec); + } + + ruleContext.registerAction(streamlinedBuilder.build(ruleContext)); // Create the main dex classes list. Artifact mainDexList = AndroidBinary.getDxArtifact(ruleContext, "main_dex_list.txt"); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java index 2b80cb1b7a..bbab1a54ab 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java @@ -650,6 +650,13 @@ com/google/common/base/Objects.class Must be used with <code>multidex="manual_main_dex"</code>. <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ .add(attr("main_dex_list", LABEL).legacyAllowAnyFileType()) + /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(main_dex_proguard_specs) --> + Files to be used as the Proguard specifications to determine classes that must be kept in + the main dex. + ${SYNOPSIS} + Only allowed if the <code>multidex</code> attribute is set to <code>legacy</code>. + <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ + .add(attr("main_dex_proguard_specs", LABEL_LIST).legacyAllowAnyFileType()) /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(proguard_specs) --> Files to be used as Proguard specification. ${SYNOPSIS} |