[PATCH] D22144: [lit] add support for unsetting environment variable

Jonathan Peyton via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 10:44:38 PDT 2016


jlpeyton created this revision.
jlpeyton added a reviewer: ddunbar.
jlpeyton added a subscriber: llvm-commits.
jlpeyton set the repository for this revision to rL LLVM.

This patch adds support for the -u flag for the env command.  The -u flag allows users to explicitly unset an environment variable for a particular command.  This is useful for OpenMP which heavily relies on environment variables to determine the library's behavior in certain situations.  So being able to unset a potentially polluted environment is important.

Example usage:
env -u FOO -u BAR GOO=16 CAR=5
This removes both FOO and BAR from the environment while setting GOO=16 and HAR=5.

Repository:
  rL LLVM

http://reviews.llvm.org/D22144

Files:
  lit/TestRunner.py

Index: lit/TestRunner.py
===================================================================
--- lit/TestRunner.py
+++ lit/TestRunner.py
@@ -205,7 +205,20 @@
             #   env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
             cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
             arg_idx = 1
+            unset_next_env_var = False
             for arg_idx, arg in enumerate(j.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.
+                if arg == '-u':
+                    unset_next_env_var = True
+                    continue
+                if unset_next_env_var:
+                    unset_next_env_var = False
+                    if arg in cmd_shenv.env:
+                        del cmd_shenv.env[arg]
+                    continue
+
                 # Partition the string into KEY=VALUE.
                 key, eq, val = arg.partition('=')
                 # Stop if there was no equals.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22144.63256.patch
Type: text/x-patch
Size: 1077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160708/e6dc70db/attachment.bin>


More information about the llvm-commits mailing list