Skip to content

Commit

Permalink
builtins: skip addition of builtins if the library is added previously
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor authored and eine committed Nov 11, 2021
1 parent 58145ae commit 7928e8d
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions vunit/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
from pathlib import Path
from glob import glob
from warnings import warn
import logging

from vunit.vhdl_standard import VHDL, VHDLStandard
from vunit.ui.common import get_checked_file_names_from_globs


LOGGER = logging.getLogger(__name__)

VHDL_PATH = (Path(__file__).parent / "vhdl").resolve()
VERILOG_PATH = (Path(__file__).parent / "verilog").resolve()

Expand Down Expand Up @@ -130,16 +135,26 @@ def _add_verification_components(self):
raise RuntimeError("Verification component library only supports vhdl 2008 and later")
self._add_files(VHDL_PATH / "verification_components" / "src" / "*.vhd")

def _add_library_if_not_exist(self, library_name, message):
"""
Check if a library name exists in the project. If not, add it and return a handle.
"""
if library_name.lower() in [
library.lower() for library in self._vunit_obj._project._libraries # pylint: disable=protected-access
]:
LOGGER.warning(message)
return None
return self._vunit_obj.add_library(library_name)

def _add_osvvm(self):
"""
Add osvvm library
"""
library_name = "osvvm"

try:
library = self._vunit_obj.library(library_name)
except KeyError:
library = self._vunit_obj.add_library(library_name)
library = self._add_library_if_not_exist(
"osvvm", "Library 'OSVVM' previously defined. Skipping addition of builtin OSVVM (2021.09)."
)
if library is None:
return

simulator_coverage_api = self._simulator_class.get_osvvm_coverage_api()
supports_vhdl_package_generics = self._simulator_class.supports_vhdl_package_generics()
Expand Down Expand Up @@ -190,12 +205,11 @@ def _add_json4vhdl(self):
"""
Add JSON-for-VHDL library
"""
library_name = "JSON"

try:
library = self._vunit_obj.library(library_name)
except KeyError:
library = self._vunit_obj.add_library(library_name)
library = self._add_library_if_not_exist(
"JSON", "Library 'JSON' previously defined. Skipping addition of builtin JSON-for-VHDL (c8a6f51)."
)
if library is None:
return

library.add_source_files(VHDL_PATH / "JSON-for-VHDL" / "src" / "*.vhdl")

Expand Down

0 comments on commit 7928e8d

Please sign in to comment.