1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

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

Use os.devnull instead of tempfiles when substituting '/dev/null' on
Windows machines. This should make the bots just a bit speedier.

Thanks to Yunzhong Gao for testing this patch on Windows!

Differential Revision: http://reviews.llvm.org/D20549

llvm-svn: 272290
This commit is contained in:
Vedant Kumar 2016-06-09 18:38:41 +00:00
parent 74b1dfdd84
commit 6e905448d5

View File

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