Skip to content

Commit

Permalink
Introduce persistent_multiplex_android_tools expansion flag
Browse files Browse the repository at this point in the history
Alternative approach to #15321 (comment) that leverages an expansion CLI flag instead of proliferating unique experimental multiplex flags.

Closes #15950.

PiperOrigin-RevId: 482004859
Change-Id: I176288fbc7934dc74b92e144aa0c43f30cb5471d
  • Loading branch information
Bencodes authored and copybara-github committed Oct 18, 2022
1 parent 37e5b23 commit 63aace2
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public static class Options extends FragmentOptions {
OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS,
OptionEffectTag.EXECUTION,
},
help = "Enable the persistent Android resource processor by using workers.",
help = "Enable persistent Android resource processor by using workers.",
expansion = {
"--internal_persistent_busybox_tools",
// This implementation uses unique workers for each tool in the busybox.
Expand All @@ -867,6 +867,82 @@ public static class Options extends FragmentOptions {
})
public Void persistentResourceProcessor;

@Option(
name = "persistent_multiplex_android_resource_processor",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY,
effectTags = {
OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS,
OptionEffectTag.EXECUTION,
},
help = "Enable persistent multiplexed Android resource processor by using workers.",
expansion = {
"--persistent_android_resource_processor",
"--modify_execution_info=AaptPackage=+supports-multiplex-workers",
"--modify_execution_info=AndroidResourceParser=+supports-multiplex-workers",
"--modify_execution_info=AndroidResourceValidator=+supports-multiplex-workers",
"--modify_execution_info=AndroidResourceCompiler=+supports-multiplex-workers",
"--modify_execution_info=RClassGenerator=+supports-multiplex-workers",
"--modify_execution_info=AndroidResourceLink=+supports-multiplex-workers",
"--modify_execution_info=AndroidAapt2=+supports-multiplex-workers",
"--modify_execution_info=AndroidAssetMerger=+supports-multiplex-workers",
"--modify_execution_info=AndroidResourceMerger=+supports-multiplex-workers",
"--modify_execution_info=AndroidCompiledResourceMerger=+supports-multiplex-workers",
"--modify_execution_info=ManifestMerger=+supports-multiplex-workers",
"--modify_execution_info=AndroidManifestMerger=+supports-multiplex-workers",
"--modify_execution_info=Aapt2Optimize=+supports-multiplex-workers",
"--modify_execution_info=AARGenerator=+supports-multiplex-workers",
})
public Void persistentMultiplexAndroidResourceProcessor;

@Option(
name = "persistent_android_dex_desugar",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY,
effectTags = {
OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS,
OptionEffectTag.EXECUTION,
},
help = "Enable persistent Android dex and desugar actions by using workers.",
expansion = {
"--strategy=Desugar=worker",
"--strategy=DexBuilder=worker",
})
public Void persistentDexDesugar;

@Option(
name = "persistent_multiplex_android_dex_desugar",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY,
effectTags = {
OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS,
OptionEffectTag.EXECUTION,
},
help = "Enable persistent multiplexed Android dex and desugar actions by using workers.",
expansion = {
"--persistent_android_dex_desugar",
"--modify_execution_info=Desugar=+supports-multiplex-workers",
"--modify_execution_info=DexBuilder=+supports-multiplex-workers",
})
public Void persistentMultiplexDexDesugar;

@Option(
name = "persistent_multiplex_android_tools",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY,
effectTags = {
OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS,
OptionEffectTag.EXECUTION,
},
help =
"Enable persistent and multiplexed Android tools (dexing, desugaring, resource "
+ "processing).",
expansion = {
"--persistent_multiplex_android_resource_processor",
"--persistent_multiplex_android_dex_desugar",
})
public Void persistentMultiplexAndroidTools;

/**
* We use this option to decide when to enable workers for busybox tools. This flag is also a
* guard against enabling workers using nothing but --persistent_android_resource_processor.
Expand All @@ -886,17 +962,6 @@ public static class Options extends FragmentOptions {
help = "Tracking flag for when busybox workers are enabled.")
public boolean persistentBusyboxTools;

@Option(
name = "experimental_persistent_multiplex_busybox_tools",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {
OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS,
OptionEffectTag.EXECUTION,
},
defaultValue = "false",
help = "Tracking flag for when multiplex busybox workers are enabled.")
public boolean experimentalPersistentMultiplexBusyboxTools;

@Option(
name = "experimental_remove_r_classes_from_instrumentation_test_jar",
defaultValue = "true",
Expand Down Expand Up @@ -1030,8 +1095,6 @@ public FragmentOptions getHost() {
host.oneVersionEnforcementUseTransitiveJarsForBinaryUnderTest =
oneVersionEnforcementUseTransitiveJarsForBinaryUnderTest;
host.persistentBusyboxTools = persistentBusyboxTools;
host.experimentalPersistentMultiplexBusyboxTools =
experimentalPersistentMultiplexBusyboxTools;
host.disableNativeAndroidRules = disableNativeAndroidRules;

// Unless the build was started from an Android device, host means MAIN.
Expand Down Expand Up @@ -1078,7 +1141,6 @@ public FragmentOptions getHost() {
private final boolean dataBindingUpdatedArgs;
private final boolean dataBindingAndroidX;
private final boolean persistentBusyboxTools;
private final boolean experimentalPersistentMultiplexBusyboxTools;
private final boolean filterRJarsFromAndroidTest;
private final boolean removeRClassesFromInstrumentationTestJar;
private final boolean alwaysFilterDuplicateClassesFromAndroidTest;
Expand Down Expand Up @@ -1139,8 +1201,6 @@ public AndroidConfiguration(BuildOptions buildOptions) throws InvalidConfigurati
this.dataBindingUpdatedArgs = options.dataBindingUpdatedArgs;
this.dataBindingAndroidX = options.dataBindingAndroidX;
this.persistentBusyboxTools = options.persistentBusyboxTools;
this.experimentalPersistentMultiplexBusyboxTools =
options.experimentalPersistentMultiplexBusyboxTools;
this.filterRJarsFromAndroidTest = options.filterRJarsFromAndroidTest;
this.removeRClassesFromInstrumentationTestJar =
options.removeRClassesFromInstrumentationTestJar;
Expand Down Expand Up @@ -1393,11 +1453,6 @@ public boolean persistentBusyboxTools() {
return persistentBusyboxTools;
}

@Override
public boolean persistentMultiplexBusyboxTools() {
return experimentalPersistentMultiplexBusyboxTools;
}

@Override
public boolean incompatibleUseToolchainResolution() {
return incompatibleUseToolchainResolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public class AndroidDataContext implements AndroidDataContextApi {
private final FilesToRunProvider busybox;
private final AndroidSdkProvider sdk;
private final boolean persistentBusyboxToolsEnabled;
private final boolean persistentMultiplexBusyboxTools;
private final boolean optOutOfResourcePathShortening;
private final boolean optOutOfResourceNameObfuscation;
private final boolean throwOnShrinkResources;
Expand All @@ -91,7 +90,6 @@ public static AndroidDataContext makeContext(RuleContext ruleContext) {
ruleContext,
ruleContext.getExecutablePrerequisite("$android_resources_busybox"),
androidConfig.persistentBusyboxTools(),
androidConfig.persistentMultiplexBusyboxTools(),
AndroidSdkProvider.fromRuleContext(ruleContext),
hasExemption(ruleContext, "allow_raw_access_to_resource_paths", false),
hasExemption(ruleContext, "allow_resource_name_obfuscation_opt_out", false),
Expand All @@ -116,7 +114,6 @@ protected AndroidDataContext(
RuleContext ruleContext,
FilesToRunProvider busybox,
boolean persistentBusyboxToolsEnabled,
boolean persistentMultiplexBusyboxTools,
AndroidSdkProvider sdk,
boolean optOutOfResourcePathShortening,
boolean optOutOfResourceNameObfuscation,
Expand All @@ -129,7 +126,6 @@ protected AndroidDataContext(
boolean includeProguardLocationReferences,
ImmutableMap<String, String> executionInfo) {
this.persistentBusyboxToolsEnabled = persistentBusyboxToolsEnabled;
this.persistentMultiplexBusyboxTools = persistentMultiplexBusyboxTools;
this.ruleContext = ruleContext;
this.busybox = busybox;
this.sdk = sdk;
Expand Down Expand Up @@ -226,10 +222,6 @@ public boolean isPersistentBusyboxToolsEnabled() {
return persistentBusyboxToolsEnabled;
}

public boolean isPersistentMultiplexBusyboxTools() {
return persistentMultiplexBusyboxTools;
}

public boolean optOutOfResourcePathShortening() {
return optOutOfResourcePathShortening;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,6 @@ public void buildAndRegister(String message, String mnemonic) {
commandLine.add("--logWarnings=false");
spawnActionBuilder.addCommandLine(commandLine.build(), WORKERS_FORCED_PARAM_FILE_INFO);
executionInfo.putAll(ExecutionRequirements.WORKER_MODE_ENABLED);

if (dataContext.isPersistentMultiplexBusyboxTools()) {
executionInfo.putAll(ExecutionRequirements.WORKER_MULTIPLEX_MODE_ENABLED);
}
} else {
spawnActionBuilder.addCommandLine(commandLine.build(), FORCED_PARAM_FILE_INFO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,6 @@ public interface AndroidConfigurationApi extends StarlarkValue {
documented = false)
boolean persistentBusyboxTools();

@StarlarkMethod(
name = "experimental_persistent_multiplex_busybox_tools",
structField = true,
doc = "",
documented = false)
boolean persistentMultiplexBusyboxTools();

@StarlarkMethod(
name = "get_output_directory_name",
structField = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function test_persistent_multiplex_resource_processor() {
create_android_binary
setup_font_resources

assert_build //java/bazel:bin --persistent_android_resource_processor \
--experimental_persistent_multiplex_busybox_tools
assert_build //java/bazel:bin --experimental_worker_multiplex \
--persistent_multiplex_android_tools
}

run_suite "Resource processing integration tests"

0 comments on commit 63aace2

Please sign in to comment.