Commit 2df02528 authored by Tristan Gingold's avatar Tristan Gingold

Merge branch 'fix/makefile-try-contextmanager-write' into 'develop'

Fix(?): Use context manager for writing Makefile, improve TestSuite on Windows

See merge request !19
parents 5aa0d0bc 08044a47
......@@ -52,7 +52,7 @@ class GhdlSyn(ToolMakefile):
self._makefile_syn_build()
self._makefile_syn_clean()
self._makefile_syn_phony()
self.makefile_close()
self.makefile_open_write_close()
logging.info(self.TOOL_INFO['name'] + " synthesis makefile generated.")
def _makefile_syn_top(self):
......
......@@ -45,6 +45,7 @@ class ToolMakefile(object):
def __init__(self):
super(ToolMakefile, self).__init__()
self._filestring = ""
self._file = None
self.fileset = None
self.manifest_dict = {}
......@@ -86,7 +87,6 @@ class ToolMakefile(object):
if os.path.exists(self._filename):
os.remove(self._filename)
self._file = open(self._filename, "w")
self.writeln("########################################")
self.writeln("# This file was generated by hdlmake #")
self.writeln("# http://ohwr.org/projects/hdl-make/ #")
......@@ -169,8 +169,9 @@ class ToolMakefile(object):
" " + ' '.join(self.CLEAN_TARGETS["mrproper"]) + "\n"
self.writeln(tmp)
def makefile_close(self):
self._file.close()
def makefile_open_write_close(self):
with open(self._filename, "w") as mf:
mf.write(self._filestring)
self._file = None
def write(self, line=None):
......@@ -182,7 +183,7 @@ class ToolMakefile(object):
# Need to remove quotes as they are needed only for unix shell.
l = l.replace('\\"', '"')
l = l.replace("'", "")
self._file.write(l)
self._filestring += l
def writeln(self, text=None):
"""Write a string in the manifest, automatically add new line"""
......
......@@ -39,7 +39,7 @@ class MakefileSim(ToolMakefile):
self._makefile_sim_command()
self._makefile_sim_clean()
self._makefile_sim_phony()
self.makefile_close()
self.makefile_open_write_close()
def _makefile_sim_top(self):
"""Generic method to write the simulation Makefile top section"""
......
......@@ -59,7 +59,7 @@ class MakefileSyn(ToolMakefile):
self._makefile_syn_build()
self._makefile_syn_clean()
self._makefile_syn_phony()
self.makefile_close()
self.makefile_open_write_close()
logging.info(self.TOOL_INFO['name'] + " synthesis makefile generated.")
def _makefile_syn_top(self):
......
......@@ -166,22 +166,18 @@ def test_quartus035():
with pytest.raises(SystemExit) as _:
run([], path="035quartus_err")
print(os.getcwd())
os.remove('035quartus_err/Makefile')
def test_quartus036():
with pytest.raises(SystemExit) as _:
run([], path="036quartus_err")
os.remove('036quartus_err/Makefile')
def test_quartus037():
with pytest.raises(SystemExit) as _:
run([], path="037quartus_err")
os.remove('037quartus_err/Makefile')
def test_quartus038():
with pytest.raises(SystemExit) as _:
run([], path="038quartus_err")
os.remove('038quartus_err/Makefile')
def test_quartus039():
with pytest.raises(SystemExit) as _:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment