elf2bin.py objcopy cleanup by mcspr · Pull Request #7351 · esp8266/Arduino (original) (raw)

Per https://docs.python.org/3/library/tempfile.html#tempfile.mkstemp

Unlike TemporaryFile(), the user of mkstemp() is responsible for deleting the temporary file when done with it.

read_segment()'s dumpfile was never deleted, producing 5 'segment' files each build.

Instead, this patch creates a temporary directory which is later used for objcopy output. TemporaryDirectory() context manager will handle the deletion.
Plus, some minor refactoring to reduce line length and add some pythonisms (hopefully, not too much)

Noticed this issue accidentally by inspecting a specific Windows PC install using WSL circa January. /tmp was ~2.5GB and there was a lot of files.