Skip to content

Commit a67d81e

Browse files
committed
[lit] Print internal env commands
Without this patch, the internal `env` command removes `env` and its args from the command line while parsing it. This patch modifies a copy instead so that the original command line is printed. Reviewed By: stella.stamenova, rnk Differential Revision: https://reviews.llvm.org/D65624 llvm-svn: 367752
1 parent 2c5a60f commit a67d81e

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,12 @@ def quote_windows_command(seq):
235235

236236
return ''.join(result)
237237

238-
# cmd is export or env
239-
def updateEnv(env, cmd):
238+
# args are from 'export' or 'env' command.
239+
# Returns copy of args without those commands or their arguments.
240+
def updateEnv(env, args):
240241
arg_idx = 1
241242
unset_next_env_var = False
242-
for arg_idx, arg in enumerate(cmd.args[1:]):
243+
for arg_idx, arg in enumerate(args[1:]):
243244
# Support for the -u flag (unsetting) for env command
244245
# e.g., env -u FOO -u BAR will remove both FOO and BAR
245246
# from the environment.
@@ -258,7 +259,7 @@ def updateEnv(env, cmd):
258259
if eq == '':
259260
break
260261
env.env[key] = val
261-
cmd.args = cmd.args[arg_idx+1:]
262+
return args[arg_idx+1:]
262263

263264
def executeBuiltinEcho(cmd, shenv):
264265
"""Interpret a redirected echo command"""
@@ -825,7 +826,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
825826
raise ValueError("'export' cannot be part of a pipeline")
826827
if len(cmd.commands[0].args) != 2:
827828
raise ValueError("'export' supports only one argument")
828-
updateEnv(shenv, cmd.commands[0])
829+
updateEnv(shenv, cmd.commands[0].args)
829830
return 0
830831

831832
if cmd.commands[0].args[0] == 'mkdir':
@@ -872,12 +873,13 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
872873
for i,j in enumerate(cmd.commands):
873874
# Reference the global environment by default.
874875
cmd_shenv = shenv
876+
args = list(j.args)
875877
if j.args[0] == 'env':
876878
# Create a copy of the global environment and modify it for this one
877879
# command. There might be multiple envs in a pipeline:
878880
# env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
879881
cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
880-
updateEnv(cmd_shenv, j)
882+
args = updateEnv(cmd_shenv, j.args)
881883

882884
stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv,
883885
opened_files)
@@ -899,7 +901,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
899901
stderrTempFiles.append((i, stderr))
900902

901903
# Resolve the executable path ourselves.
902-
args = list(j.args)
903904
executable = None
904905
is_builtin_cmd = args[0] in builtin_commands;
905906
if not is_builtin_cmd:
@@ -911,7 +912,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
911912
if not executable:
912913
executable = lit.util.which(args[0], cmd_shenv.env['PATH'])
913914
if not executable:
914-
raise InternalShellError(j, '%r: command not found' % j.args[0])
915+
raise InternalShellError(j, '%r: command not found' % args[0])
915916

916917
# Replace uses of /dev/null with temporary files.
917918
if kAvoidDevNull:

llvm/utils/lit/tests/shtest-env.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
# Check the env command
22
#
3-
# RUN: %{lit} -a -v %{inputs}/shtest-env
3+
# RUN: %{lit} -j 1 -a -v %{inputs}/shtest-env \
4+
# RUN: | FileCheck -match-full-lines %s
5+
#
6+
# END.
7+
8+
# Make sure env commands are included in printed commands.
9+
10+
# CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}})
11+
# CHECK: $ "{{[^"]*}}" "print_environment.py"
12+
# CHECK: $ "env" "-u" "FOO" "{{[^"]*}}" "print_environment.py"
13+
# CHECK: $ "env" "-u" "FOO" "-u" "BAR" "{{[^"]*}}" "print_environment.py"
14+
15+
# CHECK: PASS: shtest-env :: env.txt ({{[^)]*}})
16+
# CHECK: $ "env" "A_FOO=999" "{{[^"]*}}" "print_environment.py"
17+
# CHECK: $ "env" "A_FOO=1" "B_BAR=2" "C_OOF=3" "{{[^"]*}}" "print_environment.py"
18+
19+
# CHECK: PASS: shtest-env :: mixed.txt ({{[^)]*}})
20+
# CHECK: $ "env" "A_FOO=999" "-u" "FOO" "{{[^"]*}}" "print_environment.py"
21+
# CHECK: $ "env" "A_FOO=1" "-u" "FOO" "B_BAR=2" "-u" "BAR" "C_OOF=3" "{{[^"]*}}" "print_environment.py"
22+
23+
# CHECK: Expected Passes : 3

0 commit comments

Comments
 (0)