[llvm] [llvm-lit] Add redirection handling for `env` command without args and write a lit test to check behavior with lit internal shell (PR #106629)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 23:00:42 PDT 2024
================
@@ -746,11 +746,25 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
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(), []
- )
+ # Process redirections.
+ stdin, stdout, stderr = processRedirects(
+ j, default_stdin, cmd_shenv, opened_files
)
+ if stdout != default_stdin:
----------------
Harini0924 wrote:
The input argument (`default_stdin`, which is set to `subprocess.PIPE`) is not always returned directly as `stdout` by the `processRedirects` function. The function's purpose is to handle any redirections specified in the command. If there's a redirection for `stdout` (like `>` or `>>`), `processRedirects` will open a file and return a file descriptor for that file instead of returning the original `subprocess.PIPE`.
So, when you pass `subprocess.PIPE` as the default for `stdout`, `processRedirects` might override it with a different file descriptor if redirection is specified. If no redirection is specified, then it could return `subprocess.PIPE` as it was originally passed. This means the condition `if stdout != default_stdin` is designed to check whether `stdout` was redirected to something other than the pipe, and it's not always true—it depends on whether any redirection was applied.
Did that answer your question?
https://github.com/llvm/llvm-project/pull/106629
More information about the llvm-commits
mailing list