From ff77978dd78088c06ea2f67a7900e6c43afc6612 Mon Sep 17 00:00:00 2001 From: alexrayne Date: Fri, 31 May 2024 10:37:49 +0300 Subject: [PATCH 1/3] add_external_library( path = None ...) - allow use external library provided by simulator. Need when dependancy evaluation can't investigate all libraries - for example when verlog modules relates to verilog libraries, and there is no sv package, that handle it. Modelsim - ini provides external libraryes, that can used such way. --- vunit/project.py | 31 ++++++++++++++++++++----------- vunit/sim_if/modelsim.py | 12 +++++++++--- vunit/ui/__init__.py | 8 ++++++-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/vunit/project.py b/vunit/project.py index c9bc4f14c..a217c8763 100644 --- a/vunit/project.py +++ b/vunit/project.py @@ -83,28 +83,37 @@ def add_builtin_library(self, logical_name): def add_library( self, logical_name, - directory: Union[str, Path], + directory: Union[str, Path] = None, vhdl_standard: VHDLStandard = VHDL.STD_2008, is_external=False, ): """ Add library to project with logical_name located or to be located in directory is_external -- Library is assumed to a black-box + + :param directory: The path to the external library directory + if None - supposes simulator provides library_name """ self._validate_new_library_name(logical_name) - dpath = Path(directory) - dstr = str(directory) - - if is_external: - if not dpath.exists(): - raise ValueError(f"External library {dstr!r} does not exist") - - if not dpath.is_dir(): - raise ValueError(f"External library must be a directory. Got {dstr!r}") + if directory : + dpath = Path(directory) + dstr = str(directory) + + if is_external: + if not dpath.exists(): + raise ValueError(f"External library {dstr!r} does not exist") + + if not dpath.is_dir(): + raise ValueError(f"External library must be a directory. Got {dstr!r}") + + LOGGER.debug("Adding library %s with path %s", logical_name, dstr) + else: + dstr = None + is_external = True + LOGGER.debug("Use library %s", logical_name) library = Library(logical_name, dstr, vhdl_standard, is_external=is_external) - LOGGER.debug("Adding library %s with path %s", logical_name, dstr) self._libraries[logical_name] = library self._lower_library_names_dict[logical_name.lower()] = library.name diff --git a/vunit/sim_if/modelsim.py b/vunit/sim_if/modelsim.py index dc353211d..70818ac5f 100644 --- a/vunit/sim_if/modelsim.py +++ b/vunit/sim_if/modelsim.py @@ -202,6 +202,15 @@ def create_library(self, library_name, path, mapped_libraries=None): """ mapped_libraries = mapped_libraries if mapped_libraries is not None else {} + if library_name in mapped_libraries: + if mapped_libraries[library_name] == path: + return + elif path is None: # use existing map + return + + if path is None: + raise ValueError(f"External library {library_name!r} does not exist") + apath = str(Path(path).parent.resolve()) if not file_exists(apath): @@ -211,9 +220,6 @@ def create_library(self, library_name, path, mapped_libraries=None): proc = Process([str(Path(self._prefix) / "vlib"), "-unix", path], env=self.get_env()) proc.consume_output(callback=None) - if library_name in mapped_libraries and mapped_libraries[library_name] == path: - return - cfg = parse_modelsimini(self._sim_cfg_file_name) cfg.set("Library", library_name, path) write_modelsimini(cfg, self._sim_cfg_file_name) diff --git a/vunit/ui/__init__.py b/vunit/ui/__init__.py index 3ddc531e3..9e5f812a4 100644 --- a/vunit/ui/__init__.py +++ b/vunit/ui/__init__.py @@ -207,12 +207,13 @@ def _which_vhdl_standard(self, vhdl_standard: Optional[str]) -> VHDLStandard: return VHDL.standard(vhdl_standard) - def add_external_library(self, library_name, path: Union[str, Path], vhdl_standard: Optional[str] = None): + def add_external_library(self, library_name, path: Union[str, Path] = None, vhdl_standard: Optional[str] = None): """ Add an externally compiled library as a black-box :param library_name: The name of the external library :param path: The path to the external library directory + if None - supposes simulator provides library_name :param vhdl_standard: The VHDL standard used to compile files, if None the VUNIT_VHDL_STANDARD environment variable is used :returns: The created :class:`.Library` object @@ -225,9 +226,12 @@ def add_external_library(self, library_name, path: Union[str, Path], vhdl_standa """ + if path: + path = Path(path).resolve() + self._project.add_library( library_name, - Path(path).resolve(), + path, self._which_vhdl_standard(vhdl_standard), is_external=True, ) From a2294793092bbf4b2e67d2fb42550f3c188ff300 Mon Sep 17 00:00:00 2001 From: alexrayne Date: Mon, 3 Jun 2024 11:31:54 +0300 Subject: [PATCH 2/3] white space typo for make linter happy --- vunit/project.py | 8 ++++---- vunit/sim_if/modelsim.py | 6 +++--- vunit/ui/__init__.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/vunit/project.py b/vunit/project.py index a217c8763..85a192296 100644 --- a/vunit/project.py +++ b/vunit/project.py @@ -90,7 +90,7 @@ def add_library( """ Add library to project with logical_name located or to be located in directory is_external -- Library is assumed to a black-box - + :param directory: The path to the external library directory if None - supposes simulator provides library_name """ @@ -99,14 +99,14 @@ def add_library( if directory : dpath = Path(directory) dstr = str(directory) - + if is_external: if not dpath.exists(): raise ValueError(f"External library {dstr!r} does not exist") - + if not dpath.is_dir(): raise ValueError(f"External library must be a directory. Got {dstr!r}") - + LOGGER.debug("Adding library %s with path %s", logical_name, dstr) else: dstr = None diff --git a/vunit/sim_if/modelsim.py b/vunit/sim_if/modelsim.py index 70818ac5f..9dd8a8a5d 100644 --- a/vunit/sim_if/modelsim.py +++ b/vunit/sim_if/modelsim.py @@ -205,12 +205,12 @@ def create_library(self, library_name, path, mapped_libraries=None): if library_name in mapped_libraries: if mapped_libraries[library_name] == path: return - elif path is None: # use existing map + elif path is None: # use existing map return - + if path is None: raise ValueError(f"External library {library_name!r} does not exist") - + apath = str(Path(path).parent.resolve()) if not file_exists(apath): diff --git a/vunit/ui/__init__.py b/vunit/ui/__init__.py index 9e5f812a4..d6f7d728a 100644 --- a/vunit/ui/__init__.py +++ b/vunit/ui/__init__.py @@ -228,7 +228,7 @@ def add_external_library(self, library_name, path: Union[str, Path] = None, vhdl if path: path = Path(path).resolve() - + self._project.add_library( library_name, path, From c14f97a4e1597448fc00cf4241bf0a586dd96613 Mon Sep 17 00:00:00 2001 From: alexrayne Date: Tue, 18 Jun 2024 12:31:50 +0300 Subject: [PATCH 3/3] make linter happy --- vunit/project.py | 2 +- vunit/sim_if/modelsim.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vunit/project.py b/vunit/project.py index 85a192296..ef5f25916 100644 --- a/vunit/project.py +++ b/vunit/project.py @@ -83,7 +83,7 @@ def add_builtin_library(self, logical_name): def add_library( self, logical_name, - directory: Union[str, Path] = None, + directory: Union[str, Path, None] = None, vhdl_standard: VHDLStandard = VHDL.STD_2008, is_external=False, ): diff --git a/vunit/sim_if/modelsim.py b/vunit/sim_if/modelsim.py index 9dd8a8a5d..c247c571f 100644 --- a/vunit/sim_if/modelsim.py +++ b/vunit/sim_if/modelsim.py @@ -205,7 +205,7 @@ def create_library(self, library_name, path, mapped_libraries=None): if library_name in mapped_libraries: if mapped_libraries[library_name] == path: return - elif path is None: # use existing map + if path is None: # use existing map return if path is None: