lit: Replace /dev/null in scripts with temporary files on Windows.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 12 Jun 2010 16:00:10 +0000 (16:00 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 12 Jun 2010 16:00:10 +0000 (16:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105888 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/TestRunner.py

index 495badb622b3c6bea8b4833e36638d2d694e8363..cdf1c938af8c75634fd30a19fa4e36de7b00a493 100644 (file)
@@ -66,6 +66,7 @@ def executeShCmd(cmd, cfg, cwd, results):
     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.
@@ -148,6 +149,15 @@ def executeShCmd(cmd, cfg, cwd, results):
         if not args[0]:
             raise InternalShellError(j, '%r: command not found' % j.args[0])
 
+        # Replace uses of /dev/null with temporary files.
+        if kAvoidDevNull:
+            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
+
         procs.append(subprocess.Popen(args, cwd=cwd,
                                       stdin = stdin,
                                       stdout = stdout,
@@ -209,6 +219,13 @@ def executeShCmd(cmd, cfg, cwd, results):
     for f in opened_files:
         f.close()
 
+    # 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