[PATCH] D65624: [lit] Print internal env commands

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rL367752: [lit] Print internal env commands (authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D65624?vs=213115&id=213180#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65624/new/

https://reviews.llvm.org/D65624

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


Index: llvm/trunk/utils/lit/lit/TestRunner.py
===================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py
+++ llvm/trunk/utils/lit/lit/TestRunner.py
@@ -235,11 +235,12 @@
 
     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 @@
         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 @@
             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 @@
     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 @@
                 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 @@
             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:
Index: llvm/trunk/utils/lit/tests/shtest-env.py
===================================================================
--- llvm/trunk/utils/lit/tests/shtest-env.py
+++ llvm/trunk/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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65624.213180.patch
Type: text/x-patch
Size: 3912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190803/17ed55fb/attachment.bin>


More information about the llvm-commits mailing list