diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerParser.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerParser.java index 3590d259e18180..a484a0c5909a2f 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerParser.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerParser.java @@ -211,7 +211,7 @@ ImmutableList splitSpawnArgsIntoWorkerArgsAndFlagFiles( ImmutableList.Builder mnemonicFlags = ImmutableList.builder(); workerOptions.workerExtraFlags.stream() - .filter(entry -> entry.getKey().equals(spawn.getMnemonic())) + .filter(entry -> entry.getKey().equals(Spawns.getWorkerKeyMnemonic(spawn))) .forEach(entry -> mnemonicFlags.add(entry.getValue())); return workerArgs.add("--persistent_worker").addAll(mnemonicFlags.build()).build(); diff --git a/src/test/java/com/google/devtools/build/lib/worker/ExampleWorker.java b/src/test/java/com/google/devtools/build/lib/worker/ExampleWorker.java index 07c5ed8f8fb54a..0d49037bd7c5f4 100644 --- a/src/test/java/com/google/devtools/build/lib/worker/ExampleWorker.java +++ b/src/test/java/com/google/devtools/build/lib/worker/ExampleWorker.java @@ -125,6 +125,7 @@ public void processRequests() throws IOException { public static void main(String[] args) throws Exception { if (ImmutableSet.copyOf(args).contains("--persistent_worker")) { + System.err.printf("Worker args: %s\n", String.join(" ", args)); OptionsParser parser = OptionsParser.builder() .optionsClasses(ExampleWorkerOptions.class) diff --git a/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerMultiplexer.java b/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerMultiplexer.java index 9fcbec8e804967..78933b487ca50c 100644 --- a/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerMultiplexer.java +++ b/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerMultiplexer.java @@ -78,6 +78,7 @@ private ExampleWorkerMultiplexer() {} public static void main(String[] args) throws Exception { if (ImmutableSet.copyOf(args).contains("--persistent_worker")) { + System.err.printf("Worker args: %s\n", String.join(" ", args)); OptionsParser parser = OptionsParser.builder() .optionsClasses(ExampleWorkerMultiplexerOptions.class) diff --git a/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerOptions.java b/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerOptions.java index eeccc2e35768d0..2897f9c6437ea2 100644 --- a/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerOptions.java +++ b/src/test/java/com/google/devtools/build/lib/worker/ExampleWorkerOptions.java @@ -163,6 +163,14 @@ public static class ExampleWorkOptions extends OptionsBase { help = "Don't send a response until receiving a cancel request.") public boolean waitForCancel; + @Option( + name = "ignored_argument", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.NO_OP}, + defaultValue = "false", + help = "An argument that does nothing, but whose presence can be asserted in a test.") + public boolean ignoredArgument; + /** Enum converter for --worker_protocol. */ public static class WorkerProtocolEnumConverter extends EnumConverter { diff --git a/src/test/shell/integration/bazel_worker_test.sh b/src/test/shell/integration/bazel_worker_test.sh index 345962b241ad0b..b91f866d6f07fc 100755 --- a/src/test/shell/integration/bazel_worker_test.sh +++ b/src/test/shell/integration/bazel_worker_test.sh @@ -322,6 +322,30 @@ EOF assert_equals "$worker_uuid_1" "$worker_uuid_2" } +function test_worker_extra_flag() { + prepare_example_worker + cat >>BUILD < "$TEST_log" || fail "build failed" + + local -r worker_log=$(egrep -o -- 'logging to .*/b(azel|laze)-workers/worker-[0-9]+-World.log' "$TEST_log" | sed 's/^logging to //') + + if ! [[ -e "$worker_log" ]]; then + fail "Worker log was not found" + fi + + assert_contains "Worker args: .* --ignored_argument" "$worker_log" +} + function test_multiple_flagfiles() { prepare_example_worker cat >>BUILD < $TEST_log