llvm.org GIT mirror llvm / 4342472
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272293 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 4 years ago
1 changed file(s) with 19 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
1818
1919 # Don't use close_fds on Windows.
2020 kUseCloseFDs = not kIsWindows
21
22 # Use temporary files to replace /dev/null on Windows.
23 kAvoidDevNull = kIsWindows
2124
2225 class ShellEnvironment(object):
2326
188191 input = subprocess.PIPE
189192 stderrTempFiles = []
190193 opened_files = []
194 named_temp_files = []
191195 # To avoid deadlock, we use a single stderr stream for piped
192196 # output. This is null until we have seen some output using
193197 # stderr.
251255 else:
252256 if r[2] is None:
253257 redir_filename = None
254 if kIsWindows and r[0] == '/dev/null':
255 r[2] = open(os.devnull, r[1])
258 if kAvoidDevNull and r[0] == '/dev/null':
259 r[2] = tempfile.TemporaryFile(mode=r[1])
256260 elif kIsWindows and r[0] == '/dev/tty':
257261 # Simulate /dev/tty on Windows.
258262 # "CON" is a special filename for the console.
301305 if not executable:
302306 raise InternalShellError(j, '%r: command not found' % j.args[0])
303307
304 if kIsWindows:
305 # Replace uses of /dev/null with the Windows equivalent.
308 # Replace uses of /dev/null with temporary files.
309 if kAvoidDevNull:
306310 for i,arg in enumerate(args):
307311 if arg == "/dev/null":
308 args[i] = os.devnull
312 f = tempfile.NamedTemporaryFile(delete=False)
313 f.close()
314 named_temp_files.append(f.name)
315 args[i] = f.name
309316
310317 try:
311318 procs.append(subprocess.Popen(args, cwd=cmd_shenv.cwd,
414421 else:
415422 exitCode = res
416423
424 # Remove any named temporary files we created.
425 for f in named_temp_files:
426 try:
427 os.remove(f)
428 except OSError:
429 pass
430
417431 if cmd.negate:
418432 exitCode = not exitCode
419433