Skip to content

Commit 84c1ed4

Browse files
ted-xieBencodesShreeM01
authored
Multiplex worker fixes and tests for Android busybox tools (bazelbuild#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 <[email protected]> Co-authored-by: kshyanashree <[email protected]>
1 parent 82168d4 commit 84c1ed4

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java

+20
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ public static class Options extends FragmentOptions {
938938
"Enable persistent and multiplexed Android tools (dexing, desugaring, resource "
939939
+ "processing).",
940940
expansion = {
941+
"--internal_persistent_multiplex_busybox_tools",
941942
"--persistent_multiplex_android_resource_processor",
942943
"--persistent_multiplex_android_dex_desugar",
943944
})
@@ -962,6 +963,17 @@ public static class Options extends FragmentOptions {
962963
help = "Tracking flag for when busybox workers are enabled.")
963964
public boolean persistentBusyboxTools;
964965

966+
@Option(
967+
name = "internal_persistent_multiplex_busybox_tools",
968+
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
969+
effectTags = {
970+
OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS,
971+
OptionEffectTag.EXECUTION,
972+
},
973+
defaultValue = "false",
974+
help = "Tracking flag for when multiplexed busybox workers are enabled.")
975+
public boolean persistentMultiplexBusyboxTools;
976+
965977
@Option(
966978
name = "experimental_remove_r_classes_from_instrumentation_test_jar",
967979
defaultValue = "true",
@@ -1096,6 +1108,7 @@ public FragmentOptions getHost() {
10961108
oneVersionEnforcementUseTransitiveJarsForBinaryUnderTest;
10971109
host.persistentBusyboxTools = persistentBusyboxTools;
10981110
host.disableNativeAndroidRules = disableNativeAndroidRules;
1111+
host.persistentMultiplexBusyboxTools = persistentMultiplexBusyboxTools;
10991112

11001113
// Unless the build was started from an Android device, host means MAIN.
11011114
host.configurationDistinguisher = ConfigurationDistinguisher.MAIN;
@@ -1141,6 +1154,7 @@ public FragmentOptions getHost() {
11411154
private final boolean dataBindingUpdatedArgs;
11421155
private final boolean dataBindingAndroidX;
11431156
private final boolean persistentBusyboxTools;
1157+
private final boolean persistentMultiplexBusyboxTools;
11441158
private final boolean filterRJarsFromAndroidTest;
11451159
private final boolean removeRClassesFromInstrumentationTestJar;
11461160
private final boolean alwaysFilterDuplicateClassesFromAndroidTest;
@@ -1201,6 +1215,7 @@ public AndroidConfiguration(BuildOptions buildOptions) throws InvalidConfigurati
12011215
this.dataBindingUpdatedArgs = options.dataBindingUpdatedArgs;
12021216
this.dataBindingAndroidX = options.dataBindingAndroidX;
12031217
this.persistentBusyboxTools = options.persistentBusyboxTools;
1218+
this.persistentMultiplexBusyboxTools = options.persistentMultiplexBusyboxTools;
12041219
this.filterRJarsFromAndroidTest = options.filterRJarsFromAndroidTest;
12051220
this.removeRClassesFromInstrumentationTestJar =
12061221
options.removeRClassesFromInstrumentationTestJar;
@@ -1453,6 +1468,11 @@ public boolean persistentBusyboxTools() {
14531468
return persistentBusyboxTools;
14541469
}
14551470

1471+
@Override
1472+
public boolean persistentMultiplexBusyboxTools() {
1473+
return persistentMultiplexBusyboxTools;
1474+
}
1475+
14561476
@Override
14571477
public boolean incompatibleUseToolchainResolution() {
14581478
return incompatibleUseToolchainResolution;

src/main/java/com/google/devtools/build/lib/rules/android/AndroidDataContext.java

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class AndroidDataContext implements AndroidDataContextApi {
6464
private final FilesToRunProvider busybox;
6565
private final AndroidSdkProvider sdk;
6666
private final boolean persistentBusyboxToolsEnabled;
67+
private final boolean persistentMultiplexBusyboxToolsEnabled;
6768
private final boolean optOutOfResourcePathShortening;
6869
private final boolean optOutOfResourceNameObfuscation;
6970
private final boolean throwOnShrinkResources;
@@ -90,6 +91,7 @@ public static AndroidDataContext makeContext(RuleContext ruleContext) {
9091
ruleContext,
9192
ruleContext.getExecutablePrerequisite("$android_resources_busybox"),
9293
androidConfig.persistentBusyboxTools(),
94+
androidConfig.persistentMultiplexBusyboxTools(),
9395
AndroidSdkProvider.fromRuleContext(ruleContext),
9496
hasExemption(ruleContext, "allow_raw_access_to_resource_paths", false),
9597
hasExemption(ruleContext, "allow_resource_name_obfuscation_opt_out", false),
@@ -114,6 +116,7 @@ protected AndroidDataContext(
114116
RuleContext ruleContext,
115117
FilesToRunProvider busybox,
116118
boolean persistentBusyboxToolsEnabled,
119+
boolean persistentMultiplexBusyboxToolsEnabled,
117120
AndroidSdkProvider sdk,
118121
boolean optOutOfResourcePathShortening,
119122
boolean optOutOfResourceNameObfuscation,
@@ -126,6 +129,7 @@ protected AndroidDataContext(
126129
boolean includeProguardLocationReferences,
127130
ImmutableMap<String, String> executionInfo) {
128131
this.persistentBusyboxToolsEnabled = persistentBusyboxToolsEnabled;
132+
this.persistentMultiplexBusyboxToolsEnabled = persistentMultiplexBusyboxToolsEnabled;
129133
this.ruleContext = ruleContext;
130134
this.busybox = busybox;
131135
this.sdk = sdk;
@@ -222,6 +226,10 @@ public boolean isPersistentBusyboxToolsEnabled() {
222226
return persistentBusyboxToolsEnabled;
223227
}
224228

229+
public boolean isPersistentMultiplexBusyboxToolsEnabled() {
230+
return persistentMultiplexBusyboxToolsEnabled;
231+
}
232+
225233
public boolean optOutOfResourcePathShortening() {
226234
return optOutOfResourcePathShortening;
227235
}

src/main/java/com/google/devtools/build/lib/rules/android/BusyBoxActionBuilder.java

+4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ public void buildAndRegister(String message, String mnemonic) {
369369
commandLine.add("--logWarnings=false");
370370
spawnActionBuilder.addCommandLine(commandLine.build(), WORKERS_FORCED_PARAM_FILE_INFO);
371371
executionInfo.putAll(ExecutionRequirements.WORKER_MODE_ENABLED);
372+
373+
if (dataContext.isPersistentMultiplexBusyboxToolsEnabled()) {
374+
executionInfo.putAll(ExecutionRequirements.WORKER_MULTIPLEX_MODE_ENABLED);
375+
}
372376
} else {
373377
spawnActionBuilder.addCommandLine(commandLine.build(), FORCED_PARAM_FILE_INFO);
374378
}

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/android/AndroidConfigurationApi.java

+7
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ public interface AndroidConfigurationApi extends StarlarkValue {
231231
documented = false)
232232
boolean persistentBusyboxTools();
233233

234+
@StarlarkMethod(
235+
name = "persistent_multiplex_busybox_tools",
236+
structField = true,
237+
doc = "",
238+
documented = false)
239+
boolean persistentMultiplexBusyboxTools();
240+
234241
@StarlarkMethod(
235242
name = "get_output_directory_name",
236243
structField = true,

src/test/shell/bazel/android/resource_processing_integration_test.sh

+14-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ function test_persistent_resource_processor() {
111111
create_android_binary
112112
setup_font_resources
113113

114-
assert_build //java/bazel:bin --persistent_android_resource_processor
114+
assert_build //java/bazel:bin --persistent_android_resource_processor \
115+
--worker_verbose &> $TEST_log
116+
expect_log "Created new non-sandboxed AndroidResourceParser worker (id [0-9]\+)"
117+
expect_log "Created new non-sandboxed AndroidResourceCompiler worker (id [0-9]\+)"
118+
expect_log "Created new non-sandboxed AndroidCompiledResourceMerger worker (id [0-9]\+)"
119+
expect_log "Created new non-sandboxed AndroidAapt2 worker (id [0-9]\+)"
120+
expect_log "Created new non-sandboxed ManifestMerger worker (id [0-9]\+)"
115121
}
116122

117123
function test_persistent_multiplex_resource_processor() {
@@ -121,7 +127,13 @@ function test_persistent_multiplex_resource_processor() {
121127
setup_font_resources
122128

123129
assert_build //java/bazel:bin --experimental_worker_multiplex \
124-
--persistent_multiplex_android_tools
130+
--persistent_multiplex_android_tools \
131+
--worker_verbose &> $TEST_log
132+
expect_log "Created new non-sandboxed AndroidResourceParser multiplex-worker (id [0-9]\+)"
133+
expect_log "Created new non-sandboxed AndroidResourceCompiler multiplex-worker (id [0-9]\+)"
134+
expect_log "Created new non-sandboxed AndroidCompiledResourceMerger multiplex-worker (id [0-9]\+)"
135+
expect_log "Created new non-sandboxed AndroidAapt2 multiplex-worker (id [0-9]\+)"
136+
expect_log "Created new non-sandboxed ManifestMerger multiplex-worker (id [0-9]\+)"
125137
}
126138

127139
run_suite "Resource processing integration tests"

0 commit comments

Comments
 (0)