On Windows, an error running the debugger typically leaves a process hanging around in the working directory. When Dexter exits, it can't then delete the working directory and produces an exception, masking the problem in the debugger. (This can be worked around by specifying --save-temps). Rather than hard-erroring, print a warning when we can't delete the working directory instead. It'd be much better to improve our error handling, and make the WorkingDirectory class aware that something's wrong when it enters exit. However, this is something that's going to mask genuine errors and make everyones lives harder right now, so I think this non-ideal fix is important to get in first. Differential Revision: https://reviews.llvm.org/D74548
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# DExTer : Debugging Experience Tester
|
|
# ~~~~~~ ~ ~~ ~ ~~
|
|
#
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
"""Create/set a temporary working directory for some operations."""
|
|
|
|
import os
|
|
import shutil
|
|
import tempfile
|
|
import time
|
|
|
|
from dex.utils.Exceptions import Error
|
|
from dex.utils.Warning import warn
|
|
|
|
class WorkingDirectory(object):
|
|
def __init__(self, context, *args, **kwargs):
|
|
self.context = context
|
|
self.orig_cwd = os.getcwd()
|
|
|
|
dir_ = kwargs.get('dir', None)
|
|
if dir_ and not os.path.isdir(dir_):
|
|
os.makedirs(dir_, exist_ok=True)
|
|
self.path = tempfile.mkdtemp(*args, **kwargs)
|
|
|
|
def __enter__(self):
|
|
os.chdir(self.path)
|
|
return self
|
|
|
|
def __exit__(self, *args):
|
|
os.chdir(self.orig_cwd)
|
|
if self.context.options.save_temps:
|
|
self.context.o.blue('"{}" left in place [--save-temps]\n'.format(
|
|
self.path))
|
|
return
|
|
|
|
for _ in range(100):
|
|
try:
|
|
shutil.rmtree(self.path)
|
|
return
|
|
except OSError:
|
|
time.sleep(0.1)
|
|
|
|
warn(self.context, '"{}" left in place (couldn\'t delete)\n'.format(self.path))
|
|
return
|