Index: utils/lit/lit/TestRunner.py =================================================================== --- utils/lit/lit/TestRunner.py +++ utils/lit/lit/TestRunner.py @@ -607,7 +607,19 @@ if not recursive: stderr.write("Error: %s is a directory\n" % path) exitCode = 1 - shutil.rmtree(path, onerror = on_rm_error if force else None) + if platform.system() == 'Windows': + # NOTE: use ctypes to access `RemoveDirectoryW` on Windows + # to use the NT style path to get access to long file paths + # which cannot be removed otherwise. On python 2.7, + # `shutil.rmtree` is backed by `RemoveDirectoryA` which does + # not support the NT style path, so we must resort to the + # ctypes import. + import ctypes + path = os.path.abspath(path) + if not ctypes.windll.kernel32.RemoveDirectoryW(r'\\?\%s' % path): + raise ctypes.WinError() + else: + shutil.rmtree(path, onerror = on_rm_error if force else None) else: if force and not os.access(path, os.W_OK): os.chmod(path,