Skip to content

Commit 1e51a1d

Browse files
author
asouto
committed
Rebuild handling has broken
1 parent 40fd9c8 commit 1e51a1d

File tree

9 files changed

+62
-35
lines changed

9 files changed

+62
-35
lines changed

hdl_checker/builders/base_builder.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from hdl_checker.types import (
3232
BuildFlags,
3333
BuildFlagScope,
34+
DesignUnitType,
3435
FileType,
3536
RebuildInfo,
3637
RebuildLibraryUnit,
@@ -200,24 +201,30 @@ def _getRebuilds(self, path, line, library):
200201

201202
rebuilds = set() # type: Set[RebuildInfo]
202203
for rebuild in parse_results:
203-
unit_type = rebuild.get("unit_type", None)
204-
library_name = rebuild.get("library_name", None)
205-
unit_name = rebuild.get("unit_name", None)
206-
rebuild_path = rebuild.get("rebuild_path", None)
204+
unit_type = rebuild.get("unit_type", None) # type: str
205+
library_name = rebuild.get("library_name", None) # type: str
206+
unit_name = rebuild.get("unit_name", None) # type: str
207+
rebuild_path = rebuild.get("rebuild_path", None) # type: str
207208

208209
if None not in (unit_type, unit_name):
209210
for dependency in self._database.getDependenciesByPath(path):
210211
if dependency.name.name == rebuild["unit_name"]:
211-
rebuilds.add(RebuildUnit(unit_name, unit_type))
212+
rebuilds.add(
213+
RebuildUnit(
214+
Identifier(unit_name), DesignUnitType(unit_type)
215+
)
216+
)
212217
break
213218
elif None not in (library_name, unit_name):
214219
if library_name == "work":
215220
library_name = library.name
216-
rebuilds.add(RebuildLibraryUnit(unit_name, library_name))
221+
rebuilds.add(
222+
RebuildLibraryUnit(Identifier(unit_name), Identifier(library_name))
223+
)
217224
elif rebuild_path is not None:
218225
# GHDL sometimes gives the full path of the file that
219226
# should be recompiled
220-
rebuilds.add(RebuildPath(rebuild_path))
227+
rebuilds.add(RebuildPath(Path(rebuild_path)))
221228
else: # pragma: no cover
222229
self._logger.warning("Don't know what to do with %s", rebuild)
223230

hdl_checker/parsers/elements/design_unit.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,16 @@
1717
"Class defining a parsed design unit"
1818

1919
import logging
20-
from enum import Enum
2120
from typing import Optional, Union
2221

2322
from .identifier import Identifier, VerilogIdentifier, VhdlIdentifier
2423
from .parsed_element import LocationList, ParsedElement
2524

26-
from hdl_checker import types as t # pylint: disable=unused-import
25+
from hdl_checker.types import DesignUnitType
2726
from hdl_checker.path import Path
2827

2928
_logger = logging.getLogger(__name__)
3029

31-
32-
class DesignUnitType(str, Enum):
33-
"Specifies tracked design unit types"
34-
package = "package"
35-
entity = "entity"
36-
context = "context"
37-
38-
3930
class _DesignUnit(ParsedElement):
4031
"""
4132
Specifies a design unit (uses mostly VHDL nomenclature)

hdl_checker/parsers/verilog_parser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import re
2121
from typing import Any, Generator
2222

23-
from .elements.design_unit import DesignUnitType, VerilogDesignUnit
23+
from .elements.design_unit import VerilogDesignUnit
24+
from .elements.parsed_element import Location
2425

2526
from hdl_checker.parsers.base_parser import BaseSourceFile
27+
from hdl_checker.types import DesignUnitType
2628
from hdl_checker.utils import readFile
2729

2830
_logger = logging.getLogger(__name__)
@@ -76,14 +78,14 @@ def _getDesignUnits(self): # type: () -> Generator[VerilogDesignUnit, None, Non
7678
owner=self.filename,
7779
name=match["module_name"],
7880
type_=DesignUnitType.entity,
79-
locations={(line_number, None)},
81+
locations={Location(line_number, None)},
8082
)
8183
if match["package_name"] is not None:
8284
yield VerilogDesignUnit(
8385
owner=self.filename,
8486
name=match["package_name"],
8587
type_=DesignUnitType.package,
86-
locations={(line_number, None)},
88+
locations={Location(line_number, None)},
8789
)
8890

8991
def _getLibraries(self):

hdl_checker/parsers/vhdl_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
from typing import Any, Dict, Generator, Optional, Set, Tuple, Union
2222

2323
from .elements.dependency_spec import DependencySpec
24-
from .elements.design_unit import DesignUnitType, VhdlDesignUnit
24+
from .elements.design_unit import VhdlDesignUnit
2525
from .elements.identifier import VhdlIdentifier
2626
from .elements.parsed_element import Location
2727

2828
from hdl_checker.parsers.base_parser import BaseSourceFile
29+
from hdl_checker.types import DesignUnitType
2930
from hdl_checker.utils import readFile
3031

3132
_logger = logging.getLogger(__name__)

hdl_checker/tests/test_builders.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@
4545
Fallback,
4646
MSim,
4747
)
48-
from hdl_checker.builders.base_builder import RebuildLibraryUnit, RebuildPath, RebuildUnit
4948
from hdl_checker.diagnostics import BuilderDiag, DiagType
5049
from hdl_checker.exceptions import SanityCheckError
5150
from hdl_checker.parsers.elements.dependency_spec import DependencySpec
5251
from hdl_checker.parsers.elements.identifier import Identifier
5352
from hdl_checker.path import Path
54-
from hdl_checker.types import BuildFlagScope, FileType
53+
from hdl_checker.types import (
54+
BuildFlagScope,
55+
DesignUnitType,
56+
FileType,
57+
RebuildLibraryUnit,
58+
RebuildPath,
59+
RebuildUnit,
60+
)
5561

5662
_logger = logging.getLogger(__name__)
5763

@@ -558,19 +564,23 @@ def test_ghdl_recompile_msg(self):
558564
[
559565
(
560566
{"unit_type": "package", "unit_name": "very_common_pkg"},
561-
RebuildUnit(name="very_common_pkg", type_="package"),
567+
RebuildUnit(
568+
name=Identifier("very_common_pkg"), type_=DesignUnitType.package
569+
),
562570
),
563571
# Should replace 'work' with the path's library
564572
(
565573
{"library_name": "work", "unit_name": "foo"},
566-
RebuildLibraryUnit(name="foo", library="some_lib"),
574+
RebuildLibraryUnit(
575+
name=Identifier("foo"), library=Identifier("some_lib")
576+
),
567577
),
568578
# Should not touch the library name when != 'work'
569579
(
570580
{"library_name": "foo", "unit_name": "bar"},
571-
RebuildLibraryUnit(name="bar", library="foo"),
581+
RebuildLibraryUnit(name=Identifier("bar"), library=Identifier("foo")),
572582
),
573-
({"rebuild_path": "some_path"}, RebuildPath("some_path")),
583+
({"rebuild_path": "some_path"}, RebuildPath(Path("some_path"))),
574584
]
575585
)
576586
def test_get_rebuilds(self, rebuild_info, expected):

hdl_checker/tests/test_database.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
from hdl_checker.database import Database
4242
from hdl_checker.diagnostics import DependencyNotUnique, PathNotInProjectFile
4343
from hdl_checker.parsers.elements.dependency_spec import DependencySpec
44-
from hdl_checker.parsers.elements.design_unit import DesignUnitType, VhdlDesignUnit
44+
from hdl_checker.parsers.elements.design_unit import VhdlDesignUnit
4545
from hdl_checker.parsers.elements.identifier import Identifier
4646
from hdl_checker.parsers.elements.parsed_element import Location
4747
from hdl_checker.path import Path, TemporaryPath
4848
from hdl_checker.serialization import StateEncoder, jsonObjectHook
49-
from hdl_checker.types import BuildFlagScope, FileType
49+
from hdl_checker.types import BuildFlagScope, DesignUnitType, FileType
5050

5151
_logger = logging.getLogger(__name__)
5252

@@ -928,6 +928,8 @@ def test_infer_library_from_path(self):
928928

929929

930930
class TestUnitsDefinedInMultipleSources(TestCase):
931+
maxDiff = None
932+
931933
def setUp(self):
932934
# type: (...) -> Any
933935
_logger.info("Setting up %s", self)

hdl_checker/tests/test_verilog_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
from hdl_checker.tests import assertCountEqual, writeListToFile
2929

30-
from hdl_checker.parsers.elements.design_unit import DesignUnitType
3130
from hdl_checker.parsers.verilog_parser import VerilogDesignUnit, VerilogParser
3231
from hdl_checker.path import Path
3332
from hdl_checker.serialization import StateEncoder, jsonObjectHook
33+
from hdl_checker.types import DesignUnitType
3434

3535
_logger = logging.getLogger(__name__)
3636

hdl_checker/tests/test_vhdl_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
from hdl_checker.tests import assertCountEqual, assertSameFile, writeListToFile
3333

3434
from hdl_checker.parsers.elements.dependency_spec import DependencySpec
35-
from hdl_checker.parsers.elements.design_unit import DesignUnitType, VhdlDesignUnit
35+
from hdl_checker.parsers.elements.design_unit import VhdlDesignUnit
3636
from hdl_checker.parsers.elements.identifier import Identifier
3737
from hdl_checker.parsers.vhdl_parser import VhdlParser
3838
from hdl_checker.path import Path
3939
from hdl_checker.serialization import StateEncoder, jsonObjectHook
40+
from hdl_checker.types import DesignUnitType
4041

4142
_logger = logging.getLogger(__name__)
4243

hdl_checker/types.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,29 @@
1717
"Common type definitions for type hinting"
1818
from collections import namedtuple
1919
from enum import Enum
20-
from typing import Tuple, Union
20+
from typing import NamedTuple, Tuple, Union
2121

22+
from hdl_checker.parsers.elements.identifier import Identifier
2223
from hdl_checker.path import Path
2324

25+
26+
class DesignUnitType(str, Enum):
27+
"Specifies tracked design unit types"
28+
package = "package"
29+
entity = "entity"
30+
context = "context"
31+
32+
2433
BuildFlags = Tuple[str, ...]
2534
LibraryAndUnit = namedtuple("LibraryAndUnit", ["library", "unit"])
2635

27-
RebuildUnit = namedtuple("RebuildUnit", ["name", "type_"])
28-
RebuildLibraryUnit = namedtuple("RebuildLibraryUnit", ["name", "library"])
29-
RebuildPath = namedtuple("RebuildPath", ["path"])
36+
RebuildUnit = NamedTuple(
37+
"RebuildUnit", (("name", Identifier), ("type_", DesignUnitType))
38+
)
39+
RebuildLibraryUnit = NamedTuple(
40+
"RebuildLibraryUnit", (("name", Identifier), ("library", Identifier))
41+
)
42+
RebuildPath = NamedTuple("RebuildPath", (("path", Path),))
3043

3144
RebuildInfo = Union[RebuildUnit, RebuildLibraryUnit, RebuildPath]
3245

0 commit comments

Comments
 (0)