mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-29 14:40:39 +00:00
[lit] Clean up temporary files created by tests
Do this by creating a temp directory in the normal system temp directory, and cleaning it up on exit. It is still possible for this temp directory to leak if Python exits abnormally, but this is probably good enough for now. Fixes PR18335 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280501 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4b602e742f
commit
5dd7b750fc
@ -25,7 +25,8 @@ class TestingConfig:
|
||||
pass_vars = ['LIBRARY_PATH', 'LD_LIBRARY_PATH', 'SYSTEMROOT', 'TERM',
|
||||
'LD_PRELOAD', 'ASAN_OPTIONS', 'UBSAN_OPTIONS',
|
||||
'LSAN_OPTIONS', 'ADB', 'ANDROID_SERIAL',
|
||||
'SANITIZER_IGNORE_CVE_2016_2143']
|
||||
'SANITIZER_IGNORE_CVE_2016_2143', 'TMPDIR', 'TMP', 'TEMP',
|
||||
'TEMPDIR']
|
||||
for var in pass_vars:
|
||||
val = os.environ.get(var, '')
|
||||
# Check for empty string as some variables such as LD_PRELOAD cannot be empty
|
||||
@ -42,16 +43,6 @@ class TestingConfig:
|
||||
'TMP' : os.environ.get('TMP',''),
|
||||
})
|
||||
|
||||
# The option to preserve TEMP, TMP, and TMPDIR.
|
||||
# This is intended to check how many temporary files would be generated
|
||||
# (and be not cleaned up) in automated builders.
|
||||
if 'LIT_PRESERVES_TMP' in os.environ:
|
||||
environment.update({
|
||||
'TEMP' : os.environ.get('TEMP',''),
|
||||
'TMP' : os.environ.get('TMP',''),
|
||||
'TMPDIR' : os.environ.get('TMPDIR',''),
|
||||
})
|
||||
|
||||
# Set the default available features based on the LitConfig.
|
||||
available_features = []
|
||||
if litConfig.useValgrind:
|
||||
|
@ -8,6 +8,8 @@ See lit.pod for more information.
|
||||
|
||||
from __future__ import absolute_import
|
||||
import math, os, platform, random, re, sys, time
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
import lit.ProgressBar
|
||||
import lit.LitConfig
|
||||
@ -132,6 +134,30 @@ def sort_by_incremental_cache(run):
|
||||
run.tests.sort(key = lambda t: sortIndex(t))
|
||||
|
||||
def main(builtinParameters = {}):
|
||||
# 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.
|
||||
lit_tmp = None
|
||||
if 'LIT_PRESERVES_TMP' not in os.environ:
|
||||
lit_tmp = tempfile.mkdtemp(prefix="lit_tmp_")
|
||||
os.environ.update({
|
||||
'TMPDIR': lit_tmp,
|
||||
'TMP': lit_tmp,
|
||||
'TEMP': lit_tmp,
|
||||
'TEMPDIR': lit_tmp,
|
||||
})
|
||||
# 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:
|
||||
main_with_tmp(builtinParameters)
|
||||
finally:
|
||||
shutil.rmtree(lit_tmp)
|
||||
|
||||
def main_with_tmp(builtinParameters):
|
||||
global options
|
||||
from optparse import OptionParser, OptionGroup
|
||||
parser = OptionParser("usage: %prog [options] {file-or-path}")
|
||||
|
Loading…
Reference in New Issue
Block a user