Skip to content

Commit 1783924

Browse files
authored
[llvm-lit] Print environment variables when using env without subcommand (#98414)
This patch addresses an issue with lit's internal shell when env is without any arguments, it fails with exit code 127 because `env` requires a subcommand. This patch addresses the issue by encoding the command to properly return environment variables even when no arguments are provided. The error occurred when running the command ` LIT_USE_INTERNAL_SHELL=1 ninja check-llvm`. fixes: #102383 This is part of the test cleanups proposed in the RFC: [[RFC] Enabling the Lit Internal Shell by Default](https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179)
1 parent eed135f commit 1783924

28 files changed

+265
-225
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,16 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
742742
cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
743743
args = updateEnv(cmd_shenv, args)
744744
if not args:
745-
raise InternalShellError(j, "Error: 'env' requires a" " subcommand")
745+
# Return the environment variables if no argument is provided.
746+
env_str = "\n".join(
747+
f"{key}={value}" for key, value in sorted(cmd_shenv.env.items())
748+
)
749+
results.append(
750+
ShellCommandResult(
751+
j, env_str, "", 0, timeoutHelper.timeoutReached(), []
752+
)
753+
)
754+
return 0
746755
elif args[0] == "not":
747756
not_args.append(args.pop(0))
748757
not_count += 1

llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg renamed to llvm/utils/lit/tests/Inputs/shtest-env-negative/lit.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ config.test_source_root = None
77
config.test_exec_root = None
88
config.environment["FOO"] = "1"
99
config.environment["BAR"] = "2"
10+
config.environment["QUX"] = "3"
1011
config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))

0 commit comments

Comments
 (0)