From 1aa6f8de8a8e4cb5494c047083660fd2896cff20 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 4 Jun 2019 11:40:56 +0000 Subject: [PATCH] build.run: fix product extraction to work on Windows. Before this commit, it would fail with a "Permission denied" error. --- nmigen/build/run.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nmigen/build/run.py b/nmigen/build/run.py index 16992f9..251ba3e 100644 --- a/nmigen/build/run.py +++ b/nmigen/build/run.py @@ -68,9 +68,14 @@ class BuildProducts: files = [] try: for filename in filenames: - file = tempfile.NamedTemporaryFile(prefix="nmigen_", suffix="_" + filename) + # On Windows, a named temporary file (as created by Python) is not accessible to + # others if it's still open within the Python process, so we close it and delete + # it manually. + file = tempfile.NamedTemporaryFile(prefix="nmigen_", suffix="_" + filename, + delete=False) files.append(file) file.write(self.get(filename)) + file.close() if len(files) == 0: return (yield) @@ -80,4 +85,4 @@ class BuildProducts: return (yield [file.name for file in files]) finally: for file in files: - file.close() + os.unlink(file.name) -- 2.30.2