aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2016-05-18 12:00:23 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-05-18 13:49:38 +0000
commit9f046cba37de6088b2f81717bc263889a5146d86 (patch)
tree4051c02bfbe6d9e06ecf692cdf9ff838f41d6a99 /src/main/java/com/google/devtools/build/lib/rules/android
parent67116c7443c93b71e522cee36c72fc4af358358d (diff)
-- MOS_MIGRATED_REVID=122620007
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java49
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java4
3 files changed, 16 insertions, 47 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 b798b4f00b..aa565155a0 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
@@ -1079,7 +1079,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
@Nullable Artifact mainDexProguardSpec,
JavaTargetAttributes attributes)
throws InterruptedException {
- boolean isFinalJarDerived = isBinaryJarFiltered || binaryJar != proguardedJar;
+ boolean finalJarIsDerived = isBinaryJarFiltered || binaryJar != proguardedJar;
List<String> dexopts = ruleContext.getTokenizedStringListAttr("dexopts");
MultidexMode multidexMode = getMultidexMode(ruleContext);
if (!supportsMultidexMode(ruleContext, multidexMode)) {
@@ -1111,7 +1111,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
// Always OFF if finalJarIsDerived
ImmutableSet<AndroidBinaryType> incrementalDexing =
- getEffectiveIncrementalDexing(ruleContext, dexopts, isFinalJarDerived, isBinaryJarFiltered);
+ getEffectiveIncrementalDexing(ruleContext, dexopts, finalJarIsDerived);
if (multidexMode == MultidexMode.OFF) {
// Single dex mode: generate classes.dex directly from the input jar.
if (incrementalDexing.contains(AndroidBinaryType.MONODEX)) {
@@ -1148,7 +1148,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
createShuffleJarAction(
ruleContext,
incrementalDexing.contains(AndroidBinaryType.MULTIDEX_SHARDED),
- isFinalJarDerived ? proguardedJar : null,
+ finalJarIsDerived ? proguardedJar : null,
shards,
common,
dexopts,
@@ -1219,43 +1219,18 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
}
private static ImmutableSet<AndroidBinaryType> getEffectiveIncrementalDexing(
- RuleContext ruleContext, List<String> dexopts, boolean isFinalJarDerived,
- boolean isBinaryJarFiltered) {
- TriState override = ruleContext.attributes().get("incremental_dexing", BuildType.TRISTATE);
- // Ignore --incremental_dexing_binary_types if the incremental_dexing attribute is set, but
- // raise an error if proguard is enabled (b/c incompatible with incremental dexing ATM).
- if (isFinalJarDerived && override == TriState.YES) {
- ruleContext.attributeError("incremental_dexing",
- "target cannot be incrementally dexed because "
- + (isBinaryJarFiltered ? "it builds a partial APK" : "the target uses Proguard"));
- return ImmutableSet.of();
- }
- if (isFinalJarDerived || override == TriState.NO) {
+ RuleContext ruleContext, List<String> dexopts, boolean finalJarIsDerived) {
+ if (finalJarIsDerived) {
return ImmutableSet.of();
}
ImmutableSet<AndroidBinaryType> result =
- override == TriState.YES
- ? ImmutableSet.copyOf(AndroidBinaryType.values())
- : AndroidCommon.getAndroidConfig(ruleContext).getIncrementalDexingBinaries();
- if (!result.isEmpty()) {
- Iterable<String> blacklistedDexopts =
- Iterables.filter(
- dexopts,
- new DexArchiveAspect.FlagMatcher(AndroidCommon
- .getAndroidConfig(ruleContext)
- .getTargetDexoptsThatPreventIncrementalDexing()));
- if (!Iterables.isEmpty(blacklistedDexopts)) {
- // target's dexopts include flags blacklisted with --non_incremental_per_target_dexopts. If
- // incremental_dexing attribute is explicitly set for this target then we'll warn and
- // incrementally dex anyway. Otherwise, just don't incrementally dex.
- if (override == TriState.YES) {
- ruleContext.attributeWarning("incremental_dexing",
- "Using incremental dexing even though the following dexopts indicate this target "
- + "may be unsuitable for incremental dexing for the moment: " + blacklistedDexopts);
- } else {
- result = ImmutableSet.of();
- }
- }
+ AndroidCommon.getAndroidConfig(ruleContext).getIncrementalDexingBinaries();
+ if (!result.isEmpty()
+ && Iterables.any(dexopts,
+ new DexArchiveAspect.FlagMatcher(AndroidCommon
+ .getAndroidConfig(ruleContext)
+ .getTargetDexoptsThatPreventIncrementalDexing()))) {
+ result = ImmutableSet.of();
}
return result;
}
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 99fbebc45c..600a68ec3a 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
@@ -627,16 +627,6 @@ public final class AndroidRuleClasses {
setting this to more than 1 is not recommended for release binaries.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("dex_shards", INTEGER).value(1))
- /* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(incremental_dexing) -->
- Force the target to be built with or without incremental dexing, overriding defaults and
- --incremental_dexing flag. Users should set this attribute to 0 for release binaries
- (e.g., to avoid accidental usage of --incremental_dexing), since incremental dexing can
- produce slightly larger artifacts than dx. It is an error to set this attribute to 1 for
- android_binary and android_test rules that have proguard enabled, as well as for
- android_test rules with binary_under_test set. We are working on addressing these
- shortcomings so please check with us if you run into these limitations.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("incremental_dexing", TRISTATE))
/* <!-- #BLAZE_RULE($android_binary_base).ATTRIBUTE(main_dex_list_opts) -->
Command line options to pass to the main dex list builder.
Use this option to affect the classes included in the main dex list.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
index 8efb2cd151..bf2ad53fe3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
@@ -106,6 +106,10 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext,
AspectParameters params) throws InterruptedException {
+ if (getAndroidConfig(ruleContext).getIncrementalDexingBinaries().isEmpty()) {
+ // Dex archives will never be used, so don't bother setting them up.
+ return new ConfiguredAspect.Builder(NAME, ruleContext).build();
+ }
checkState(base.getProvider(DexArchiveProvider.class) == null,
"dex archive natively generated: %s", ruleContext.getLabel());