lit: Allow use of /dev/null in redirects on Windows (replace by a temporary
authorDaniel Dunbar <daniel@zuster.org>
Sun, 25 Oct 2009 01:37:26 +0000 (01:37 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 25 Oct 2009 01:37:26 +0000 (01:37 +0000)
file).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85028 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/TestRunner.py

index 356632e92f3b927d777dae7c5f929a581b392adc..a2a9e3629ca869f2d86f48556b511e0ee3cf24eb 100644 (file)
@@ -15,6 +15,10 @@ class InternalShellError(Exception):
 
 # Don't use close_fds on Windows.
 kUseCloseFDs = platform.system() != 'Windows'
+
+# Use temporary files to replace /dev/null on Windows.
+kAvoidDevNull = platform.system() == 'Windows'
+
 def executeCommand(command, cwd=None, env=None):
     p = subprocess.Popen(command, cwd=cwd,
                          stdin=subprocess.PIPE,
@@ -104,7 +108,10 @@ def executeShCmd(cmd, cfg, cwd, results):
                 result = subprocess.PIPE
             else:
                 if r[2] is None:
-                    r[2] = open(r[0], r[1])
+                    if kAvoidDevNull and r[0] == '/dev/null':
+                        r[2] = tempfile.TemporaryFile(mode=r[1])
+                    else:
+                        r[2] = open(r[0], r[1])
                 result = r[2]
             final_redirects.append(result)