Add project configuration and build tools

- Introduced new scripts for project generation and synthesis (dodo.py, generate_prj.py, generate_scr.py, run_xst.py).
- Implemented configuration parsing for VHDL sources and project settings (config.py).
- Added default configuration values (defaults.py).
- Updated .gitignore to include additional file types.
- Created test cases for project generation and configuration parsing (test_generate_prj.py, test_generate_scr.py, test_project_cfg.py).
This commit is contained in:
2025-04-20 11:32:37 +00:00
parent 5d4cd3e315
commit 2fce367686
15 changed files with 530 additions and 1 deletions

14
tasks/generate_prj.py Normal file
View File

@@ -0,0 +1,14 @@
import os
from tools.config import get_vhdl_sources_and_tests
from tools.paths import REL_FROM_WORKING_TO_ROOT as REL_ROOT, ROOT, WORKING
from pathlib import Path
def generate_prj(prj_path: Path, *_):
sources, _ = get_vhdl_sources_and_tests()
prj_path.parent.mkdir(parents=True, exist_ok=True)
with prj_path.open("w", encoding="utf-8") as f:
for libname, files in sources.items():
for file in files:
rel_path = os.path.relpath(ROOT / file, WORKING)
f.write(f"vhdl {libname} {rel_path}\n")

33
tasks/generate_scr.py Normal file
View File

@@ -0,0 +1,33 @@
from tools.config import parse_project_cfg
from pathlib import Path
def generate_scr(scr_path: Path, cfg_path: Path):
cfg = parse_project_cfg(cfg_path)
project = cfg["PROJECT"]
top = cfg.get("TOPLEVEL", project)
target_part = cfg["TARGET_PART"]
xst_opts = cfg.get("XST_OPTS", "")
# SCR-Datei vollständig in einer Zeile, wie im Makefile
scr_parts = [
"run",
f"-ifn {project}.prj",
f"-ofn {project}.ngc",
"-ifmt mixed",
]
# Optional: Optionen aus XST_OPTS hinzufügen
if xst_opts.strip():
scr_parts += xst_opts.strip().split()
scr_parts += [
f"-top {top}",
"-ofmt NGC",
f"-p {target_part}",
]
scr_line = " ".join(scr_parts).replace("\n", " ").replace("\r", " ")
scr_path.parent.mkdir(parents=True, exist_ok=True)
scr_path.write_text(scr_line, encoding="utf-8")

32
tasks/run_xst.py Normal file
View File

@@ -0,0 +1,32 @@
import subprocess
from tools.paths import WORKING, REPORTS, PROJECT_CFG
from tools.config import parse_project_cfg
from tools.defaults import with_defaults
from pathlib import Path
def run_xst():
cfg = with_defaults(parse_project_cfg(PROJECT_CFG))
project = cfg["PROJECT"]
scr_file = f"{project}.scr"
scr_path = WORKING / scr_file
xilinx_path = Path(cfg["XILINX"])
xilinx_platform = "lin64" # TODO: Optional dynamisch machen
xst_exe = xilinx_path / "bin" / xilinx_platform / "xst"
common_opts = cfg.get("COMMON_OPTS", "")
if not xst_exe.exists():
raise FileNotFoundError(f"xst executable not found at {xst_exe}")
if not scr_path.exists():
raise FileNotFoundError(f"SCR file not found: {scr_path}")
print(f"\n============ Running XST ============\n")
print(f"> {xst_exe} {common_opts} -ifn {scr_file}\n")
subprocess.run(
[str(xst_exe), *common_opts.split(), "-ifn", scr_file],
cwd=WORKING,
check=True
)