[PATCH] D20549: [lit] Use os.devnull instead of named temp files

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 9 11:45:23 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL272290: [lit] Use os.devnull instead of named temp files (authored by vedantk).

Changed prior to commit:
  http://reviews.llvm.org/D20549?vs=58179&id=60219#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20549

Files:
  llvm/trunk/utils/lit/lit/TestRunner.py

Index: llvm/trunk/utils/lit/lit/TestRunner.py
===================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py
+++ llvm/trunk/utils/lit/lit/TestRunner.py
@@ -20,9 +20,6 @@
 # Don't use close_fds on Windows.
 kUseCloseFDs = not kIsWindows
 
-# Use temporary files to replace /dev/null on Windows.
-kAvoidDevNull = kIsWindows
-
 class ShellEnvironment(object):
 
     """Mutable shell environment containing things like CWD and env vars.
@@ -192,7 +189,6 @@
     input = subprocess.PIPE
     stderrTempFiles = []
     opened_files = []
-    named_temp_files = []
     # To avoid deadlock, we use a single stderr stream for piped
     # output. This is null until we have seen some output using
     # stderr.
@@ -256,8 +252,8 @@
             else:
                 if r[2] is None:
                     redir_filename = None
-                    if kAvoidDevNull and r[0] == '/dev/null':
-                        r[2] = tempfile.TemporaryFile(mode=r[1])
+                    if kIsWindows and r[0] == '/dev/null':
+                        r[2] = open(os.devnull, r[1])
                     elif kIsWindows and r[0] == '/dev/tty':
                         # Simulate /dev/tty on Windows.
                         # "CON" is a special filename for the console.
@@ -306,14 +302,11 @@
         if not executable:
             raise InternalShellError(j, '%r: command not found' % j.args[0])
 
-        # Replace uses of /dev/null with temporary files.
-        if kAvoidDevNull:
+        if kIsWindows:
+            # Replace uses of /dev/null with the Windows equivalent.
             for i,arg in enumerate(args):
                 if arg == "/dev/null":
-                    f = tempfile.NamedTemporaryFile(delete=False)
-                    f.close()
-                    named_temp_files.append(f.name)
-                    args[i] = f.name
+                    args[i] = os.devnull
 
         try:
             procs.append(subprocess.Popen(args, cwd=cmd_shenv.cwd,
@@ -422,13 +415,6 @@
         else:
             exitCode = res
 
-    # Remove any named temporary files we created.
-    for f in named_temp_files:
-        try:
-            os.remove(f)
-        except OSError:
-            pass
-
     if cmd.negate:
         exitCode = not exitCode
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20549.60219.patch
Type: text/x-patch
Size: 2301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160609/fd6d0cd2/attachment.bin>


More information about the llvm-commits mailing list