|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
|
import os
|
|
import os
|
|
|
import pty
|
|
import pty
|
|
|
import select
|
|
import select
|
|
|
|
|
+import shutil
|
|
|
import socket
|
|
import socket
|
|
|
import subprocess
|
|
import subprocess
|
|
|
import sys
|
|
import sys
|
|
@@ -41,6 +42,10 @@ def _cad_root() -> Path | None:
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _system_cad_available() -> bool:
|
|
|
|
|
+ return all(shutil.which(tool) for tool in ("iverilog", "vvp"))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _python_libdir(python: Path) -> str:
|
|
def _python_libdir(python: Path) -> str:
|
|
|
r = subprocess.run(
|
|
r = subprocess.run(
|
|
|
[str(python), "-c", "import sysconfig; print(sysconfig.get_config_var('LIBDIR') or '')"],
|
|
[str(python), "-c", "import sysconfig; print(sysconfig.get_config_var('LIBDIR') or '')"],
|
|
@@ -53,6 +58,25 @@ def _python_libdir(python: Path) -> str:
|
|
|
return (r.stdout or "").strip()
|
|
return (r.stdout or "").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _python_library(python: Path) -> str:
|
|
|
|
|
+ r = subprocess.run(
|
|
|
|
|
+ [
|
|
|
|
|
+ str(python),
|
|
|
|
|
+ "-c",
|
|
|
|
|
+ "import pathlib,sysconfig; "
|
|
|
|
|
+ "print(pathlib.Path(sysconfig.get_config_var('LIBDIR') or '') / "
|
|
|
|
|
+ "(sysconfig.get_config_var('LDLIBRARY') or ''))",
|
|
|
|
|
+ ],
|
|
|
|
|
+ stdout=subprocess.PIPE,
|
|
|
|
|
+ stderr=subprocess.DEVNULL,
|
|
|
|
|
+ text=True,
|
|
|
|
|
+ timeout=10,
|
|
|
|
|
+ env={k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON},
|
|
|
|
|
+ )
|
|
|
|
|
+ candidate = Path((r.stdout or "").strip())
|
|
|
|
|
+ return str(candidate) if candidate.is_file() else ""
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _write_clean_cad_shims(shim: Path, cad: Path, extra_libs: list[str] | None = None) -> None:
|
|
def _write_clean_cad_shims(shim: Path, cad: Path, extra_libs: list[str] | None = None) -> None:
|
|
|
"""Call libexec iverilog/vvp without the OSS CAD vvp wrapper's PYTHONEXECUTABLE poison."""
|
|
"""Call libexec iverilog/vvp without the OSS CAD vvp wrapper's PYTHONEXECUTABLE poison."""
|
|
|
shim.mkdir(parents=True, exist_ok=True)
|
|
shim.mkdir(parents=True, exist_ok=True)
|
|
@@ -79,6 +103,12 @@ def _write_clean_cad_shims(shim: Path, cad: Path, extra_libs: list[str] | None =
|
|
|
|
|
|
|
|
|
|
|
|
|
def _select_cocotb_python() -> Path | None:
|
|
def _select_cocotb_python() -> Path | None:
|
|
|
|
|
+ probe = """import cocotb
|
|
|
|
|
+try:
|
|
|
|
|
+ import cocotb_tools.runner
|
|
|
|
|
+except ModuleNotFoundError:
|
|
|
|
|
+ import cocotb.runner
|
|
|
|
|
+"""
|
|
|
candidates = [
|
|
candidates = [
|
|
|
Path(os.environ.get("PROD2U_P4_COCOTB_PYTHON", "")),
|
|
Path(os.environ.get("PROD2U_P4_COCOTB_PYTHON", "")),
|
|
|
Path("/opt/hth-cocotb312/bin/python"),
|
|
Path("/opt/hth-cocotb312/bin/python"),
|
|
@@ -91,7 +121,7 @@ def _select_cocotb_python() -> Path | None:
|
|
|
if not cand.is_file():
|
|
if not cand.is_file():
|
|
|
continue
|
|
continue
|
|
|
r = subprocess.run(
|
|
r = subprocess.run(
|
|
|
- [str(cand), "-B", "-c", "import cocotb, cocotb_tools"],
|
|
|
|
|
|
|
+ [str(cand), "-B", "-c", probe],
|
|
|
stdout=subprocess.DEVNULL,
|
|
stdout=subprocess.DEVNULL,
|
|
|
stderr=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL,
|
|
|
timeout=20,
|
|
timeout=20,
|
|
@@ -124,14 +154,21 @@ def _sdk_python() -> Path:
|
|
|
return Path(sys.executable)
|
|
return Path(sys.executable)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _shim_dir(build: Path, python: Path, cad: Path) -> Path:
|
|
|
|
|
|
|
+def _shim_dir(build: Path, python: Path, cad: Path | None) -> Path:
|
|
|
shim = build / "path-shim"
|
|
shim = build / "path-shim"
|
|
|
- extra = []
|
|
|
|
|
- pydir = _python_libdir(python)
|
|
|
|
|
- if pydir:
|
|
|
|
|
- extra.append(pydir)
|
|
|
|
|
- extra.append("/opt/python-3.12/lib")
|
|
|
|
|
- _write_clean_cad_shims(shim, cad, extra)
|
|
|
|
|
|
|
+ if cad is not None:
|
|
|
|
|
+ extra = []
|
|
|
|
|
+ pydir = _python_libdir(python)
|
|
|
|
|
+ if pydir:
|
|
|
|
|
+ extra.append(pydir)
|
|
|
|
|
+ extra.append("/opt/python-3.12/lib")
|
|
|
|
|
+ _write_clean_cad_shims(shim, cad, extra)
|
|
|
|
|
+ else:
|
|
|
|
|
+ shim.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ for name in ("iverilog", "vvp"):
|
|
|
|
|
+ resolved = shutil.which(name)
|
|
|
|
|
+ if resolved:
|
|
|
|
|
+ (shim / name).symlink_to(resolved)
|
|
|
for name in ("python", "python3"):
|
|
for name in ("python", "python3"):
|
|
|
path = shim / name
|
|
path = shim / name
|
|
|
if path.exists() or path.is_symlink():
|
|
if path.exists() or path.is_symlink():
|
|
@@ -535,7 +572,10 @@ asyncio.run(main())
|
|
|
|
|
|
|
|
def _run_sim_child() -> int:
|
|
def _run_sim_child() -> int:
|
|
|
py = Path(os.environ["PYGPI_PYTHON_BIN"])
|
|
py = Path(os.environ["PYGPI_PYTHON_BIN"])
|
|
|
- from cocotb_tools.runner import get_runner
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ from cocotb_tools.runner import get_runner
|
|
|
|
|
+ except ModuleNotFoundError:
|
|
|
|
|
+ from cocotb.runner import get_runner
|
|
|
|
|
|
|
|
uart_top, hdl_top, clks = _uart_choice()
|
|
uart_top, hdl_top, clks = _uart_choice()
|
|
|
runner = get_runner("icarus")
|
|
runner = get_runner("icarus")
|
|
@@ -582,6 +622,7 @@ def main() -> int:
|
|
|
|
|
|
|
|
skip = "--skip-missing" in sys.argv
|
|
skip = "--skip-missing" in sys.argv
|
|
|
cad = _cad_root()
|
|
cad = _cad_root()
|
|
|
|
|
+ cad_available = cad is not None or _system_cad_available()
|
|
|
py = _select_cocotb_python()
|
|
py = _select_cocotb_python()
|
|
|
uart_top, hdl_top, clks = _uart_choice()
|
|
uart_top, hdl_top, clks = _uart_choice()
|
|
|
try:
|
|
try:
|
|
@@ -593,9 +634,11 @@ def main() -> int:
|
|
|
return 2
|
|
return 2
|
|
|
if not uart_top.is_file():
|
|
if not uart_top.is_file():
|
|
|
missing_rtl.append(str(uart_top))
|
|
missing_rtl.append(str(uart_top))
|
|
|
- if cad is None or py is None or missing_rtl:
|
|
|
|
|
|
|
+ if not cad_available or py is None or missing_rtl:
|
|
|
print("RTL-in-the-loop hthd+PTY+UART-bit: NOT RUN")
|
|
print("RTL-in-the-loop hthd+PTY+UART-bit: NOT RUN")
|
|
|
print("cad_root:", cad)
|
|
print("cad_root:", cad)
|
|
|
|
|
+ print("iverilog:", shutil.which("iverilog"))
|
|
|
|
|
+ print("vvp:", shutil.which("vvp"))
|
|
|
print("cocotb_python:", py)
|
|
print("cocotb_python:", py)
|
|
|
print("missing_rtl:", ",".join(missing_rtl) or "none")
|
|
print("missing_rtl:", ",".join(missing_rtl) or "none")
|
|
|
return 2
|
|
return 2
|
|
@@ -641,7 +684,9 @@ def main() -> int:
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
env = {k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON}
|
|
env = {k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON}
|
|
|
- libpython = os.environ.get("LIBPYTHON_LOC", "/opt/python-3.12/lib/libpython3.12.so.1.0")
|
|
|
|
|
|
|
+ libpython = os.environ.get("LIBPYTHON_LOC") or _python_library(py)
|
|
|
|
|
+ if not libpython:
|
|
|
|
|
+ libpython = "/opt/python-3.12/lib/libpython3.12.so.1.0"
|
|
|
env["PATH"] = os.pathsep.join([str(py.parent), str(shim), "/usr/bin", "/bin"])
|
|
env["PATH"] = os.pathsep.join([str(py.parent), str(shim), "/usr/bin", "/bin"])
|
|
|
env["LD_LIBRARY_PATH"] = "/opt/python-3.12/lib" + os.pathsep + env.get("LD_LIBRARY_PATH", "")
|
|
env["LD_LIBRARY_PATH"] = "/opt/python-3.12/lib" + os.pathsep + env.get("LD_LIBRARY_PATH", "")
|
|
|
env["PYTHONPATH"] = str(HERE) + os.pathsep + str(RTL_REPO)
|
|
env["PYTHONPATH"] = str(HERE) + os.pathsep + str(RTL_REPO)
|