_toolchain: new module, for injecting dependencies in e.g. Nix.
This commit is contained in:
parent
2168ff512b
commit
b14f5572d8
13
nmigen/_toolchain.py
Normal file
13
nmigen/_toolchain.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["get_tool"]
|
||||||
|
|
||||||
|
|
||||||
|
def get_tool(name):
|
||||||
|
return os.environ.get(name.upper().replace("-", "_"), overrides.get(name, name))
|
||||||
|
|
||||||
|
|
||||||
|
# Packages for systems like Nix can inject full paths to certain tools by adding them in
|
||||||
|
# this dictionary, e.g. ``overrides = {"yosys": "/full/path/to/yosys"}``.
|
||||||
|
overrides = {}
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from .._toolchain import *
|
||||||
from . import rtlil
|
from . import rtlil
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,15 +14,18 @@ class YosysError(Exception):
|
||||||
|
|
||||||
|
|
||||||
def _yosys_version():
|
def _yosys_version():
|
||||||
|
yosys_path = get_tool("yosys")
|
||||||
try:
|
try:
|
||||||
version = subprocess.check_output([os.getenv("YOSYS", "yosys"), "-V"], encoding="utf-8")
|
version = subprocess.check_output([yosys_path, "-V"], encoding="utf-8")
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
if os.getenv("YOSYS"):
|
if os.getenv("YOSYS"):
|
||||||
raise YosysError("Could not find Yosys in {} as specified via the YOSYS environment "
|
raise YosysError("Could not find Yosys in {} as specified via the YOSYS environment "
|
||||||
"variable".format(os.getenv("YOSYS"))) from e
|
"variable".format(os.getenv("YOSYS"))) from e
|
||||||
else:
|
elif yosys_path == "yosys":
|
||||||
raise YosysError("Could not find Yosys in PATH. Place `yosys` in PATH or specify "
|
raise YosysError("Could not find Yosys in PATH. Place `yosys` in PATH or specify "
|
||||||
"path explicitly via the YOSYS environment variable") from e
|
"path explicitly via the YOSYS environment variable") from e
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
m = re.match(r"^Yosys ([\d.]+)(?:\+(\d+))?", version)
|
m = re.match(r"^Yosys ([\d.]+)(?:\+(\d+))?", version)
|
||||||
tag, offset = m[1], m[2] or 0
|
tag, offset = m[1], m[2] or 0
|
||||||
|
|
|
@ -6,6 +6,7 @@ import re
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
from .. import __version__
|
from .. import __version__
|
||||||
|
from .._toolchain import *
|
||||||
from ..hdl.ast import *
|
from ..hdl.ast import *
|
||||||
from ..hdl.cd import *
|
from ..hdl.cd import *
|
||||||
from ..hdl.dsl import *
|
from ..hdl.dsl import *
|
||||||
|
@ -263,10 +264,6 @@ class TemplatedPlatform(Platform):
|
||||||
assert False
|
assert False
|
||||||
return "\n".join(commands)
|
return "\n".join(commands)
|
||||||
|
|
||||||
def get_tool(tool):
|
|
||||||
tool_env = tool.upper().replace("-", "_")
|
|
||||||
return os.environ.get(tool_env, tool)
|
|
||||||
|
|
||||||
def get_override(var):
|
def get_override(var):
|
||||||
var_env = "NMIGEN_{}".format(var)
|
var_env = "NMIGEN_{}".format(var)
|
||||||
if var_env in os.environ:
|
if var_env in os.environ:
|
||||||
|
|
Loading…
Reference in a new issue