Skip to content

Commit 1b93cd2

Browse files
authored
Save all temp files in EMCC_DEBUG mode (emscripten-core#13406)
We have two classes of temp files that we use in emscripten 1. Temp files that live in emscripten temp dir and have non-unique names 2. Temp files that live direclyt in the temp dir (not in a subdirectory and must have unique names. The cleanup mechanism we use for these two is separate. - We keep (1) around when EMCC_DEBUG is set. - We keep (2) around when EMCC_DEBUG_SAVE is set. When EMCC_DEBUG is set we also use the emscripten temp dir (1) to store the files of type (2), but we were still deleting them. This change makes the saving of temp file consisten such that EMCC_DEBUG acts as superset of EMCC_DEBUG_SAVE. This has the nice property that repsonce files and other temporaries are preserver in debug mode which makes subprocess commands more each to reproduce.
1 parent 7f66f59 commit 1b93cd2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

tools/shared.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434

3535
DEBUG = int(os.environ.get('EMCC_DEBUG', '0'))
36+
DEBUG_SAVE = DEBUG or int(os.environ.get('EMCC_DEBUG_SAVE', '0'))
3637
EXPECTED_NODE_VERSION = (4, 1, 1)
3738
EXPECTED_BINARYEN_VERSION = 99
3839
EXPECTED_LLVM_VERSION = "13.0"
@@ -376,12 +377,14 @@ def get_emscripten_temp_dir():
376377
if not EMSCRIPTEN_TEMP_DIR:
377378
EMSCRIPTEN_TEMP_DIR = tempfile.mkdtemp(prefix='emscripten_temp_', dir=configuration.TEMP_DIR)
378379

379-
def prepare_to_clean_temp(d):
380-
def clean_temp():
381-
try_delete(d)
380+
if not DEBUG_SAVE:
381+
def prepare_to_clean_temp(d):
382+
def clean_temp():
383+
try_delete(d)
382384

383-
atexit.register(clean_temp)
384-
prepare_to_clean_temp(EMSCRIPTEN_TEMP_DIR) # this global var might change later
385+
atexit.register(clean_temp)
386+
# this global var might change later
387+
prepare_to_clean_temp(EMSCRIPTEN_TEMP_DIR)
385388
return EMSCRIPTEN_TEMP_DIR
386389

387390

@@ -422,9 +425,13 @@ def __init__(self):
422425
atexit.register(lock.release)
423426

424427
def get_temp_files(self):
425-
return tempfiles.TempFiles(
426-
tmpdir=self.TEMP_DIR if not DEBUG else get_emscripten_temp_dir(),
427-
save_debug_files=os.environ.get('EMCC_DEBUG_SAVE'))
428+
if DEBUG_SAVE:
429+
# In debug mode store all temp files in the emscripten-specific temp dir
430+
# and don't worry about cleaning them up.
431+
return tempfiles.TempFiles(get_emscripten_temp_dir(), save_debug_files=True)
432+
else:
433+
# Otherwise use the system tempdir and try to clean up after ourselves.
434+
return tempfiles.TempFiles(self.TEMP_DIR, save_debug_files=False)
428435

429436

430437
def apply_configuration():

tools/tempfiles.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def get_dir(self):
9595

9696
def clean(self):
9797
if self.save_debug_files:
98-
print(f'not cleaning up temp files since in debug-save mode, see them in ${self.tmpdir}', file=sys.stderr)
98+
print(f'not cleaning up temp files since in debug-save mode, see them in {self.tmpdir}', file=sys.stderr)
9999
return
100100
for filename in self.to_clean:
101101
try_delete(filename)

0 commit comments

Comments
 (0)