aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-05-19 15:56:19 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-05-19 18:05:12 +0000
commitab63a1224c9b7c1e85ab50f8ecf0a543519371fe (patch)
treea95ce9fef082522fe958967fd7dab49a48c5db35 /src/main/java/com/google
parent8058099184c470c41fce67aa02bbbfa4e098fa87 (diff)
*** Reason for rollback *** Rollback of commit e37c55eccbd4516b2db7aaf58ef95209dfad3ed4 is complete so rolling this semantically unrelated change forward again *** Original change description *** Automated [] rollback of commit b8946eabd60a199a66a1892701d52d9801c7fb1a. -- MOS_MIGRATED_REVID=122736257
Diffstat (limited to 'src/main/java/com/google')
-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, 47 insertions, 16 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 f76a5b8b0e..c112969e77 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 finalJarIsDerived = isBinaryJarFiltered || binaryJar != proguardedJar;
+ boolean isFinalJarDerived = 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, finalJarIsDerived);
+ getEffectiveIncrementalDexing(ruleContext, dexopts, isFinalJarDerived, isBinaryJarFiltered);
if (multidexMode == MultidexMode.OFF) {
// Single dex mode: generate classes.dex directly from the input jar.
if (incrementalDexing.contains(AndroidBinaryType.MONODEX)) {
@@ -1149,7 +1149,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
createShuffleJarAction(
ruleContext,
incrementalDexing.contains(AndroidBinaryType.MULTIDEX_SHARDED),
- finalJarIsDerived ? proguardedJar : null,
+ isFinalJarDerived ? proguardedJar : null,
shards,
common,
attributes,
@@ -1221,18 +1221,43 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
}
private static ImmutableSet<AndroidBinaryType> getEffectiveIncrementalDexing(
- RuleContext ruleContext, List<String> dexopts, boolean finalJarIsDerived) {
- if (finalJarIsDerived) {
+ 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) {
return ImmutableSet.of();
}
ImmutableSet<AndroidBinaryType> result =
- AndroidCommon.getAndroidConfig(ruleContext).getIncrementalDexingBinaries();
- if (!result.isEmpty()
- && Iterables.any(dexopts,
- new FlagMatcher(AndroidCommon
- .getAndroidConfig(ruleContext)
- .getTargetDexoptsThatPreventIncrementalDexing()))) {
- result = ImmutableSet.of();
+ override == TriState.YES
+ ? ImmutableSet.copyOf(AndroidBinaryType.values())
+ : AndroidCommon.getAndroidConfig(ruleContext).getIncrementalDexingBinaries();
+ if (!result.isEmpty()) {
+ Iterable<String> blacklistedDexopts =
+ Iterables.filter(
+ dexopts,
+ new 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();
+ }
+ }
}
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 a6a612a42a..acf7067aa3 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
@@ -625,6 +625,16 @@ 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 06698e10ef..8920cfbd90 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
@@ -71,10 +71,6 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext,
AspectParameters params) throws InterruptedException {
- if (AndroidCommon.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());