mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Close the temporary file before using it
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.
This commit is contained in:
parent
589c6eeb0f
commit
81ccbac103
1 changed files with 5 additions and 4 deletions
|
@ -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:
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue