From 56ee9adc753948b938fb9bb6ef1ca47e77259858 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 7 Nov 2022 12:32:22 +0100 Subject: [PATCH] Fix some Vivado issues (SystemVerilog support, space in file name, environment variable) --- vunit/vivado/vivado.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/vunit/vivado/vivado.py b/vunit/vivado/vivado.py index 91c31bbb4c..c249302a38 100644 --- a/vunit/vivado/vivado.py +++ b/vunit/vivado/vivado.py @@ -9,7 +9,7 @@ """ from subprocess import check_call -from os import makedirs +from os import makedirs, environ from pathlib import Path @@ -31,7 +31,7 @@ def add_from_compile_order_file( no_dependency_scan = [] with_dependency_scan = [] for library_name, file_name in compile_order: - is_verilog = file_name.endswith(".v") or file_name.endswith(".vp") + is_verilog = file_name.endswith((".v", ".vp", ".sv")) # Optionally use VUnit dependency scanning for everything in xil_defaultlib, which # typically contains unencrypted top levels that instantiate encrypted implementations. @@ -81,7 +81,7 @@ def create_compile_order_file(project_file, compile_order_file, vivado_path=None def _read_compile_order(file_name, fail_on_non_hdl_files): """ - Read the compile order file and filter out duplicate files + Read the compile order file and filter out duplicate files. """ compile_order = [] unique = set() @@ -93,7 +93,7 @@ def _read_compile_order(file_name, fail_on_non_hdl_files): for line in ifile.readlines(): library_name, file_type, file_name = line.strip().split(",", 2) - if file_type not in ("Verilog", "VHDL", "Verilog Header"): + if file_type not in ("Verilog", "VHDL", "Verilog Header", "SystemVerilog"): if fail_on_non_hdl_files: raise RuntimeError(f"Unsupported compile order file: {file_name}") print(f"Compile order file ignored: {file_name}") @@ -120,12 +120,22 @@ def run_vivado(tcl_file_name, tcl_args=None, cwd=None, vivado_path=None): """ Run tcl script in Vivado in batch mode. - Note: the shell=True is important in windows where Vivado is just a bat file. + :param tcl_file_name: Path to tcl file + :param tcl_args: tcl arguments passed to Vivado via the ``-tclargs`` switch + :param cwd: Passed as ``cwd`` to ``subprocess.check_call`` + :param vivado_path: Path to Vivado install directory. If ``None``, the + environment variable ``VUNIT_VIVADO_PATH`` is used if set. Otherwise, + rely on that ``vivado`` is in the path. """ - vivado = "vivado" if vivado_path is None else str(Path(vivado_path).resolve() / "bin" / "vivado") - cmd = f"{vivado} -nojournal -nolog -notrace -mode batch -source {str(Path(tcl_file_name).resolve())}" + vivado = ( + str(Path(vivado_path).resolve() / "bin" / "vivado") + if vivado_path is not None + else environ.get("VUNIT_VIVADO_PATH", "vivado") + ) + cmd = f'"{vivado}" -nojournal -nolog -notrace -mode batch -source "{str(Path(tcl_file_name).resolve())}"' if tcl_args is not None: - cmd += " -tclargs " + " ".join([str(val) for val in tcl_args]) + cmd += " -tclargs " + " ".join([f'"{val}"' for val in tcl_args]) print(cmd) + # shell=True is important in Windows where Vivado is just a bat file. check_call(cmd, cwd=cwd, shell=True)