Skip to content

Commit

Permalink
add flag to use incremental dexing by default for proguarded android …
Browse files Browse the repository at this point in the history
…binaries

RELNOTES: None.

PiperOrigin-RevId: 186067158
  • Loading branch information
kevin1e100 authored and Copybara-Service committed Feb 17, 2018
1 parent d18d3e2 commit 97c4a9e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1140,12 +1140,10 @@ private static boolean getEffectiveIncrementalDexing(
if (override == TriState.NO) {
return false;
}
if (isBinaryProguarded) {
// Require explicit opt-in for proguarded binaries, but no need to check dexopts since we'll
// be able to create dexbuilder actions with the appropriate flags as part of this rule.
return override == TriState.YES;
}
if (override == TriState.YES || config.useIncrementalDexing()) {
if (isBinaryProguarded) {
return override == TriState.YES || config.incrementalDexingAfterProguardByDefault();
}
Iterable<String> blacklistedDexopts =
DexArchiveAspect.blacklistedDexopts(ruleContext, dexopts);
if (Iterables.isEmpty(blacklistedDexopts)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ public static class Options extends FragmentOptions {
)
public boolean incrementalDexingUseDexSharder;

@Option(
name = "experimental_incremental_dexing_after_proguard_by_default",
defaultValue = "false",
metadataTags = {OptionMetadataTag.EXPERIMENTAL},
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
help = "Whether to use incremental dexing for proguarded Android binaries by default. "
+ "Use incremental_dexing attribute to override default for a particular android_binary."
)
public boolean incrementalDexingAfterProguardByDefault;

// TODO(b/31711689): Remove this flag when this optimization is proven to work globally.
@Option(
name = "experimental_android_assume_minsdkversion",
Expand Down Expand Up @@ -788,6 +799,7 @@ public FragmentOptions getHost() {
host.incrementalDexing = incrementalDexing;
host.incrementalDexingShardsAfterProguard = incrementalDexingShardsAfterProguard;
host.incrementalDexingUseDexSharder = incrementalDexingUseDexSharder;
host.incrementalDexingAfterProguardByDefault = incrementalDexingAfterProguardByDefault;
host.assumeMinSdkVersion = assumeMinSdkVersion;
host.nonIncrementalPerTargetDexopts = nonIncrementalPerTargetDexopts;
host.dexoptsSupportedInIncrementalDexing = dexoptsSupportedInIncrementalDexing;
Expand Down Expand Up @@ -831,6 +843,7 @@ public ImmutableSet<Class<? extends FragmentOptions>> requiredOptions() {
private final boolean incrementalDexing;
private final int incrementalDexingShardsAfterProguard;
private final boolean incrementalDexingUseDexSharder;
private final boolean incrementalDexingAfterProguardByDefault;
private final boolean assumeMinSdkVersion;
private final ImmutableList<String> dexoptsSupportedInIncrementalDexing;
private final ImmutableList<String> targetDexoptsThatPreventIncrementalDexing;
Expand Down Expand Up @@ -864,6 +877,7 @@ public ImmutableSet<Class<? extends FragmentOptions>> requiredOptions() {
this.incrementalDexing = options.incrementalDexing;
this.incrementalDexingShardsAfterProguard = options.incrementalDexingShardsAfterProguard;
this.incrementalDexingUseDexSharder = options.incrementalDexingUseDexSharder;
this.incrementalDexingAfterProguardByDefault = options.incrementalDexingAfterProguardByDefault;
this.assumeMinSdkVersion = options.assumeMinSdkVersion;
this.dexoptsSupportedInIncrementalDexing =
ImmutableList.copyOf(options.dexoptsSupportedInIncrementalDexing);
Expand Down Expand Up @@ -896,6 +910,11 @@ public ImmutableSet<Class<? extends FragmentOptions>> requiredOptions() {
throw new InvalidConfigurationException(
"--experimental_incremental_dexing_after_proguard must be a positive number");
}
if (incrementalDexingAfterProguardByDefault && incrementalDexingShardsAfterProguard == 0) {
throw new InvalidConfigurationException(
"--experimental_incremental_dexing_after_proguard_by_default requires "
+ "--experimental_incremental_dexing_after_proguard to be at least 1");
}
if (desugarJava8Libs && !desugarJava8) {
throw new InvalidConfigurationException(
"Java 8 library support requires --desugar_java8 to be enabled.");
Expand All @@ -911,6 +930,7 @@ public ImmutableSet<Class<? extends FragmentOptions>> requiredOptions() {
boolean incrementalDexing,
int incrementalDexingShardsAfterProguard,
boolean incrementalDexingUseDexSharder,
boolean incrementalDexingAfterProguardByDefault,
boolean assumeMinSdkVersion,
ImmutableList<String> dexoptsSupportedInIncrementalDexing,
ImmutableList<String> targetDexoptsThatPreventIncrementalDexing,
Expand Down Expand Up @@ -942,6 +962,7 @@ public ImmutableSet<Class<? extends FragmentOptions>> requiredOptions() {
this.incrementalDexing = incrementalDexing;
this.incrementalDexingShardsAfterProguard = incrementalDexingShardsAfterProguard;
this.incrementalDexingUseDexSharder = incrementalDexingUseDexSharder;
this.incrementalDexingAfterProguardByDefault = incrementalDexingAfterProguardByDefault;
this.assumeMinSdkVersion = assumeMinSdkVersion;
this.dexoptsSupportedInIncrementalDexing = dexoptsSupportedInIncrementalDexing;
this.targetDexoptsThatPreventIncrementalDexing = targetDexoptsThatPreventIncrementalDexing;
Expand Down Expand Up @@ -1001,6 +1022,11 @@ public boolean incrementalDexingUseDexSharder() {
return incrementalDexingUseDexSharder;
}

/** Whether to use incremental dexing to build proguarded binaries by default. */
public boolean incrementalDexingAfterProguardByDefault() {
return incrementalDexingAfterProguardByDefault;
}

/**
* Returns true if an -assumevalues should be generated for Proguard based on the minSdkVersion of
* the merged AndroidManifest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,9 @@ public void testIncrementalDexingAfterProguard_unsharded() throws Exception {
}

@Test
public void testIncrementalDexingAfterProguard_autoShardedMultidex() throws Exception {
useConfiguration("--experimental_incremental_dexing_after_proguard=3");
public void testIncrementalDexingAfterProguard_autoShardedMultidexAutoOptIn() throws Exception {
useConfiguration("--experimental_incremental_dexing_after_proguard=3",
"--experimental_incremental_dexing_after_proguard_by_default");
// Use "legacy" multidex mode so we get a main dex list file and can test that it's passed to
// the splitter action (similar to _withDexShards below), unlike without the dex splitter where
// the main dex list goes to the merging action.
Expand All @@ -696,11 +697,10 @@ public void testIncrementalDexingAfterProguard_autoShardedMultidex() throws Exce
" name = 'top',",
" srcs = ['foo.java', 'bar.srcjar'],",
" manifest = 'AndroidManifest.xml',",
" incremental_dexing = 1,",
" multidex = 'legacy',",
" dexopts = ['--minimal-main-dex', '--positions=none'],",
" proguard_specs = ['b.pro'],",
")");
")"); // incremental_dexing = 1 attribute not needed

ConfiguredTarget topTarget = getConfiguredTarget("//java/com/google/android:top");
assertNoEvents();
Expand Down

0 comments on commit 97c4a9e

Please sign in to comment.