def execute_in_tmp_dir(run, lit_config): # Create a temp directory inside the normal temp directory so that we can # try to avoid temporary test file leaks. The user can avoid this behavior # by setting LIT_PRESERVES_TMP in the environment, so they can easily use # their own temp directory to monitor temporary file leaks or handle them at # the buildbot level. tmp_dir = None if 'LIT_PRESERVES_TMP' not in os.environ: import tempfile tmp_dir = tempfile.mkdtemp(prefix="lit_tmp_") os.environ.update({ 'TMPDIR': tmp_dir, 'TMP': tmp_dir, 'TEMP': tmp_dir, 'TEMPDIR': tmp_dir, }) # FIXME: If Python does not exit cleanly, this directory will not be cleaned # up. We should consider writing the lit pid into the temp directory, # scanning for stale temp directories, and deleting temp directories whose # lit process has died. try: run.execute() finally: if tmp_dir: try: import shutil shutil.rmtree(tmp_dir) except: # FIXME: Re-try after timeout on Windows. lit_config.warning("Failed to delete temp directory '%s'" % tmp_dir)
def execute_in_tmp_dir(run, lit_config): # Create a temp directory inside the normal temp directory so that we can # try to avoid temporary test file leaks. The user can avoid this behavior # by setting LIT_PRESERVES_TMP in the environment, so they can easily use # their own temp directory to monitor temporary file leaks or handle them at # the buildbot level. tmp_dir = None if 'LIT_PRESERVES_TMP' not in os.environ: import tempfile tmp_dir = tempfile.mkdtemp(prefix="lit_tmp_") os.environ.update({ 'TMPDIR': tmp_dir, 'TMP': tmp_dir, 'TEMP': tmp_dir, 'TEMPDIR': tmp_dir, }) try: run.execute() finally: if tmp_dir: try: import shutil shutil.rmtree(tmp_dir) except Exception as e: lit_config.warning("Failed to delete temp directory '%s', try upgrading your version of Python to fix this" % tmp_dir)
def execute_in_tmp_dir(run, lit_config): # Create a temp directory inside the normal temp directory so that we can # try to avoid temporary test file leaks. The user can avoid this behavior # by setting LIT_PRESERVES_TMP in the environment, so they can easily use # their own temp directory to monitor temporary file leaks or handle them at # the buildbot level. tmp_dir = None if 'LIT_PRESERVES_TMP' not in os.environ: import tempfile # z/OS linker does not support '_' in paths, so use '-'. tmp_dir = tempfile.mkdtemp(prefix='lit-tmp-') tmp_dir_envs = { k: tmp_dir for k in ['TMP', 'TMPDIR', 'TEMP', 'TEMPDIR'] } os.environ.update(tmp_dir_envs) for cfg in {t.config for t in run.tests}: cfg.environment.update(tmp_dir_envs) try: run.execute() finally: if tmp_dir: try: import shutil shutil.rmtree(tmp_dir) except Exception as e: lit_config.warning( "Failed to delete temp directory '%s', try upgrading your version of Python to fix this" % tmp_dir)