From 9ea3ff7ae2fb14f862697ebd5fac03679125bb7b Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 12 Sep 2019 21:56:48 +0000 Subject: [PATCH] build.plat: bypass tool detection if NMIGEN_*_env is set. It's not practical to detect tools within the toolchain environment for various reasons, so just assume the tools are there if the user says they are. Before this commit, the tools would be searched outside the toolchain environment, which of course would always fail for Vivado, ISE, etc. --- nmigen/build/plat.py | 15 +++++++++++---- nmigen/vendor/lattice_ecp5.py | 6 +++--- nmigen/vendor/xilinx_spartan_3_6.py | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/nmigen/build/plat.py b/nmigen/build/plat.py index c8e5058..1ad3999 100644 --- a/nmigen/build/plat.py +++ b/nmigen/build/plat.py @@ -60,12 +60,17 @@ class Platform(ResourceManager, metaclass=ABCMeta): raise TypeError("File contents must be str, bytes, or a file-like object") self.extra_files[filename] = content + @property + def _toolchain_env_var(self): + return f"NMIGEN_{self.toolchain}_env" + def build(self, elaboratable, name="top", build_dir="build", do_build=True, program_opts=None, do_program=False, **kwargs): - for tool in self.required_tools: - require_tool(tool) + if self._toolchain_env_var not in os.environ: + for tool in self.required_tools: + require_tool(tool) plan = self.prepare(elaboratable, name, **kwargs) if not do_build: @@ -78,6 +83,8 @@ class Platform(ResourceManager, metaclass=ABCMeta): self.toolchain_program(products, name, **(program_opts or {})) def has_required_tools(self): + if self._toolchain_env_var in os.environ: + return True return all(has_tool(name) for name in self.required_tools) @abstractmethod @@ -238,13 +245,13 @@ class TemplatedPlatform(Platform): "build_{{name}}.sh": """ # {{autogenerated}} set -e{{verbose("x")}} - [ -n "$NMIGEN_{{platform.toolchain}}_env" ] && . "$NMIGEN_{{platform.toolchain}}_env" + [ -n "${{platform._toolchain_env_var}}" ] && . "${{platform._toolchain_env_var}}" {{emit_commands("sh")}} """, "build_{{name}}.bat": """ @rem {{autogenerated}} {{quiet("@echo off")}} - if defined NMIGEN_{{platform.toolchain}}_env call %NMIGEN_{{platform.toolchain}}_env% + if defined {{platform._toolchain_env_var}} call %{{platform._toolchain_env_var}}% {{emit_commands("bat")}} """, } diff --git a/nmigen/vendor/lattice_ecp5.py b/nmigen/vendor/lattice_ecp5.py index db4ac06..c02e370 100644 --- a/nmigen/vendor/lattice_ecp5.py +++ b/nmigen/vendor/lattice_ecp5.py @@ -163,9 +163,9 @@ class LatticeECP5Platform(TemplatedPlatform): # {{autogenerated}} set -e{{verbose("x")}} if [ -z "$BASH" ] ; then exec /bin/bash "$0" "$@"; fi - if [ -n "$NMIGEN_{{platform.toolchain}}_env" ]; then - bindir=$(dirname "$NMIGEN_{{platform.toolchain}}_env") - . "$NMIGEN_{{platform.toolchain}}_env" + if [ -n "${{platform._toolchain_env_var}}" ]; then + bindir=$(dirname "${{platform._toolchain_env_var}}") + . "${{platform._toolchain_env_var}}" fi {{emit_commands("sh")}} """, diff --git a/nmigen/vendor/xilinx_spartan_3_6.py b/nmigen/vendor/xilinx_spartan_3_6.py index c4c18ce..00d6831 100644 --- a/nmigen/vendor/xilinx_spartan_3_6.py +++ b/nmigen/vendor/xilinx_spartan_3_6.py @@ -88,7 +88,7 @@ class XilinxSpartan3Or6Platform(TemplatedPlatform): # {{autogenerated}} set -e{{verbose("x")}} if [ -z "$BASH" ] ; then exec /bin/bash "$0" "$@"; fi - [ -n "$NMIGEN_{{platform.toolchain}}_env" ] && . "$NMIGEN_{{platform.toolchain}}_env" + [ -n "${{platform._toolchain_env_var}}" ] && . "${{platform._toolchain_env_var}}" {{emit_commands("sh")}} """, "{{name}}.v": r""" -- 2.30.2