Skip to content

Commit deedbe9

Browse files
committed
Allow $vunit_tb_path in init file paths. Solves #1075.
1 parent 2210608 commit deedbe9

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

docs/py/opts.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ The following simulation options are known.
121121
A list of user defined DO/TCL-files that is sourced after the design has been loaded.
122122
They will be executed during ``vunit_load``, after the top level has been loaded
123123
using the ``vsim`` command.
124-
During script evaluation the ``vunit_tb_path`` variable is defined
124+
During script and file path evaluation the ``vunit_tb_path`` variable is defined
125125
as the path of the folder containing the test bench.
126126
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
127127
Must be a list of strings.
@@ -135,7 +135,7 @@ The following simulation options are known.
135135
``modelsim.init_file.gui``
136136
A user defined TCL-file that is sourced after the design has been loaded in the GUI.
137137
For example this can be used to configure the waveform viewer.
138-
During script evaluation the ``vunit_tb_path`` variable is defined
138+
During script and file path evaluation the ``vunit_tb_path`` variable is defined
139139
as the path of the folder containing the test bench.
140140
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
141141
Must be a string.
@@ -166,7 +166,7 @@ The following simulation options are known.
166166
A list of user defined DO/TCL-files that is sourced after the design has been loaded.
167167
They will be executed during ``vunit_load``, after the top level has been loaded
168168
using the ``vsim`` command.
169-
During script evaluation the ``vunit_tb_path`` variable is defined
169+
During script and file path evaluation the ``vunit_tb_path`` variable is defined
170170
as the path of the folder containing the test bench.
171171
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
172172
Must be a list of strings.
@@ -180,7 +180,7 @@ The following simulation options are known.
180180
``rivierapro.init_file.gui``
181181
A user defined TCL-file that is sourced after the design has been loaded in the GUI.
182182
For example this can be used to configure the waveform viewer.
183-
During script evaluation the ``vunit_tb_path`` variable is defined
183+
During script and file path evaluation the ``vunit_tb_path`` variable is defined
184184
as the path of the folder containing the test bench.
185185
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
186186
Must be a string.
@@ -197,7 +197,7 @@ The following simulation options are known.
197197
``activehdl.init_file.gui``
198198
A user defined TCL-file that is sourced after the design has been loaded in the GUI.
199199
For example this can be used to configure the waveform viewer.
200-
During script evaluation the ``vunit_tb_path`` variable is defined
200+
During script and file path evaluation the ``vunit_tb_path`` variable is defined
201201
as the path of the folder containing the test bench.
202202
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
203203
Must be a string.

vunit/sim_if/activehdl.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,22 @@ def _create_user_init_function(self, config):
463463
simulator_name.init_file.gui.
464464
Also defines the vunit_tb_path and the vunit_tb_name variable.
465465
"""
466+
466467
opt_name = self.name + ".init_file.gui"
467468
init_file = config.sim_options.get(opt_name, None)
469+
468470
tcl = "proc vunit_user_init {} {\n"
469471
if init_file is not None:
472+
# Do not resolve paths starting with $vunit_tb_path but
473+
# leave that to TCL variable expansion
474+
init_file_path = Path(init_file)
475+
if not init_file.startswith("$vunit_tb_path"):
476+
init_file_path = init_file_path.resolve()
477+
init_file_path = fix_path(str(init_file_path))
478+
470479
tcl += f"set vunit_tb_name {config.design_unit_name}\n"
471480
tcl += f"set vunit_tb_path {fix_path(str(Path(config.tb_path).resolve()))}\n"
472-
tcl += f'source "{fix_path(str(Path(init_file).resolve()))!s}"\n'
481+
tcl += f'source "{init_file_path}"\n'
473482
tcl += " return 0\n"
474483
tcl += "}\n"
475484
return tcl

vunit/sim_if/vsim_simulator_mixin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,15 @@ def _source_tcl_file(file_name, config, message):
280280
Create TCL to source a file and catch errors
281281
Also defines the vunit_tb_path variable as the config.tb_path
282282
and the vunit_tb_name variable as the config.design_unit_name
283-
284283
"""
284+
285+
# Do not resolve paths starting with $vunit_tb_path but
286+
# leave that to TCL variable expansion
287+
file_name_path = Path(file_name)
288+
if not file_name.startswith("$vunit_tb_path"):
289+
file_name_path = file_name_path.resolve()
290+
file_name_path = fix_path(str(file_name_path))
291+
285292
template = """
286293
set vunit_tb_path "%s"
287294
set vunit_tb_name "%s"
@@ -296,7 +303,7 @@ def _source_tcl_file(file_name, config, message):
296303
tcl = template % (
297304
fix_path(str(Path(config.tb_path).resolve())),
298305
config.design_unit_name,
299-
fix_path(str(Path(file_name).resolve())),
306+
file_name_path,
300307
message,
301308
)
302309
return tcl

0 commit comments

Comments
 (0)