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.
This commit is contained in:
whitequark 2019-09-12 21:56:48 +00:00
parent c8f8c09f29
commit 9ea3ff7ae2
3 changed files with 15 additions and 8 deletions

View 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")}}
""",
}

View 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")}}
""",

View 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"""