[llvm] r272293 - Revert "[lit] Use os.devnull instead of named temp files"
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 9 12:36:48 PDT 2016
Author: vedantk
Date: Thu Jun 9 14:36:48 2016
New Revision: 272293
URL: http://llvm.org/viewvc/llvm-project?rev=272293&view=rev
Log:
Revert "[lit] Use os.devnull instead of named temp files"
This reverts commit r272290. It breaks a test that depends on being able
to seek the /dev/null equivalent on Windows:
http://bb.pgr.jp/builders/ninja-clang-x64-mingw64-RA/builds/11360
Modified:
llvm/trunk/utils/lit/lit/TestRunner.py
Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=272293&r1=272292&r2=272293&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Thu Jun 9 14:36:48 2016
@@ -20,6 +20,9 @@ kIsWindows = platform.system() == 'Windo
# 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.
@@ -189,6 +192,7 @@ def _executeShCmd(cmd, shenv, results, t
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.
@@ -252,8 +256,8 @@ def _executeShCmd(cmd, shenv, results, t
else:
if r[2] is None:
redir_filename = None
- if kIsWindows and r[0] == '/dev/null':
- r[2] = open(os.devnull, r[1])
+ if kAvoidDevNull and r[0] == '/dev/null':
+ r[2] = tempfile.TemporaryFile(mode=r[1])
elif kIsWindows and r[0] == '/dev/tty':
# Simulate /dev/tty on Windows.
# "CON" is a special filename for the console.
@@ -302,11 +306,14 @@ def _executeShCmd(cmd, shenv, results, t
if not executable:
raise InternalShellError(j, '%r: command not found' % j.args[0])
- if kIsWindows:
- # Replace uses of /dev/null with the Windows equivalent.
+ # Replace uses of /dev/null with temporary files.
+ if kAvoidDevNull:
for i,arg in enumerate(args):
if arg == "/dev/null":
- args[i] = os.devnull
+ f = tempfile.NamedTemporaryFile(delete=False)
+ f.close()
+ named_temp_files.append(f.name)
+ args[i] = f.name
try:
procs.append(subprocess.Popen(args, cwd=cmd_shenv.cwd,
@@ -415,6 +422,13 @@ def _executeShCmd(cmd, shenv, results, t
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
More information about the llvm-commits
mailing list