From 3c7d8792f12d6598ead6c3fb5f10d5a4be90ed4c Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Wed, 16 Oct 2019 22:20:25 +0000 Subject: [PATCH] [lit] Skip creation of tmp dir if we don't actually run any tests llvm-svn: 375048 --- llvm/utils/lit/lit/main.py | 67 ++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py index 4fd0a1a..14258c5 100755 --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -20,37 +20,6 @@ import lit.Test import lit.util 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: - import tempfile - 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: - if lit_tmp: - try: - import shutil - shutil.rmtree(lit_tmp) - except: - # FIXME: Re-try after timeout on Windows. - pass - -def main_with_tmp(builtinParameters): opts = lit.cl_arguments.parse_args() if opts.show_version: @@ -249,9 +218,12 @@ def run_tests(tests, litConfig, opts, numTotalTests): if opts.incremental: update_incremental_cache(test) + run_callback = lambda: run.execute_tests(progress_callback, opts.numWorkers, + opts.maxTime) + startTime = time.time() try: - run.execute_tests(progress_callback, opts.numWorkers, opts.maxTime) + run_tests_in_tmp_dir(run_callback) except KeyboardInterrupt: sys.exit(2) testing_time = time.time() - startTime @@ -259,6 +231,37 @@ def run_tests(tests, litConfig, opts, numTotalTests): display.finish() return testing_time +def run_tests_in_tmp_dir(run_callback): + # 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_callback() + finally: + if tmp_dir: + try: + import shutil + shutil.rmtree(tmp_dir) + except: + # FIXME: Re-try after timeout on Windows. + pass + def print_summary(tests, opts): byCode = {} for test in tests: -- 2.7.4