From: whitequark Date: Tue, 4 Jun 2019 11:40:56 +0000 (+0000) Subject: build.run: fix product extraction to work on Windows. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1aa6f8de8a8e4cb5494c047083660fd2896cff20;p=nmigen.git build.run: fix product extraction to work on Windows. Before this commit, it would fail with a "Permission denied" error. --- 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)