VUnit / vunit

VUnit is a unit testing framework for VHDL/SystemVerilog
http://vunit.github.io/
Other
739 stars 263 forks source link

Add VUNIT_VIVADO_PATH env variable #811

Open dbalthazor opened 2 years ago

dbalthazor commented 2 years ago

The vivado.py python script pulls the path to the vivado binary from either the user's path or from method argument, rather than from a env variable like the simulator paths. Modifying the run_vivado method under vivado.py to pull from an env variable would make it much easier to work with multiple local vivado installs on a machine, and unify this code with how VUnit specifies other binaries.

The run_vivado method might look something like this

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.
    """
    vivado = os.environ.get("VUNIT_VIVADO_PATH", None) 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())}"
    if tcl_args is not None:
        cmd += " -tclargs " + " ".join([str(val) for val in tcl_args])

    print(cmd)
    check_call(cmd, cwd=cwd, shell=True)
LarsAsplund commented 2 years ago

@dbalthazor Adding an environment variable is a good idea but I think we should keep the current behavior to search the user's path if no environment variable is given. That will maintain backward compatibility. In order of priority:

  1. Use vivado_path
  2. Use VUNIT_VIVADO_PATH
  3. Use vivado

or

vivado = str(Path(vivado_path).resolve() / "bin" / "vivado") if vivado_path is not None else environ["VUNIT_VIVADO_PATH"] if "VUNIT_VIVADO_PATH" in environ else "vivado"