[llvm] [llvm-lit] Resolve env subcommand required error (PR #98414)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 15:28:26 PDT 2024


================
@@ -744,7 +744,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
                 args = updateEnv(cmd_shenv, args)
                 if not args:
                     # Return the environment variables if no argument is provided 
-                    return {key: value for key, value in cmd_shenv.env.items()}
+                    env_str = "\n".join(f"{key}={value}" for key, value in cmd_shenv.env.items())
+                    results.append(ShellCommandResult(j, env_str, "", 0 , timeoutHelper.timeoutReached(), []))
+                    return 0
----------------
Harini0924 wrote:

@ilovepi @petrhosek I made changes to the handling of the `env` command when no arguments are provided to ensure compatibility with piped commands and maintain the correct exit codes. Previously, the code raised an error if env had no arguments, which would break commands like `env | grep TERM `. By modifying the code to generate a string of environment variables and append it to the results list, the env command can now function correctly in pipelines, allowing subsequent commands to receive the expected input. Additionally, it  returns 0, signifying successful execution and maintaining consistency across different execution paths. I tested these changes by running `LIT_USE_INTERNAL_SHELL=1 ninja check-all`, and the tests pass, confirming that the modifications work across the project.

https://github.com/llvm/llvm-project/pull/98414


More information about the llvm-commits mailing list