lit/TestRunner.py: [Win32] Rework WinWaitReleased() again! "win32file" from Python Win32 Extensions.

We can simply confirm the handle released to open it with EXCLUSIVE. Attempting renaming was bad.

Disable win32file at ImportError. Thanks to Francois to let me know.

FIXME: Could we report warning or notification if win32file were not found?

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153172 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
NAKAMURA Takumi 2012-03-21 07:49:44 +00:00
parent 57f33c86c7
commit 9146e66cc1

View File

@ -23,42 +23,55 @@ kUseCloseFDs = not kIsWindows
# Use temporary files to replace /dev/null on Windows. # Use temporary files to replace /dev/null on Windows.
kAvoidDevNull = kIsWindows kAvoidDevNull = kIsWindows
# Negate if win32file is not found.
kHaveWin32File = kIsWindows
def RemoveForce(f): def RemoveForce(f):
try: try:
os.remove(f) os.remove(f)
except OSError: except OSError:
pass pass
def WinRename(f_o, f_n):
import time
retry_cnt = 256
while (True):
try:
os.rename(f_o, f_n)
break
except WindowsError, (winerror, strerror):
retry_cnt = retry_cnt - 1
if retry_cnt <= 0:
raise
elif winerror == 32: # ERROR_SHARING_VIOLATION
time.sleep(0.01)
else:
raise
def WinWaitReleased(f): def WinWaitReleased(f):
import random global kHaveWin32File
t = "%s%06d" % (f, random.randint(0, 999999)) if not kHaveWin32File:
RemoveForce(t) return
try: try:
WinRename(f, t) # rename import time
WinRename(t, f) # restore import win32file, pywintypes
except WindowsError, (winerror, strerror): retry_cnt = 256
if winerror in (2, 3): while True:
# 2: ERROR_FILE_NOT_FOUND try:
# 3: ERROR_PATH_NOT_FOUND h = win32file.CreateFile(
pass f,
else: win32file.GENERIC_READ,
raise 0, # Exclusive
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL,
None)
h.close()
return
except WindowsError, (winerror, strerror):
retry_cnt = retry_cnt - 1
if retry_cnt <= 0:
raise
elif winerror == 32: # ERROR_SHARING_VIOLATION
pass
else:
raise
except pywintypes.error, e:
retry_cnt = retry_cnt - 1
if retry_cnt <= 0:
raise
elif e[0]== 32: # ERROR_SHARING_VIOLATION
pass
else:
raise
time.sleep(0.01)
except ImportError, e:
kHaveWin32File = False
return
def executeCommand(command, cwd=None, env=None): def executeCommand(command, cwd=None, env=None):
p = subprocess.Popen(command, cwd=cwd, p = subprocess.Popen(command, cwd=cwd,