Skip to content

Commit 3c7d879

Browse files
committed
[lit] Skip creation of tmp dir if we don't actually run any tests
llvm-svn: 375048
1 parent 70055d8 commit 3c7d879

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

llvm/utils/lit/lit/main.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,6 @@
2020
import lit.util
2121

2222
def main(builtinParameters = {}):
23-
# Create a temp directory inside the normal temp directory so that we can
24-
# try to avoid temporary test file leaks. The user can avoid this behavior
25-
# by setting LIT_PRESERVES_TMP in the environment, so they can easily use
26-
# their own temp directory to monitor temporary file leaks or handle them at
27-
# the buildbot level.
28-
lit_tmp = None
29-
if 'LIT_PRESERVES_TMP' not in os.environ:
30-
import tempfile
31-
lit_tmp = tempfile.mkdtemp(prefix="lit_tmp_")
32-
os.environ.update({
33-
'TMPDIR': lit_tmp,
34-
'TMP': lit_tmp,
35-
'TEMP': lit_tmp,
36-
'TEMPDIR': lit_tmp,
37-
})
38-
# FIXME: If Python does not exit cleanly, this directory will not be cleaned
39-
# up. We should consider writing the lit pid into the temp directory,
40-
# scanning for stale temp directories, and deleting temp directories whose
41-
# lit process has died.
42-
try:
43-
main_with_tmp(builtinParameters)
44-
finally:
45-
if lit_tmp:
46-
try:
47-
import shutil
48-
shutil.rmtree(lit_tmp)
49-
except:
50-
# FIXME: Re-try after timeout on Windows.
51-
pass
52-
53-
def main_with_tmp(builtinParameters):
5423
opts = lit.cl_arguments.parse_args()
5524

5625
if opts.show_version:
@@ -249,16 +218,50 @@ def progress_callback(test):
249218
if opts.incremental:
250219
update_incremental_cache(test)
251220

221+
run_callback = lambda: run.execute_tests(progress_callback, opts.numWorkers,
222+
opts.maxTime)
223+
252224
startTime = time.time()
253225
try:
254-
run.execute_tests(progress_callback, opts.numWorkers, opts.maxTime)
226+
run_tests_in_tmp_dir(run_callback)
255227
except KeyboardInterrupt:
256228
sys.exit(2)
257229
testing_time = time.time() - startTime
258230

259231
display.finish()
260232
return testing_time
261233

234+
def run_tests_in_tmp_dir(run_callback):
235+
# Create a temp directory inside the normal temp directory so that we can
236+
# try to avoid temporary test file leaks. The user can avoid this behavior
237+
# by setting LIT_PRESERVES_TMP in the environment, so they can easily use
238+
# their own temp directory to monitor temporary file leaks or handle them at
239+
# the buildbot level.
240+
tmp_dir = None
241+
if 'LIT_PRESERVES_TMP' not in os.environ:
242+
import tempfile
243+
tmp_dir = tempfile.mkdtemp(prefix="lit_tmp_")
244+
os.environ.update({
245+
'TMPDIR': tmp_dir,
246+
'TMP': tmp_dir,
247+
'TEMP': tmp_dir,
248+
'TEMPDIR': tmp_dir,
249+
})
250+
# FIXME: If Python does not exit cleanly, this directory will not be cleaned
251+
# up. We should consider writing the lit pid into the temp directory,
252+
# scanning for stale temp directories, and deleting temp directories whose
253+
# lit process has died.
254+
try:
255+
run_callback()
256+
finally:
257+
if tmp_dir:
258+
try:
259+
import shutil
260+
shutil.rmtree(tmp_dir)
261+
except:
262+
# FIXME: Re-try after timeout on Windows.
263+
pass
264+
262265
def print_summary(tests, opts):
263266
byCode = {}
264267
for test in tests:

0 commit comments

Comments
 (0)