Skip to content

Commit

Permalink
Use a temporary directory for flag test
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed May 9, 2022
1 parent c72093a commit 9e1849b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions brian2/codegen/cpp_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,13 @@
def _determine_flag_compatibility(compiler, flagname):
import tempfile
from distutils.errors import CompileError
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f, std_silent():
f.write('int main (int argc, char **argv) { return 0; }')
with tempfile.TemporaryDirectory(prefix='brian_flag_test_') as temp_dir, std_silent():
fname = os.path.join(temp_dir, 'flag_test.cpp')
with open(fname, 'wt') as f:
f.write('int main (int argc, char **argv) { return 0; }')
try:
object_files = compiler.compile([f.name],
output_dir=os.path.dirname(f.name),
extra_postargs=[flagname])
for object_file in object_files:
os.unlink(object_file)
compiler.compile([fname], output_dir=temp_dir,
extra_postargs=[flagname])
except CompileError:
logger.warn(f"Removing unsupported flag '{flagname}' from "
f'compiler flags.')
Expand Down

0 comments on commit 9e1849b

Please sign in to comment.