|
20 | 20 | import lit.util
|
21 | 21 |
|
22 | 22 | 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): |
54 | 23 | opts = lit.cl_arguments.parse_args()
|
55 | 24 |
|
56 | 25 | if opts.show_version:
|
@@ -249,16 +218,50 @@ def progress_callback(test):
|
249 | 218 | if opts.incremental:
|
250 | 219 | update_incremental_cache(test)
|
251 | 220 |
|
| 221 | + run_callback = lambda: run.execute_tests(progress_callback, opts.numWorkers, |
| 222 | + opts.maxTime) |
| 223 | + |
252 | 224 | startTime = time.time()
|
253 | 225 | try:
|
254 |
| - run.execute_tests(progress_callback, opts.numWorkers, opts.maxTime) |
| 226 | + run_tests_in_tmp_dir(run_callback) |
255 | 227 | except KeyboardInterrupt:
|
256 | 228 | sys.exit(2)
|
257 | 229 | testing_time = time.time() - startTime
|
258 | 230 |
|
259 | 231 | display.finish()
|
260 | 232 | return testing_time
|
261 | 233 |
|
| 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 | + |
262 | 265 | def print_summary(tests, opts):
|
263 | 266 | byCode = {}
|
264 | 267 | for test in tests:
|
|
0 commit comments