Skip to content

Commit

Permalink
Added possibility to set <SIMULATOR_NAME>_PATH environment variable t…
Browse files Browse the repository at this point in the history
…o explicitly set simulator executable prefix. Closes #148
  • Loading branch information
kraigher committed Mar 13, 2016
1 parent beabadd commit 63741c7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 37 deletions.
11 changes: 2 additions & 9 deletions vunit/activehdl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,15 @@ def from_args(cls, output_path, args):
"""
Create new instance from command line arguments object
"""
return cls(prefix=cls._find_prefix(),
return cls(prefix=cls.find_prefix(),
library_cfg=join(output_path, "library.cfg"),
gui=args.gui)

@classmethod
def _find_prefix(cls):
def find_prefix_from_path(cls):
return cls.find_toolchain(["vsim",
"avhdl"])

@classmethod
def is_available(cls):
"""
Return True if installed
"""
return cls._find_prefix() is not None

def __init__(self, prefix, library_cfg="library.cfg", gui=False):
self._vhdl_standard = None
self._library_cfg = abspath(library_cfg)
Expand Down
11 changes: 2 additions & 9 deletions vunit/ghdl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,19 @@ def from_args(cls,
"""
Create instance from args namespace
"""
prefix = cls._find_prefix()
prefix = cls.find_prefix()
return cls(prefix=prefix,
gtkwave=args.gtkwave,
gtkwave_args=args.gtkwave_args,
backend=cls.determine_backend(prefix))

@classmethod
def _find_prefix(cls):
def find_prefix_from_path(cls):
"""
Find first valid ghdl toolchain prefix
"""
return cls.find_toolchain(["ghdl"])

@classmethod
def is_available(cls):
"""
Return True if GHDL is installed
"""
return cls._find_prefix() is not None

def __init__(self, prefix, gtkwave=None, gtkwave_args="", backend="llvm"):
self._prefix = prefix
self._libraries = {}
Expand Down
12 changes: 2 additions & 10 deletions vunit/modelsim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,23 @@ def from_args(cls, output_path, args):
"""
persistent = not (args.new_vsim or args.gui)

return cls(prefix=cls._find_prefix(),
return cls(prefix=cls.find_prefix(),
modelsim_ini=join(output_path, "modelsim.ini"),
persistent=persistent,
coverage=args.coverage,
gui_mode="load" if args.gui else None)

@classmethod
def _find_prefix(cls):
def find_prefix_from_path(cls):
"""
Find first valid modelsim toolchain prefix
"""

def has_modelsim_ini(path):
return os.path.isfile(join(path, "..", "modelsim.ini"))

return cls.find_toolchain(["vsim"],
constraints=[has_modelsim_ini])

@classmethod
def is_available(cls):
"""
Return True if ModelSim is installed
"""
return cls._find_prefix() is not None

def __init__(self, prefix, modelsim_ini="modelsim.ini", persistent=False, gui_mode=None, coverage=None):
self._vhdl_standard = None
self._modelsim_ini = abspath(modelsim_ini)
Expand Down
11 changes: 2 additions & 9 deletions vunit/rivierapro_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def from_args(cls, output_path, args):
"""
Create new instance from command line arguments object
"""
return cls(prefix=cls._find_prefix(),
return cls(prefix=cls.find_prefix(),
library_cfg=join(output_path, "library.cfg"),
gui=args.gui)

@classmethod
def _find_prefix(cls):
def find_prefix_from_path(cls):
"""
Find RivieraPro toolchain.
Expand All @@ -63,13 +63,6 @@ def no_avhdl(path):
"vsimsa"],
constraints=[no_avhdl])

@classmethod
def is_available(cls):
"""
Return True if installed
"""
return cls._find_prefix() is not None

def __init__(self, prefix, library_cfg="library.cfg", gui=False):
self._vhdl_standard = None
self._library_cfg = abspath(library_cfg)
Expand Down
24 changes: 24 additions & 0 deletions vunit/simulator_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ def find_executable(executable):
result.append(file_name)
return result

@classmethod
def find_prefix(cls):
"""
Find prefix by looking at SIMULATOR_NAME_PATH environment variable
"""
prefix = os.environ.get(cls.name.upper() + "_PATH", None)
if prefix is not None:
return prefix
return cls.find_prefix_from_path()

@classmethod
def find_prefix_from_path(cls):
"""
Find simulator toolchain prefix from PATH environment variable
"""
return None

@classmethod
def is_available(cls):
"""
Returns True if simulator is available
"""
return cls.find_prefix() is not None

@classmethod
def find_toolchain(cls, executables, constraints=None):
"""
Expand Down
31 changes: 31 additions & 0 deletions vunit/test/unit/test_simulator_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,37 @@ def raise_compile_error(*args, **kwargs):
self.assertRaises(CompileError, simif.compile_source_files, project)
self.assertEqual(project.get_files_in_compile_order(incremental=True), [source_file])

@mock.patch("os.environ", autospec=True)
def test_find_prefix(self, environ):

class MySimulatorInterface(SimulatorInterface): # pylint: disable=abstract-method
"""
Dummy simulator interface for testing
"""
name = "simname"
prefix_from_path = None

@classmethod
def find_prefix_from_path(cls):
return cls.prefix_from_path

simif = MySimulatorInterface()
simif.name = "simname"
environ.get.return_value = None
self.assertEqual(simif.find_prefix(), None)
environ.get.assert_called_once_with("SIMNAME_PATH", None)

environ.reset_mock()
environ.get.return_value = "simname/bin"
self.assertEqual(simif.find_prefix(), "simname/bin")
environ.get.assert_called_once_with("SIMNAME_PATH", None)

environ.reset_mock()
environ.get.return_value = None
MySimulatorInterface.prefix_from_path = "prefix_from_path"
self.assertEqual(simif.find_prefix(), "prefix_from_path")
environ.get.assert_called_once_with("SIMNAME_PATH", None)

def setUp(self):
self.output_path = join(dirname(__file__), "test_simulator_interface__out")
renew_path(self.output_path)
Expand Down

0 comments on commit 63741c7

Please sign in to comment.