build/xilinx/vivado: only try Xilinx setup if vivado is not already in the path

Only affects the non-Windows code path.
Uses python distutils, already used elsewhere.
This commit is contained in:
Larry Doolittle 2019-04-22 15:42:31 -07:00
parent 7d278854d5
commit fda18fd6ef
1 changed files with 17 additions and 13 deletions

View File

@ -5,6 +5,7 @@ import os
import subprocess import subprocess
import sys import sys
import math import math
from distutils import spawn
from migen.fhdl.structure import _Fragment from migen.fhdl.structure import _Fragment
@ -65,6 +66,9 @@ def _run_vivado(build_name, vivado_path, source, ver=None):
else: else:
build_script_contents = "# Autogenerated by Migen\nset -e\n" build_script_contents = "# Autogenerated by Migen\nset -e\n"
# No reason to search for vivado if it's already in our $PATH
# https://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
if not spawn.find_executable("vivado"):
# For backwards compatibility with ISE paths, also # For backwards compatibility with ISE paths, also
# look for a version in a subdirectory named "Vivado" # look for a version in a subdirectory named "Vivado"
# under the current directory. # under the current directory.
@ -77,8 +81,8 @@ def _run_vivado(build_name, vivado_path, source, ver=None):
break break
else: else:
raise OSError("Unable to locate Vivado directory or settings.") raise OSError("Unable to locate Vivado directory or settings.")
build_script_contents += "source " + settings + "\n" build_script_contents += "source " + settings + "\n"
build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n" build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n"
build_script_file = "build_" + build_name + ".sh" build_script_file = "build_" + build_name + ".sh"
tools.write_to_file(build_script_file, build_script_contents) tools.write_to_file(build_script_file, build_script_contents)