Skip to content

Commit 319370d

Browse files
committed
Fix some Vivado issues (SystemVerilog support, space in file name, environment variable)
1 parent a61579d commit 319370d

5 files changed

Lines changed: 50 additions & 11 deletions

File tree

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
extensions = [
3232
"sphinx.ext.autodoc",
33+
"sphinx.ext.autosummary",
3334
"sphinx.ext.extlinks",
3435
"sphinx.ext.intersphinx",
3536
"sphinx.ext.todo",
@@ -113,7 +114,7 @@
113114
# -- InterSphinx --------------------------------------------------------------
114115

115116
intersphinx_mapping = {
116-
"python": ("https://docs.python.org/3.8/", None),
117+
"python": ("https://docs.python.org/3/", None),
117118
"pytest": ("https://docs.pytest.org/en/latest/", None),
118119
"osvb": ("https://umarcor.github.io/osvb", None),
119120
}

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ often"* approach through automation. :ref:`Read more <about>`
4949
py/ui
5050
hdl_libraries
5151
examples
52+
tool_integration/index
5253

5354
.. toctree::
5455
:caption: Continuous Integration

docs/tool_integration/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. _tool_integration:
2+
3+
Tool Integration
4+
================
5+
There are additional integration support available for selected tools.
6+
7+
Vivado Integration
8+
==================
9+
10+
.. automodule:: vunit.vivado
11+
:members:

vunit/vivado/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
add_from_compile_order_file,
1414
create_compile_order_file,
1515
)
16+
17+
__all__ = ["run_vivado", "add_from_compile_order_file", "create_compile_order_file"]

vunit/vivado/vivado.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@
99
"""
1010

1111
from subprocess import check_call
12-
from os import makedirs
12+
from os import makedirs, environ
1313
from pathlib import Path
1414

1515

1616
def add_from_compile_order_file(
1717
vunit_obj, compile_order_file, dependency_scan_defaultlib=True, fail_on_non_hdl_files=True
1818
): # pylint: disable=too-many-locals
1919
"""
20-
Add Vivado IP:s from a compile order file
20+
Add Vivado IP:s from a compile order file.
21+
22+
:param project_file: :class:`~vunit.ui.VUnit`
23+
:param compile_order_file: Compile-order file (from :func:`create_compile_order_file`)
24+
:param dependency_scan_defaultlib: Whether to do VUnit scanning of ``xil_defaultlib``.
25+
:param fail_on_non_hdl_files: Whether to fail on non-HDL files.
26+
2127
"""
2228
compile_order, libraries, include_dirs = _read_compile_order(compile_order_file, fail_on_non_hdl_files)
2329

@@ -30,8 +36,9 @@ def add_from_compile_order_file(
3036

3137
no_dependency_scan = []
3238
with_dependency_scan = []
39+
verilog_file_endings = (".v", ".vp", ".sv")
3340
for library_name, file_name in compile_order:
34-
is_verilog = file_name.endswith(".v") or file_name.endswith(".vp")
41+
is_verilog = file_name.endswith(verilog_file_endings)
3542

3643
# Optionally use VUnit dependency scanning for everything in xil_defaultlib, which
3744
# typically contains unencrypted top levels that instantiate encrypted implementations.
@@ -63,7 +70,13 @@ def add_from_compile_order_file(
6370

6471
def create_compile_order_file(project_file, compile_order_file, vivado_path=None):
6572
"""
66-
Create compile file from Vivado project
73+
Create compile file from Vivado project.
74+
75+
:param project_file: Project filename.
76+
:param compile_order_file: Filename for to write compile-order file.
77+
:param vivado_path: Path to Vivado install directory. If ``None``, the
78+
environment variable ``VUNIT_VIVADO_PATH`` is used if set. Otherwise,
79+
rely on that ``vivado`` is in the path.
6780
"""
6881
print(f"Generating Vivado project compile order into {str(Path(compile_order_file).resolve())} ...")
6982

@@ -81,18 +94,19 @@ def create_compile_order_file(project_file, compile_order_file, vivado_path=None
8194

8295
def _read_compile_order(file_name, fail_on_non_hdl_files):
8396
"""
84-
Read the compile order file and filter out duplicate files
97+
Read the compile order file and filter out duplicate files.
8598
"""
8699
compile_order = []
87100
unique = set()
88101
include_dirs = set()
89102
libraries = set()
90103

104+
valid_file_types = ("Verilog", "VHDL", "Verilog Header", "SystemVerilog")
91105
with Path(file_name).open("r", encoding="utf-8") as ifile:
92106
for line in ifile.readlines():
93107
library_name, file_type, file_name = line.strip().split(",", 2)
94108

95-
if file_type not in ("Verilog", "VHDL", "Verilog Header"):
109+
if file_type not in valid_file_types:
96110
if fail_on_non_hdl_files:
97111
raise RuntimeError(f"Unsupported compile order file: {file_name}")
98112
print(f"Compile order file ignored: {file_name}")
@@ -119,12 +133,22 @@ def run_vivado(tcl_file_name, tcl_args=None, cwd=None, vivado_path=None):
119133
"""
120134
Run tcl script in Vivado in batch mode.
121135
122-
Note: the shell=True is important in windows where Vivado is just a bat file.
136+
:param tcl_file_name: Path to tcl file
137+
:param tcl_args: tcl arguments passed to Vivado via the ``-tclargs`` switch
138+
:param cwd: Passed as ``cwd`` to :func:`subprocess.check_call`
139+
:param vivado_path: Path to Vivado install directory. If ``None``, the
140+
environment variable ``VUNIT_VIVADO_PATH`` is used if set. Otherwise,
141+
rely on that ``vivado`` is in the path.
123142
"""
124-
vivado = "vivado" if vivado_path is None else str(Path(vivado_path).resolve() / "bin" / "vivado")
125-
cmd = f"{vivado} -nojournal -nolog -notrace -mode batch -source {str(Path(tcl_file_name).resolve())}"
143+
vivado = (
144+
str(Path(vivado_path).resolve() / "bin" / "vivado")
145+
if vivado_path is not None
146+
else environ.get("VUNIT_VIVADO_PATH", "vivado")
147+
)
148+
cmd = f'"{vivado}" -nojournal -nolog -notrace -mode batch -source "{Path(tcl_file_name).resolve()}"'
126149
if tcl_args is not None:
127-
cmd += " -tclargs " + " ".join([str(val) for val in tcl_args])
150+
cmd += " -tclargs " + " ".join([f'"{val}"' for val in tcl_args])
128151

129152
print(cmd)
153+
# shell=True is important in Windows where Vivado is just a bat file.
130154
check_call(cmd, cwd=cwd, shell=True)

0 commit comments

Comments
 (0)