Skip to content

Commit

Permalink
Close the temporary file before using it
Browse files Browse the repository at this point in the history
An instance of NamedTemporaryFile would keep the file open in the
current process, however, on Windows, a opened filed is no accessible
from any other process, and thus the following commands use this file
would fail to execute.

To fix this, this commit ensures that the temporary file has been closed
before it is used anywhere else, and removes the temporary file after
everything gets done.
  • Loading branch information
upsuper committed Jul 19, 2016
1 parent 589c6ee commit 81ccbac
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ports/geckolib/gecko_bindings/tools/regen.py
Expand Up @@ -284,10 +284,11 @@ def build(objdir, target_name, kind_name=None,
print("[RUSTC]... ", end='')
sys.stdout.flush()

tests_file = tempfile.NamedTemporaryFile()
with tempfile.NamedTemporaryFile(delete=False) as f:
test_file = f.name
output = None
try:
rustc_command = ["rustc", output_filename, "--test", "-o", tests_file.name]
rustc_command = ["rustc", output_filename, "--test", "-o", test_file]
output = subprocess.check_output(rustc_command, stderr=subprocess.STDOUT)
output = output.decode('utf8')
except subprocess.CalledProcessError as e:
Expand All @@ -299,17 +300,17 @@ def build(objdir, target_name, kind_name=None,
if verbose:
print(output)

tests_file.file.close()
print("[RUSTC_TEST]... ", end='')
sys.stdout.flush()

try:
output = subprocess.check_output([tests_file.name], stderr=subprocess.STDOUT)
output = subprocess.check_output([test_file], stderr=subprocess.STDOUT)
output = output.decode('utf8')
except subprocess.CalledProcessError as e:
print("tests failed: ", e.output.decode('utf8'))
return 1

os.remove(test_file)
print("OK")

# TODO: this -3 is hacky as heck
Expand Down

0 comments on commit 81ccbac

Please sign in to comment.