Skip to content

Commit

Permalink
Multiplex worker fixes and tests for Android busybox tools (bazelbuil…
Browse files Browse the repository at this point in the history
…d#17371)

* Fix multiplexed workers for Android busybox tools

Unblocks merging for PR bazelbuild#15952.

RELNOTES:
PiperOrigin-RevId: 505149043
Change-Id: I1cb5ccb4c162f26fea51e0cdef8c8553f3a3d5df

* Add worker assertions resource_processing_integration_test

Adding a few assertions to the worker and multiplex worker tests to ensure that the expected workers are in fact coming up.

Closes bazelbuild#15952.

PiperOrigin-RevId: 505690186
Change-Id: If732c9f040ec144395b5525a48d3a7d367fe244b

---------

Co-authored-by: Benjamin Lee <ben@ben.cm>
Co-authored-by: kshyanashree <109167932+kshyanashree@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 7, 2023
1 parent 82168d4 commit 84c1ed4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ public static class Options extends FragmentOptions {
"Enable persistent and multiplexed Android tools (dexing, desugaring, resource "
+ "processing).",
expansion = {
"--internal_persistent_multiplex_busybox_tools",
"--persistent_multiplex_android_resource_processor",
"--persistent_multiplex_android_dex_desugar",
})
Expand All @@ -962,6 +963,17 @@ public static class Options extends FragmentOptions {
help = "Tracking flag for when busybox workers are enabled.")
public boolean persistentBusyboxTools;

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

@Option(
name = "experimental_remove_r_classes_from_instrumentation_test_jar",
defaultValue = "true",
Expand Down Expand Up @@ -1096,6 +1108,7 @@ public FragmentOptions getHost() {
oneVersionEnforcementUseTransitiveJarsForBinaryUnderTest;
host.persistentBusyboxTools = persistentBusyboxTools;
host.disableNativeAndroidRules = disableNativeAndroidRules;
host.persistentMultiplexBusyboxTools = persistentMultiplexBusyboxTools;

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

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

@Override
public boolean incompatibleUseToolchainResolution() {
return incompatibleUseToolchainResolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class AndroidDataContext implements AndroidDataContextApi {
private final FilesToRunProvider busybox;
private final AndroidSdkProvider sdk;
private final boolean persistentBusyboxToolsEnabled;
private final boolean persistentMultiplexBusyboxToolsEnabled;
private final boolean optOutOfResourcePathShortening;
private final boolean optOutOfResourceNameObfuscation;
private final boolean throwOnShrinkResources;
Expand All @@ -90,6 +91,7 @@ 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 @@ -114,6 +116,7 @@ protected AndroidDataContext(
RuleContext ruleContext,
FilesToRunProvider busybox,
boolean persistentBusyboxToolsEnabled,
boolean persistentMultiplexBusyboxToolsEnabled,
AndroidSdkProvider sdk,
boolean optOutOfResourcePathShortening,
boolean optOutOfResourceNameObfuscation,
Expand All @@ -126,6 +129,7 @@ protected AndroidDataContext(
boolean includeProguardLocationReferences,
ImmutableMap<String, String> executionInfo) {
this.persistentBusyboxToolsEnabled = persistentBusyboxToolsEnabled;
this.persistentMultiplexBusyboxToolsEnabled = persistentMultiplexBusyboxToolsEnabled;
this.ruleContext = ruleContext;
this.busybox = busybox;
this.sdk = sdk;
Expand Down Expand Up @@ -222,6 +226,10 @@ public boolean isPersistentBusyboxToolsEnabled() {
return persistentBusyboxToolsEnabled;
}

public boolean isPersistentMultiplexBusyboxToolsEnabled() {
return persistentMultiplexBusyboxToolsEnabled;
}

public boolean optOutOfResourcePathShortening() {
return optOutOfResourcePathShortening;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ 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.isPersistentMultiplexBusyboxToolsEnabled()) {
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,6 +231,13 @@ public interface AndroidConfigurationApi extends StarlarkValue {
documented = false)
boolean persistentBusyboxTools();

@StarlarkMethod(
name = "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 @@ -111,7 +111,13 @@ function test_persistent_resource_processor() {
create_android_binary
setup_font_resources

assert_build //java/bazel:bin --persistent_android_resource_processor
assert_build //java/bazel:bin --persistent_android_resource_processor \
--worker_verbose &> $TEST_log
expect_log "Created new non-sandboxed AndroidResourceParser worker (id [0-9]\+)"
expect_log "Created new non-sandboxed AndroidResourceCompiler worker (id [0-9]\+)"
expect_log "Created new non-sandboxed AndroidCompiledResourceMerger worker (id [0-9]\+)"
expect_log "Created new non-sandboxed AndroidAapt2 worker (id [0-9]\+)"
expect_log "Created new non-sandboxed ManifestMerger worker (id [0-9]\+)"
}

function test_persistent_multiplex_resource_processor() {
Expand All @@ -121,7 +127,13 @@ function test_persistent_multiplex_resource_processor() {
setup_font_resources

assert_build //java/bazel:bin --experimental_worker_multiplex \
--persistent_multiplex_android_tools
--persistent_multiplex_android_tools \
--worker_verbose &> $TEST_log
expect_log "Created new non-sandboxed AndroidResourceParser multiplex-worker (id [0-9]\+)"
expect_log "Created new non-sandboxed AndroidResourceCompiler multiplex-worker (id [0-9]\+)"
expect_log "Created new non-sandboxed AndroidCompiledResourceMerger multiplex-worker (id [0-9]\+)"
expect_log "Created new non-sandboxed AndroidAapt2 multiplex-worker (id [0-9]\+)"
expect_log "Created new non-sandboxed ManifestMerger multiplex-worker (id [0-9]\+)"
}

run_suite "Resource processing integration tests"

0 comments on commit 84c1ed4

Please sign in to comment.