Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.1.0] Emit spawn runner with --subcommands #25051

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ public <T extends ActionContext> T getContext(Class<T> type) {
}

/**
* Report a subcommand event to this Executor's Reporter and, if action
* logging is enabled, post it on its EventBus.
* Report a subcommand event to this Executor's Reporter and, if action logging is enabled, post
* it on its EventBus.
*/
public void maybeReportSubcommand(Spawn spawn) {
public void maybeReportSubcommand(Spawn spawn, @Nullable String spawnRunner) {
ShowSubcommands showSubcommands = executor.reportsSubcommands();
if (!showSubcommands.shouldShowSubcommands) {
return;
Expand Down Expand Up @@ -489,7 +489,8 @@ public void maybeReportSubcommand(Spawn spawn) {
/* environmentVariablesToClear= */ null,
getExecRoot().getPathString(),
spawn.getConfigurationChecksum(),
spawn.getExecutionPlatformLabel());
spawn.getExecutionPlatformLabel(),
spawnRunner);
getEventHandler().handle(Event.of(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public ImmutableList<SpawnResult> exec(
ActionExecutionContext actionExecutionContext,
@Nullable SandboxedSpawnStrategy.StopConcurrentSpawns stopConcurrentSpawns)
throws ExecException, InterruptedException {
actionExecutionContext.maybeReportSubcommand(spawn);
actionExecutionContext.maybeReportSubcommand(spawn, spawnRunner.getName());

final Duration timeout = Spawns.getTimeout(spawn);
SpawnExecutionContext context =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private static InputStream spawnGrep(
outputs,
LOCAL_RESOURCES);

actionExecutionContext.maybeReportSubcommand(spawn);
actionExecutionContext.maybeReportSubcommand(spawn, /* spawnRunner= */ null);

// Don't share the originalOutErr across spawnGrep calls. Doing so would not be thread-safe.
FileOutErr originalOutErr = actionExecutionContext.getFileOutErr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ private void writeAction(ActionAnalysisMetadata action, PrintStream printStream)
action.getOwner().getConfigurationChecksum(),
action.getExecutionPlatform() != null
? action.getExecutionPlatform().label()
: null))
: null,
/* spawnRunner= */ null))
.append("\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public Optional<String> getInteractiveDebugInstructions() {
/* environmentVariablesToClear= */ null,
/* cwd= */ null,
/* configurationChecksum= */ null,
/* executionPlatformLabel= */ null));
/* executionPlatformLabel= */ null,
/* spawnRunner= */ null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public static String describeCommand(
@Nullable List<String> environmentVariablesToClear,
@Nullable String cwd,
@Nullable String configurationChecksum,
@Nullable Label executionPlatformLabel) {
@Nullable Label executionPlatformLabel,
@Nullable String spawnRunner) {

Preconditions.checkNotNull(form);
StringBuilder message = new StringBuilder();
Expand Down Expand Up @@ -134,6 +135,11 @@ public static String describeCommand(
message.append("\n");
message.append("# Execution platform: ").append(executionPlatformLabel);
}

if (spawnRunner != null) {
message.append("\n");
message.append("# Runner: ").append(spawnRunner);
}
}

return message.toString();
Expand All @@ -152,7 +158,8 @@ static String describeCommandFailure(
@Nullable String cwd,
@Nullable String configurationChecksum,
@Nullable Label targetLabel,
@Nullable Label executionPlatformLabel) {
@Nullable Label executionPlatformLabel,
@Nullable String spawnRunner) {

String commandName = commandLineElements.iterator().next();
// Extract the part of the command name after the last "/", if any.
Expand Down Expand Up @@ -181,7 +188,8 @@ static String describeCommandFailure(
null,
cwd,
configurationChecksum,
executionPlatformLabel));
executionPlatformLabel,
spawnRunner));
return shortCommandName + " failed: " + output;
}

Expand All @@ -195,6 +203,7 @@ public static String describeCommandFailure(
cwd,
command.getConfigurationChecksum(),
command.getTargetLabel(),
command.getExecutionPlatformLabel());
command.getExecutionPlatformLabel(),
/* spawnRunner= */ null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public String toString() {
/* environmentVariablesToClear= */ null,
execRoot.getPathString(),
/* configurationChecksum= */ null,
/* executionPlatformLabel= */ null);
/* executionPlatformLabel= */ null,
/* spawnRunner= */ getWorkerTypeName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void describeCommandFailure() throws Exception {
cwd,
"cfg12345",
target,
executionPlatform.label());
executionPlatform.label(),
"local");
assertThat(message)
.isEqualTo(
"sh failed: error executing Mnemonic command (from target //foo:bar) "
Expand Down Expand Up @@ -80,16 +81,20 @@ public void describeCommandFailure_verbose() throws Exception {
cwd,
"cfg12345",
target,
executionPlatform.label());
executionPlatform.label(),
"local");
assertThat(message)
.isEqualTo(
"sh failed: error executing Mnemonic command (from target //foo:bar) \n"
+ " (exec env - \\\n"
+ " FOO=foo \\\n"
+ " PATH=/usr/bin:/bin:/sbin \\\n"
+ " /bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42')\n"
+ "# Configuration: cfg12345\n"
+ "# Execution platform: //platform:exec");
"""
sh failed: error executing Mnemonic command (from target //foo:bar)\s
(exec env - \\
FOO=foo \\
PATH=/usr/bin:/bin:/sbin \\
/bin/sh -c 'echo Some errors 1>&2; echo Some output; exit 42')
# Configuration: cfg12345
# Execution platform: //platform:exec
# Runner: local\
""");
}

@Test
Expand Down Expand Up @@ -117,7 +122,8 @@ public void describeCommandFailure_longMessage() throws Exception {
cwd,
"cfg12345",
target,
executionPlatform.label());
executionPlatform.label(),
"local");
assertThat(message)
.isEqualTo(
"some_command failed: error executing Mnemonic command (from target //foo:bar) "
Expand Down Expand Up @@ -153,21 +159,25 @@ public void describeCommandFailure_longMessage_verbose() throws Exception {
cwd,
"cfg12345",
target,
executionPlatform.label());
executionPlatform.label(),
"local");
assertThat(message)
.isEqualTo(
"some_command failed: error executing Mnemonic command (from target //foo:bar) \n"
+ " (cd /my/working/directory && \\\n"
+ " exec env - \\\n"
+ " FOO=foo \\\n"
+ " PATH=/usr/bin:/bin:/sbin \\\n"
+ " some_command arg1 arg2 arg3 arg4 arg5 arg6 'with spaces' arg8 '*' arg10 "
+ "arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 "
+ "arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 "
+ "arg27 arg28 arg29 arg30 arg31 arg32 arg33 arg34 "
+ "arg35 arg36 arg37 arg38 arg39)\n"
+ "# Configuration: cfg12345\n"
+ "# Execution platform: //platform:exec");
"""
some_command failed: error executing Mnemonic command (from target //foo:bar)\s
(cd /my/working/directory && \\
exec env - \\
FOO=foo \\
PATH=/usr/bin:/bin:/sbin \\
some_command arg1 arg2 arg3 arg4 arg5 arg6 'with spaces' arg8 '*' arg10 \
arg11 arg12 arg13 arg14 arg15 arg16 arg17 arg18 \
arg19 arg20 arg21 arg22 arg23 arg24 arg25 arg26 \
arg27 arg28 arg29 arg30 arg31 arg32 arg33 arg34 \
arg35 arg36 arg37 arg38 arg39)
# Configuration: cfg12345
# Execution platform: //platform:exec
# Runner: local\
""");
}

@Test
Expand All @@ -191,7 +201,8 @@ public void describeCommandFailure_singleSkippedArgument() throws Exception {
cwd,
"cfg12345",
target,
executionPlatform.label());
executionPlatform.label(),
"local");
assertThat(message)
.isEqualTo(
"some_command failed: error executing Mnemonic command (from target //foo:bar)"
Expand Down Expand Up @@ -230,23 +241,27 @@ public void describeCommandPrettyPrintArgs() throws Exception {
envToClear,
cwd,
"cfg12345",
executionPlatform.label());
executionPlatform.label(),
"remote");

assertThat(message)
.isEqualTo(
"(cd /my/working/directory && \\\n"
+ " exec env - \\\n"
+ " -u CLEAR \\\n"
+ " -u THIS \\\n"
+ " FOO=foo \\\n"
+ " PATH=/usr/bin:/bin:/sbin \\\n"
+ " some_command \\\n"
+ " arg1 \\\n"
+ " arg2 \\\n"
+ " 'with spaces' \\\n"
+ " '*' \\\n"
+ " arg5)\n"
+ "# Configuration: cfg12345\n"
+ "# Execution platform: //platform:exec");
"""
(cd /my/working/directory && \\
exec env - \\
-u CLEAR \\
-u THIS \\
FOO=foo \\
PATH=/usr/bin:/bin:/sbin \\
some_command \\
arg1 \\
arg2 \\
'with spaces' \\
'*' \\
arg5)
# Configuration: cfg12345
# Execution platform: //platform:exec
# Runner: remote\
""");
}
}
Loading