From 06cbc253a71daacb94bc69e3d1d3113824d9ddca Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Sat, 3 Aug 2019 06:08:19 +0000 Subject: [PATCH] [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 --- utils/lit/lit/TestRunner.py | 17 +++++++++-------- utils/lit/tests/shtest-env.py | 22 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py index ac627d51c1c..f8a00567c3c 100644 --- a/utils/lit/lit/TestRunner.py +++ b/utils/lit/lit/TestRunner.py @@ -235,11 +235,12 @@ def quote_windows_command(seq): return ''.join(result) -# cmd is export or env -def updateEnv(env, cmd): +# args are from 'export' or 'env' command. +# Returns copy of args without those commands or their arguments. +def updateEnv(env, args): arg_idx = 1 unset_next_env_var = False - for arg_idx, arg in enumerate(cmd.args[1:]): + for arg_idx, arg in enumerate(args[1:]): # Support for the -u flag (unsetting) for env command # e.g., env -u FOO -u BAR will remove both FOO and BAR # from the environment. @@ -258,7 +259,7 @@ def updateEnv(env, cmd): if eq == '': break env.env[key] = val - cmd.args = cmd.args[arg_idx+1:] + return args[arg_idx+1:] def executeBuiltinEcho(cmd, shenv): """Interpret a redirected echo command""" @@ -825,7 +826,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): raise ValueError("'export' cannot be part of a pipeline") if len(cmd.commands[0].args) != 2: raise ValueError("'export' supports only one argument") - updateEnv(shenv, cmd.commands[0]) + updateEnv(shenv, cmd.commands[0].args) return 0 if cmd.commands[0].args[0] == 'mkdir': @@ -872,12 +873,13 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): for i,j in enumerate(cmd.commands): # Reference the global environment by default. cmd_shenv = shenv + args = list(j.args) if j.args[0] == 'env': # Create a copy of the global environment and modify it for this one # command. There might be multiple envs in a pipeline: # env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env) - updateEnv(cmd_shenv, j) + args = updateEnv(cmd_shenv, j.args) stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv, opened_files) @@ -899,7 +901,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): stderrTempFiles.append((i, stderr)) # Resolve the executable path ourselves. - args = list(j.args) executable = None is_builtin_cmd = args[0] in builtin_commands; if not is_builtin_cmd: @@ -911,7 +912,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): if not executable: executable = lit.util.which(args[0], cmd_shenv.env['PATH']) if not executable: - raise InternalShellError(j, '%r: command not found' % j.args[0]) + raise InternalShellError(j, '%r: command not found' % args[0]) # Replace uses of /dev/null with temporary files. if kAvoidDevNull: diff --git a/utils/lit/tests/shtest-env.py b/utils/lit/tests/shtest-env.py index fc5f973e676..ceabcada677 100644 --- a/utils/lit/tests/shtest-env.py +++ b/utils/lit/tests/shtest-env.py @@ -1,3 +1,23 @@ # Check the env command # -# RUN: %{lit} -a -v %{inputs}/shtest-env +# RUN: %{lit} -j 1 -a -v %{inputs}/shtest-env \ +# RUN: | FileCheck -match-full-lines %s +# +# END. + +# Make sure env commands are included in printed commands. + +# CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}}) +# CHECK: $ "{{[^"]*}}" "print_environment.py" +# CHECK: $ "env" "-u" "FOO" "{{[^"]*}}" "print_environment.py" +# CHECK: $ "env" "-u" "FOO" "-u" "BAR" "{{[^"]*}}" "print_environment.py" + +# CHECK: PASS: shtest-env :: env.txt ({{[^)]*}}) +# CHECK: $ "env" "A_FOO=999" "{{[^"]*}}" "print_environment.py" +# CHECK: $ "env" "A_FOO=1" "B_BAR=2" "C_OOF=3" "{{[^"]*}}" "print_environment.py" + +# CHECK: PASS: shtest-env :: mixed.txt ({{[^)]*}}) +# CHECK: $ "env" "A_FOO=999" "-u" "FOO" "{{[^"]*}}" "print_environment.py" +# CHECK: $ "env" "A_FOO=1" "-u" "FOO" "B_BAR=2" "-u" "BAR" "C_OOF=3" "{{[^"]*}}" "print_environment.py" + +# CHECK: Expected Passes : 3 -- 2.49.0