Skip to content

Commit 7c1dfe2

Browse files
committed
Forcing recompilation when ModelSim return warning re waiting on lock
1 parent 7f22c7c commit 7c1dfe2

File tree

5 files changed

+49
-43
lines changed

5 files changed

+49
-43
lines changed

hdl_checker/builders/base_builder.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import os
2222
import os.path as p
2323
from threading import Lock
24-
from typing import Any, Dict, FrozenSet, Iterable, Optional, Set, Tuple
24+
from typing import Any, Dict, FrozenSet, Iterable, Mapping, Optional, Set, Tuple
2525

2626
from hdl_checker.database import Database # pylint: disable=unused-import
2727
from hdl_checker.diagnostics import CheckerDiagnostic, DiagType
@@ -202,18 +202,21 @@ def _getRebuilds(self, path, line, library):
202202
Gets info on what should be rebuilt to satisfy the builder
203203
"""
204204
try:
205-
parse_results = self._searchForRebuilds(line)
205+
parse_results = self._searchForRebuilds(path, line)
206206
except NotImplementedError: # pragma: no cover
207207
return set()
208208

209209
rebuilds = set() # type: Set[RebuildInfo]
210210
for rebuild in parse_results:
211-
unit_type = rebuild.get("unit_type", None) # type: str
212-
library_name = rebuild.get("library_name", None) # type: str
213-
unit_name = rebuild.get("unit_name", None) # type: str
214-
rebuild_path = rebuild.get("rebuild_path", None) # type: str
211+
unit_type = rebuild.get("unit_type", None) # type: Optional[str]
212+
library_name = rebuild.get("library_name", None) # type: Optional[str]
213+
unit_name = rebuild.get("unit_name", None) # type: Optional[str]
214+
rebuild_path = rebuild.get("rebuild_path", None) # type: Optional[str]
215215

216-
if None not in (unit_type, unit_name):
216+
if library_name == "work":
217+
library_name = library.name
218+
219+
if unit_name is not None and unit_type is not None:
217220
for dependency in self._database.getDependenciesByPath(path):
218221
if dependency.name.name == rebuild["unit_name"]:
219222
rebuilds.add(
@@ -222,9 +225,7 @@ def _getRebuilds(self, path, line, library):
222225
)
223226
)
224227
break
225-
elif None not in (library_name, unit_name):
226-
if library_name == "work":
227-
library_name = library.name
228+
elif library_name is not None and unit_name is not None:
228229
rebuilds.add(
229230
RebuildLibraryUnit(Identifier(unit_name), Identifier(library_name))
230231
)
@@ -237,8 +238,8 @@ def _getRebuilds(self, path, line, library):
237238

238239
return rebuilds
239240

240-
def _searchForRebuilds(self, line): # pragma: no cover
241-
# type: (...) -> Any
241+
def _searchForRebuilds(self, path, line): # pragma: no cover
242+
# type: (Path, str) -> Iterable[Mapping[str, str]]
242243
"""
243244
Finds units that the builders is telling us to rebuild
244245
"""

hdl_checker/builders/ghdl.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import os.path as p
2121
import re
2222
from glob import glob
23-
from typing import Any, Iterable, List, Optional
23+
from typing import Any, Iterable, List, Mapping, Optional
2424

2525
from .base_builder import BaseBuilder
2626

@@ -195,10 +195,9 @@ def _createLibrary(self, _):
195195
if not p.exists(workdir):
196196
os.makedirs(workdir)
197197

198-
def _searchForRebuilds(self, line):
199-
rebuilds = []
200-
201-
for match in self._iter_rebuild_units(line):
198+
def _searchForRebuilds(self, path, line):
199+
# type: (Path, str) -> Iterable[Mapping[str, str]]
200+
for match in GHDL._iter_rebuild_units(line):
202201
mdict = match.groupdict()
203202
# When compilers reports units out of date, they do this
204203
# by either
@@ -207,10 +206,6 @@ def _searchForRebuilds(self, line):
207206
# 2. Reporting which design unit has been affected by a
208207
# given change.
209208
if "rebuild_path" in mdict and mdict["rebuild_path"] is not None:
210-
rebuilds.append(mdict)
209+
yield mdict
211210
else:
212-
rebuilds.append(
213-
{"unit_type": mdict["unit_type"], "unit_name": mdict["unit_name"]}
214-
)
215-
216-
return rebuilds
211+
yield {"unit_type": mdict["unit_type"], "unit_name": mdict["unit_name"]}

hdl_checker/builders/msim.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import os.path as p
2121
import re
2222
from shutil import copyfile
23-
from typing import Any, Iterable, List, Optional
23+
from typing import Any, Iterable, List, Mapping, Optional
2424

2525
from .base_builder import BaseBuilder
2626

@@ -184,14 +184,16 @@ def _parseBuiltinLibraries(self):
184184
for match in self._BuilderLibraryScanner.finditer(line):
185185
yield Identifier(match.groupdict()["library_name"], False)
186186

187-
def _searchForRebuilds(self, line):
188-
rebuilds = []
189-
for match in self._iter_rebuild_units(line):
187+
def _searchForRebuilds(self, path, line):
188+
# type: (Path, str) -> Iterable[Mapping[str, str]]
189+
if line.startswith("** Warning: ") and "Waiting for lock by" in line:
190+
yield {"rebuild_path": path.abspath}
191+
for match in MSim._iter_rebuild_units(line):
190192
mdict = match.groupdict()
191193
library_name = mdict["lib_name_0"] or mdict["lib_name_1"]
192194
unit_name = mdict["unit_name_0"] or mdict["unit_name_1"]
193195
if None not in (library_name, unit_name):
194-
rebuilds.append({"library_name": library_name, "unit_name": unit_name})
196+
yield {"library_name": library_name, "unit_name": unit_name}
195197
else: # pragma: no cover
196198
_msg = "Something wrong while parsing '%s'. " "Match is '%s'" % (
197199
line,
@@ -200,8 +202,6 @@ def _searchForRebuilds(self, line):
200202
self._logger.error(_msg)
201203
assert 0, _msg
202204

203-
return rebuilds
204-
205205
def _buildSource(self, path, library, flags=None):
206206
# type: (Path, Identifier, Optional[BuildFlags]) -> Iterable[str]
207207
filetype = FileType.fromPath(path)

hdl_checker/builders/xvhdl.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import re
2121
import shutil
2222
import tempfile
23-
from typing import Iterable, Optional
23+
from typing import Iterable, Mapping, Optional
2424

2525
from .base_builder import BaseBuilder
2626

@@ -169,13 +169,11 @@ def _buildSource(self, path, library, flags=None):
169169
cmd += [path.name]
170170
return runShellCommand(cmd, cwd=self._work_folder)
171171

172-
def _searchForRebuilds(self, line):
173-
rebuilds = []
174-
172+
def _searchForRebuilds(self, path, line):
173+
# type: (Path, str) -> Iterable[Mapping[str, str]]
175174
for match in _ITER_REBUILD_UNITS(line):
176175
dict_ = match.groupdict()
177-
rebuilds.append(
178-
{"library_name": dict_["library_name"], "unit_name": dict_["unit_name"]}
179-
)
180-
181-
return rebuilds
176+
yield {
177+
"library_name": dict_["library_name"],
178+
"unit_name": dict_["unit_name"],
179+
}

hdl_checker/tests/test_builders.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def test_MsimRecompileMsg0(self):
561561

562562
self.assertEqual(
563563
[{"library_name": "foo_lib", "unit_name": "bar_component"}],
564-
self.builder._searchForRebuilds(line),
564+
list(self.builder._searchForRebuilds(Path("foo.vhd"), line)),
565565
)
566566

567567
def test_MsimRecompileMsg1(self):
@@ -576,7 +576,19 @@ def test_MsimRecompileMsg1(self):
576576

577577
self.assertEqual(
578578
[{"library_name": "foo_lib", "unit_name": "bar_component"}],
579-
self.builder._searchForRebuilds(line),
579+
list(self.builder._searchForRebuilds(Path("foo.vhd"), line)),
580+
)
581+
582+
def test_MsimRecompileMsg2(self):
583+
# type: (...) -> Any
584+
if not isinstance(self.builder, MSim):
585+
raise unittest2.SkipTest("ModelSim only test")
586+
587+
line = '** Warning: (vcom-6) -- Waiting for lock by "user@host, pid = 4661". Lockfile is'
588+
589+
self.assertEqual(
590+
[{"rebuild_path": p.abspath("foo.vhd")}],
591+
list(self.builder._searchForRebuilds(Path("foo.vhd"), line)),
580592
)
581593

582594
def test_GhdlRecompileMsg(self):
@@ -588,7 +600,7 @@ def test_GhdlRecompileMsg(self):
588600

589601
self.assertEqual(
590602
[{"unit_type": "package", "unit_name": "leon3"}],
591-
self.builder._searchForRebuilds(line),
603+
list(self.builder._searchForRebuilds(Path("foo.vhd"), line)),
592604
)
593605

594606
def test_XvhdlRecompileMsg0(self):
@@ -605,7 +617,7 @@ def test_XvhdlRecompileMsg0(self):
605617

606618
self.assertEqual(
607619
[{"library_name": "some_library", "unit_name": "some_package"}],
608-
self.builder._searchForRebuilds(line),
620+
list(self.builder._searchForRebuilds(Path("foo.vhd"), line)),
609621
)
610622

611623
# Rebuild formats are:

0 commit comments

Comments
 (0)