build.plat: bypass tool detection if NMIGEN_*_env is set.
authorwhitequark <whitequark@whitequark.org>
Thu, 12 Sep 2019 21:56:48 +0000 (21:56 +0000)
committerwhitequark <whitequark@whitequark.org>
Thu, 12 Sep 2019 21:56:48 +0000 (21:56 +0000)
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
nmigen/vendor/lattice_ecp5.py
nmigen/vendor/xilinx_spartan_3_6.py

index c8e50584fb394b005ff2aa931b9d89b9e8a85169..1ad399915a263aea08a64fd1d9d2276c6d244fe5 100644 (file)
@@ -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")}}
         """,
     }
index db4ac0669327f98108d50f650953390060e215d4..c02e370203614c4eb2e7e0ac6e6dfa8b00f0fd56 100644 (file)
@@ -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")}}
         """,
index c4c18ceffafaa2f1a2ea6d8fdde40fbc1a590271..00d6831da55d6708b72d03119fbf596e817157ab 100644 (file)
@@ -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"""