Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/unit/test_modelsim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,46 @@ def test_overwrites_modelsim_ini_file_from_user(self):
with open(modelsim_ini, "r") as fptr:
self.assertEqual(fptr.read(), "user")

def test_hierarchical_library_mapping(self):
modelsim_ini = str(Path(self.test_path) / "modelsim.ini")
sub_modelsim_ini = str(Path(self.test_path) / "sub_modelsim.ini")
sub_sub_modelsim_ini = str(Path(self.test_path) / "sub_sub_modelsim.ini")

with open(modelsim_ini, "w") as fptr:
fptr.write("\n".join([
"[Library]",
"top_lib=top_lib_path",
"others=" + sub_modelsim_ini,
]))

with open(sub_modelsim_ini, "w") as fptr:
fptr.write("\n".join([
"[Library]",
"top_lib=ignore",
"sub_lib=sub_lib_path",
"others=" + sub_sub_modelsim_ini,
]))

with open(sub_sub_modelsim_ini, "w") as fptr:
fptr.write("\n".join([
"[Library]",
"top_lib=ignore",
"sub_lib=ignore",
"sub_sub_lib=sub_sub_lib_path",
]))

with set_env(VUNIT_MODELSIM_INI=modelsim_ini):
simif = ModelSimInterface(prefix=self.prefix_path, output_path=self.output_path, persistent=False)

project = Project()
num_std_libs = len(project._builtin_libraries)
simif.compile_project(project)

self.assertIn("top_lib", project._builtin_libraries)
self.assertIn("sub_lib", project._builtin_libraries)
self.assertIn("sub_sub_lib", project._builtin_libraries)
self.assertEqual(3, len(project._builtin_libraries) - num_std_libs)

def setUp(self):
self.test_path = str(Path(__file__).parent / "test_modelsim_out")

Expand Down
8 changes: 6 additions & 2 deletions vunit/sim_if/modelsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,17 @@ def create_library(self, library_name, path, mapped_libraries=None):
cfg.set("Library", library_name, path)
write_modelsimini(cfg, self._sim_cfg_file_name)

def _get_mapped_libraries(self):
def _get_mapped_libraries(self, cfg_file_name=None):
"""
Get mapped libraries from modelsim.ini file
"""
cfg = parse_modelsimini(self._sim_cfg_file_name)
cfg_file_name = cfg_file_name if cfg_file_name is not None else self._sim_cfg_file_name
cfg = parse_modelsimini(cfg_file_name)
libraries = dict(cfg.items("Library"))
if "others" in libraries:
other_libraries = self._get_mapped_libraries(libraries["others"])
# current mappings take precedence over others
libraries = {**other_libraries, **libraries}
del libraries["others"]
return libraries

Expand Down