Skip to content

Commit 4d27da9

Browse files
committedJun 9, 2016
[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
1 parent 54238fd commit 4d27da9

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed
 

‎llvm/utils/lit/lit/TestRunner.py

+5-19
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ def __init__(self, command, message):
2020
# Don't use close_fds on Windows.
2121
kUseCloseFDs = not kIsWindows
2222

23-
# Use temporary files to replace /dev/null on Windows.
24-
kAvoidDevNull = kIsWindows
25-
2623
class ShellEnvironment(object):
2724

2825
"""Mutable shell environment containing things like CWD and env vars.
@@ -192,7 +189,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
192189
input = subprocess.PIPE
193190
stderrTempFiles = []
194191
opened_files = []
195-
named_temp_files = []
196192
# To avoid deadlock, we use a single stderr stream for piped
197193
# output. This is null until we have seen some output using
198194
# stderr.
@@ -256,8 +252,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
256252
else:
257253
if r[2] is None:
258254
redir_filename = None
259-
if kAvoidDevNull and r[0] == '/dev/null':
260-
r[2] = tempfile.TemporaryFile(mode=r[1])
255+
if kIsWindows and r[0] == '/dev/null':
256+
r[2] = open(os.devnull, r[1])
261257
elif kIsWindows and r[0] == '/dev/tty':
262258
# Simulate /dev/tty on Windows.
263259
# "CON" is a special filename for the console.
@@ -306,14 +302,11 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
306302
if not executable:
307303
raise InternalShellError(j, '%r: command not found' % j.args[0])
308304

309-
# Replace uses of /dev/null with temporary files.
310-
if kAvoidDevNull:
305+
if kIsWindows:
306+
# Replace uses of /dev/null with the Windows equivalent.
311307
for i,arg in enumerate(args):
312308
if arg == "/dev/null":
313-
f = tempfile.NamedTemporaryFile(delete=False)
314-
f.close()
315-
named_temp_files.append(f.name)
316-
args[i] = f.name
309+
args[i] = os.devnull
317310

318311
try:
319312
procs.append(subprocess.Popen(args, cwd=cmd_shenv.cwd,
@@ -422,13 +415,6 @@ def to_string(bytes):
422415
else:
423416
exitCode = res
424417

425-
# Remove any named temporary files we created.
426-
for f in named_temp_files:
427-
try:
428-
os.remove(f)
429-
except OSError:
430-
pass
431-
432418
if cmd.negate:
433419
exitCode = not exitCode
434420

0 commit comments

Comments
 (0)