_yosys: add a way to retrieve Yosys data directory.
This is important for CXXRTL, since that's where its include files are located.
This commit is contained in:
parent
45c61969fc
commit
eddc397509
|
@ -3,6 +3,7 @@ import sys
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import warnings
|
import warnings
|
||||||
|
import pathlib
|
||||||
try:
|
try:
|
||||||
from importlib import metadata as importlib_metadata # py3.8+ stdlib
|
from importlib import metadata as importlib_metadata # py3.8+ stdlib
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -10,6 +11,14 @@ except ImportError:
|
||||||
import importlib_metadata # py3.7- shim
|
import importlib_metadata # py3.7- shim
|
||||||
except ImportError:
|
except ImportError:
|
||||||
importlib_metadata = None # not installed
|
importlib_metadata = None # not installed
|
||||||
|
try:
|
||||||
|
from importlib import resources as importlib_resources
|
||||||
|
try:
|
||||||
|
importlib_resources.files # py3.9+ stdlib
|
||||||
|
except AttributeError:
|
||||||
|
import importlib_resources # py3.8- shim
|
||||||
|
except ImportError:
|
||||||
|
import importlib_resources # py3.6- shim
|
||||||
|
|
||||||
from ._toolchain import has_tool, require_tool
|
from ._toolchain import has_tool, require_tool
|
||||||
|
|
||||||
|
@ -53,6 +62,17 @@ class YosysBinary:
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def data_dir(cls):
|
||||||
|
"""Get Yosys data directory.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
data_dir : pathlib.Path
|
||||||
|
Yosys data directory (also known as "datdir").
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, args, stdin=""):
|
def run(cls, args, stdin=""):
|
||||||
"""Run Yosys process.
|
"""Run Yosys process.
|
||||||
|
@ -107,6 +127,10 @@ class _BuiltinYosys(YosysBinary):
|
||||||
match = re.match(r"^(\d+)\.(\d+)(?:\.post(\d+))?", version)
|
match = re.match(r"^(\d+)\.(\d+)(?:\.post(\d+))?", version)
|
||||||
return (int(match[1]), int(match[2]), int(match[3] or 0))
|
return (int(match[1]), int(match[2]), int(match[3] or 0))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def data_dir(cls):
|
||||||
|
return importlib_resources.files(cls.YOSYS_PACKAGE) / "share"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, args, stdin="", *, ignore_warnings=False, src_loc_at=0):
|
def run(cls, args, stdin="", *, ignore_warnings=False, src_loc_at=0):
|
||||||
popen = subprocess.Popen([sys.executable, "-m", cls.YOSYS_PACKAGE, *args],
|
popen = subprocess.Popen([sys.executable, "-m", cls.YOSYS_PACKAGE, *args],
|
||||||
|
@ -129,6 +153,16 @@ class _SystemYosys(YosysBinary):
|
||||||
match = re.match(r"^Yosys (\d+)\.(\d+)(?:\+(\d+))?", version)
|
match = re.match(r"^Yosys (\d+)\.(\d+)(?:\+(\d+))?", version)
|
||||||
return (int(match[1]), int(match[2]), int(match[3] or 0))
|
return (int(match[1]), int(match[2]), int(match[3] or 0))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def data_dir(cls):
|
||||||
|
popen = subprocess.Popen([require_tool(cls.YOSYS_BINARY) + "-config", "--datdir"],
|
||||||
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
|
encoding="utf-8")
|
||||||
|
stdout, stderr = popen.communicate()
|
||||||
|
if popen.returncode:
|
||||||
|
raise YosysError(stderr.strip())
|
||||||
|
return pathlib.Path(stdout.strip())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, args, stdin="", *, ignore_warnings=False, src_loc_at=0):
|
def run(cls, args, stdin="", *, ignore_warnings=False, src_loc_at=0):
|
||||||
popen = subprocess.Popen([require_tool(cls.YOSYS_BINARY), *args],
|
popen = subprocess.Popen([require_tool(cls.YOSYS_BINARY), *args],
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -25,7 +25,8 @@ setup(
|
||||||
python_requires="~=3.6",
|
python_requires="~=3.6",
|
||||||
setup_requires=["setuptools", "setuptools_scm"],
|
setup_requires=["setuptools", "setuptools_scm"],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"importlib_metadata; python_version<'3.8'", # for nmigen._yosys
|
"importlib_metadata; python_version<'3.8'", # for nmigen._yosys
|
||||||
|
"importlib_resources; python_version<'3.9'", # for nmigen._yosys
|
||||||
"pyvcd~=0.2.0", # for nmigen.pysim
|
"pyvcd~=0.2.0", # for nmigen.pysim
|
||||||
"Jinja2~=2.11", # for nmigen.build
|
"Jinja2~=2.11", # for nmigen.build
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue