llvm.org GIT mirror llvm / 06cbc25
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367752 91177308-0d34-0410-b5e6-96231b3b80d8 Joel E. Denny a month ago
2 changed file(s) with 30 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
234234
235235 return ''.join(result)
236236
237 # cmd is export or env
238 def updateEnv(env, cmd):
237 # args are from 'export' or 'env' command.
238 # Returns copy of args without those commands or their arguments.
239 def updateEnv(env, args):
239240 arg_idx = 1
240241 unset_next_env_var = False
241 for arg_idx, arg in enumerate(cmd.args[1:]):
242 for arg_idx, arg in enumerate(args[1:]):
242243 # Support for the -u flag (unsetting) for env command
243244 # e.g., env -u FOO -u BAR will remove both FOO and BAR
244245 # from the environment.
257258 if eq == '':
258259 break
259260 env.env[key] = val
260 cmd.args = cmd.args[arg_idx+1:]
261 return args[arg_idx+1:]
261262
262263 def executeBuiltinEcho(cmd, shenv):
263264 """Interpret a redirected echo command"""
824825 raise ValueError("'export' cannot be part of a pipeline")
825826 if len(cmd.commands[0].args) != 2:
826827 raise ValueError("'export' supports only one argument")
827 updateEnv(shenv, cmd.commands[0])
828 updateEnv(shenv, cmd.commands[0].args)
828829 return 0
829830
830831 if cmd.commands[0].args[0] == 'mkdir':
871872 for i,j in enumerate(cmd.commands):
872873 # Reference the global environment by default.
873874 cmd_shenv = shenv
875 args = list(j.args)
874876 if j.args[0] == 'env':
875877 # Create a copy of the global environment and modify it for this one
876878 # command. There might be multiple envs in a pipeline:
877879 # env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
878880 cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
879 updateEnv(cmd_shenv, j)
881 args = updateEnv(cmd_shenv, j.args)
880882
881883 stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv,
882884 opened_files)
898900 stderrTempFiles.append((i, stderr))
899901
900902 # Resolve the executable path ourselves.
901 args = list(j.args)
902903 executable = None
903904 is_builtin_cmd = args[0] in builtin_commands;
904905 if not is_builtin_cmd:
910911 if not executable:
911912 executable = lit.util.which(args[0], cmd_shenv.env['PATH'])
912913 if not executable:
913 raise InternalShellError(j, '%r: command not found' % j.args[0])
914 raise InternalShellError(j, '%r: command not found' % args[0])
914915
915916 # Replace uses of /dev/null with temporary files.
916917 if kAvoidDevNull:
0 # Check the env command
11 #
2 # RUN: %{lit} -a -v %{inputs}/shtest-env
2 # RUN: %{lit} -j 1 -a -v %{inputs}/shtest-env \
3 # RUN: | FileCheck -match-full-lines %s
4 #
5 # END.
6
7 # Make sure env commands are included in printed commands.
8
9 # CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}})
10 # CHECK: $ "{{[^"]*}}" "print_environment.py"
11 # CHECK: $ "env" "-u" "FOO" "{{[^"]*}}" "print_environment.py"
12 # CHECK: $ "env" "-u" "FOO" "-u" "BAR" "{{[^"]*}}" "print_environment.py"
13
14 # CHECK: PASS: shtest-env :: env.txt ({{[^)]*}})
15 # CHECK: $ "env" "A_FOO=999" "{{[^"]*}}" "print_environment.py"
16 # CHECK: $ "env" "A_FOO=1" "B_BAR=2" "C_OOF=3" "{{[^"]*}}" "print_environment.py"
17
18 # CHECK: PASS: shtest-env :: mixed.txt ({{[^)]*}})
19 # CHECK: $ "env" "A_FOO=999" "-u" "FOO" "{{[^"]*}}" "print_environment.py"
20 # CHECK: $ "env" "A_FOO=1" "-u" "FOO" "B_BAR=2" "-u" "BAR" "C_OOF=3" "{{[^"]*}}" "print_environment.py"
21
22 # CHECK: Expected Passes : 3