[llvm] [LIT] Fix env without subcommand causing early return in pipeline (PR #184028)
Aaron Chen via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 2 20:01:42 PST 2026
================
@@ -831,16 +831,28 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env, shenv.umask)
args = updateEnv(cmd_shenv, args)
if not args:
- # Return the environment variables if no argument is provided.
- env_str = "\n".join(
- f"{key}={value}" for key, value in sorted(cmd_shenv.env.items())
- )
- results.append(
- ShellCommandResult(
- j, env_str, "", 0, timeoutHelper.timeoutReached(), []
+ if len(cmd.commands) == 1:
+ # Single command: return environment variables in-process.
+ env_str = "\n".join(
+ f"{key}={value}" for key, value in sorted(cmd_shenv.env.items())
)
- )
- return 0
+ results.append(
+ ShellCommandResult(
+ j, env_str, "", 0, timeoutHelper.timeoutReached(), []
+ )
+ )
+ return 0
+ # Pipeline: replace with a subprocess that prints the
+ # environment variables to stdout so the output can be
+ # piped to the next command.
+ args = [
+ sys.executable,
+ "-c",
+ "import os, sys; sys.stdout.write("
+ "'\\n'.join(k + '=' + v"
+ " for k, v in sorted(os.environ.items())) + '\\n')",
+ ]
----------------
nailo2c wrote:
How about moving the env printing logic into a standalone script in `builtin_commands` (like `env.py`)?
I think this would be easier to read and maintain than the current version, following the pattern we already use here:
https://github.com/llvm/llvm-project/blob/6d25af00ac475e0b1f7d2b7a9ca24a223930a8d2/llvm/utils/lit/lit/TestRunner.py#L982-L983
https://github.com/llvm/llvm-project/pull/184028
More information about the llvm-commits
mailing list