[llvm] r367752 - [lit] Print internal env commands

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 23:08:20 PDT 2019


Author: jdenny
Date: Fri Aug  2 23:08:19 2019
New Revision: 367752

URL: http://llvm.org/viewvc/llvm-project?rev=367752&view=rev
Log:
[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

Modified:
    llvm/trunk/utils/lit/lit/TestRunner.py
    llvm/trunk/utils/lit/tests/shtest-env.py

Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=367752&r1=367751&r2=367752&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Fri Aug  2 23:08:19 2019
@@ -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, t
             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, t
     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, t
                 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, t
             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:

Modified: llvm/trunk/utils/lit/tests/shtest-env.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shtest-env.py?rev=367752&r1=367751&r2=367752&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/shtest-env.py (original)
+++ llvm/trunk/utils/lit/tests/shtest-env.py Fri Aug  2 23:08:19 2019
@@ -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




More information about the llvm-commits mailing list