Skip to content

Commit 746b483

Browse files
committed
Fix some Vivado issues (SystemVerilog support, space in file name, environment variable)
1 parent 3292c28 commit 746b483

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

docs/conf.py

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

1717
extensions = [
1818
"sphinx.ext.autodoc",
19+
"sphinx.ext.autosummary",
1920
"sphinx.ext.extlinks",
2021
"sphinx.ext.intersphinx",
2122
"sphinx.ext.todo",
@@ -85,7 +86,7 @@
8586
# -- InterSphinx ----------------------------------------------------------
8687

8788
intersphinx_mapping = {
88-
"python": ("https://docs.python.org/3.8/", None),
89+
"python": ("https://docs.python.org/3/", None),
8990
"pytest": ("https://docs.pytest.org/en/latest/", None),
9091
}
9192

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ often"* approach through automation. :ref:`Read more <about>`
4747
py/ui
4848
vhdl_libraries
4949
examples
50+
py/vivado
5051

5152
.. toctree::
5253
:caption: Continuous Integration

docs/py/vivado.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Vivado Integration
2+
==================
3+
4+
.. automodule:: vunit.vivado
5+
: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: 32 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

@@ -31,7 +37,7 @@ def add_from_compile_order_file(
3137
no_dependency_scan = []
3238
with_dependency_scan = []
3339
for library_name, file_name in compile_order:
34-
is_verilog = file_name.endswith(".v") or file_name.endswith(".vp")
40+
is_verilog = file_name.endswith((".v", ".vp", ".sv"))
3541

3642
# Optionally use VUnit dependency scanning for everything in xil_defaultlib, which
3743
# typically contains unencrypted top levels that instantiate encrypted implementations.
@@ -63,7 +69,13 @@ def add_from_compile_order_file(
6369

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

@@ -81,7 +93,7 @@ def create_compile_order_file(project_file, compile_order_file, vivado_path=None
8193

8294
def _read_compile_order(file_name, fail_on_non_hdl_files):
8395
"""
84-
Read the compile order file and filter out duplicate files
96+
Read the compile order file and filter out duplicate files.
8597
"""
8698
compile_order = []
8799
unique = set()
@@ -93,7 +105,7 @@ def _read_compile_order(file_name, fail_on_non_hdl_files):
93105
for line in ifile.readlines():
94106
library_name, file_type, file_name = line.strip().split(",", 2)
95107

96-
if file_type not in ("Verilog", "VHDL", "Verilog Header"):
108+
if file_type not in ("Verilog", "VHDL", "Verilog Header", "SystemVerilog"):
97109
if fail_on_non_hdl_files:
98110
raise RuntimeError(f"Unsupported compile order file: {file_name}")
99111
print(f"Compile order file ignored: {file_name}")
@@ -120,12 +132,22 @@ def run_vivado(tcl_file_name, tcl_args=None, cwd=None, vivado_path=None):
120132
"""
121133
Run tcl script in Vivado in batch mode.
122134
123-
Note: the shell=True is important in windows where Vivado is just a bat file.
135+
:param tcl_file_name: Path to tcl file
136+
:param tcl_args: tcl arguments passed to Vivado via the ``-tclargs`` switch
137+
:param cwd: Passed as ``cwd`` to :func:`subprocess.check_call`
138+
:param vivado_path: Path to Vivado install directory. If ``None``, the
139+
environment variable ``VUNIT_VIVADO_PATH`` is used if set. Otherwise,
140+
rely on that ``vivado`` is in the path.
124141
"""
125-
vivado = "vivado" if vivado_path is None else str(Path(vivado_path).resolve() / "bin" / "vivado")
126-
cmd = f"{vivado} -nojournal -nolog -notrace -mode batch -source {str(Path(tcl_file_name).resolve())}"
142+
vivado = (
143+
str(Path(vivado_path).resolve() / "bin" / "vivado")
144+
if vivado_path is not None
145+
else environ.get("VUNIT_VIVADO_PATH", "vivado")
146+
)
147+
cmd = f'"{vivado}" -nojournal -nolog -notrace -mode batch -source "{str(Path(tcl_file_name).resolve())}"'
127148
if tcl_args is not None:
128-
cmd += " -tclargs " + " ".join([str(val) for val in tcl_args])
149+
cmd += " -tclargs " + " ".join([f'"{val}"' for val in tcl_args])
129150

130151
print(cmd)
152+
# shell=True is important in Windows where Vivado is just a bat file.
131153
check_call(cmd, cwd=cwd, shell=True)

0 commit comments

Comments
 (0)