Refactors file management and enhances task tracking

Replaces duplicate file copy logic with a unified `copy_file` function to improve code reuse and maintainability. Updates step tracking across the toolchain to reflect a consistent 12-step workflow. Adds a new entry point (`xilinx_ise_all`) to streamline execution of the entire toolchain.

Improves logging by integrating enhanced console utilities for better step visualization and progress tracking.
This commit is contained in:
2025-04-26 16:18:38 +00:00
parent 90859715c4
commit 12d9f4b6c9
8 changed files with 77 additions and 49 deletions

View File

@@ -4,7 +4,7 @@ import shutil
from typing import Optional
from models.project import ProjectConfig
from models.config import DIRECTORIES
from tools.xilinx_ise.common import run_tool
from tools.xilinx_ise.common import copy_file, run_tool
def run_bitgen(project: ProjectConfig):
run_tool(
@@ -15,24 +15,15 @@ def run_bitgen(project: ProjectConfig):
"-w",
f"{project.name}.ncd",
f"{project.name}.bit"
], step_number=5, total_steps=6
], step_number=9, total_steps=12
)
def copy_bitstream_file(project: ProjectConfig):
"""
Kopiert die Bitstream-Datei (.bit) vom Build-Verzeichnis ins Output-Verzeichnis.
Args:
project (ProjectConfig): Geladene Projektkonfiguration.
"""
src_path = os.path.join(DIRECTORIES.build, f"{project.name}.bit")
dst_path = os.path.join(DIRECTORIES.copy_target, f"{project.name}.bit")
if not os.path.exists(src_path):
raise FileNotFoundError(f"Bitstream-Datei nicht gefunden: {src_path}")
os.makedirs(DIRECTORIES.copy_target, exist_ok=True)
shutil.copyfile(src_path, dst_path)
print(f"[hdlbuild] Bitstream-Datei kopiert nach {dst_path}")
copy_file(
project=project,
source_filename=f"{project.name}.bit",
destination_filename=f"{project.name}.Bitstream",
description="Bitstream File",
step_number=10, total_steps=12
)

View File

@@ -1,13 +1,10 @@
import shutil
import subprocess
import os
import threading
import time
import sys
from typing import Optional, List
from models.project import ProjectConfig
from models.config import DIRECTORIES
from utils.console_utils import ConsoleTask
from utils.console_utils import ConsoleTask, ConsoleUtils
from rich.console import Console
def run_tool(
project: ProjectConfig,
@@ -28,9 +25,6 @@ def run_tool(
if not os.path.exists(tool_executable):
raise FileNotFoundError(f"Executable nicht gefunden: {tool_executable}")
step_info = f"[{step_number}/{total_steps}] " if step_number and total_steps else ""
progress_line = f"{step_info}[hdlbuild] Starte {tool_executable_name.upper()}..."
cmd = [tool_executable]
if project.tool_options and project.tool_options.common:
@@ -43,15 +37,17 @@ def run_tool(
cmd.extend(mandatory_arguments)
task = ConsoleTask(progress_line)
task = ConsoleTask("hdlbuild", tool_executable_name.upper(), step_number, total_steps)
task.run_command(cmd, cwd=working_dir, silent=silent)
def copy_report_file(
def copy_file(
project: ProjectConfig,
source_filename: str,
destination_filename: str,
description: str = "Report"
description: str = "Report",
step_number: Optional[int] = None,
total_steps: Optional[int] = None
):
"""
Kopiert eine beliebige Report-Datei vom Build- in das Report-Verzeichnis.
@@ -71,4 +67,6 @@ def copy_report_file(
os.makedirs(DIRECTORIES.report, exist_ok=True)
shutil.copyfile(src_path, dst_path)
print(f"[hdlbuild] {description} kopiert nach {dst_path} 🗎")
util = ConsoleUtils("hdlbuild", step_number, total_steps)
util.print(f"{description} kopiert nach {dst_path}")

View File

@@ -0,0 +1,34 @@
from models.config import DIRECTORIES
from models.project import ProjectConfig
from tools.xilinx_ise.bitgen import copy_bitstream_file, run_bitgen
from tools.xilinx_ise.map import copy_map_report, run_map
from tools.xilinx_ise.ngdbuild import run_ngdbuild
from tools.xilinx_ise.par import copy_par_report, copy_pinout_report, run_par
from tools.xilinx_ise.trace import copy_trace_report, run_trace
from tools.xilinx_ise.xst import copy_synthesis_report, generate_xst_project_file, generate_xst_script_file, run_xst
def xilinx_ise_synth(project: ProjectConfig):
generate_xst_project_file(project, f"{DIRECTORIES.build}/{project.name}.prj")
generate_xst_script_file(project, f"{DIRECTORIES.build}/{project.name}.scr")
run_xst(project)
copy_synthesis_report(project)
def xilinx_ise_all(project: ProjectConfig):
xilinx_ise_synth(project)
run_ngdbuild(project)
run_map(project)
copy_map_report(project)
run_par(project)
copy_par_report(project)
copy_pinout_report(project)
run_bitgen(project)
copy_bitstream_file(project)
run_trace(project)
copy_trace_report(project)

View File

@@ -4,7 +4,7 @@ import shutil
from typing import Optional
from models.project import ProjectConfig
from models.config import DIRECTORIES
from tools.xilinx_ise.common import copy_report_file, run_tool
from tools.xilinx_ise.common import copy_file, run_tool
def run_map(project: ProjectConfig):
run_tool(
@@ -17,13 +17,14 @@ def run_map(project: ProjectConfig):
f"{project.name}.ngd",
"-o", f"{project.name}.map.ncd",
f"{project.name}.pcf"
], step_number=3, total_steps=6
], step_number=4, total_steps=12
)
def copy_map_report(project: ProjectConfig):
copy_report_file(
copy_file(
project=project,
source_filename=f"{project.name}.map.mrp",
destination_filename=f"{project.name}.MapReport",
description="Map Report"
description="Map Report",
step_number=5, total_steps=12
)

View File

@@ -15,5 +15,5 @@ def run_ngdbuild(project: ProjectConfig):
"-uc", f"{DIRECTORIES.get_relative_prefix()}{project.constraints}",
f"{project.name}.ngc",
f"{project.name}.ngd"
], step_number=2, total_steps=6
], step_number=3, total_steps=12
)

View File

@@ -4,7 +4,7 @@ import os
from typing import Optional
from models.project import ProjectConfig
from models.config import DIRECTORIES
from tools.xilinx_ise.common import copy_report_file, run_tool
from tools.xilinx_ise.common import copy_file, run_tool
def run_par(project: ProjectConfig):
run_tool(
@@ -16,21 +16,23 @@ def run_par(project: ProjectConfig):
f"{project.name}.map.ncd",
f"{project.name}.ncd",
f"{project.name}.pcf"
], step_number=4, total_steps=6
], step_number=6, total_steps=12
)
def copy_par_report(project: ProjectConfig):
copy_report_file(
copy_file(
project=project,
source_filename=f"{project.name}.par",
destination_filename=f"{project.name}.PlaceRouteReport",
description="Place & Route Report"
description="Place & Route Report",
step_number=7, total_steps=12
)
def copy_pinout_report(project: ProjectConfig):
copy_report_file(
copy_file(
project=project,
source_filename=f"{project.name}_pad.txt",
destination_filename=f"{project.name}.PinoutReport",
description="Pinout Report"
description="Pinout Report",
step_number=8, total_steps=12
)

View File

@@ -4,7 +4,7 @@ import shutil
from typing import Optional
from models.project import ProjectConfig
from models.config import DIRECTORIES
from tools.xilinx_ise.common import copy_report_file, run_tool
from tools.xilinx_ise.common import copy_file, run_tool
def run_trace(project: ProjectConfig):
run_tool(
@@ -14,13 +14,14 @@ def run_trace(project: ProjectConfig):
mandatory_arguments=[
f"{project.name}.ncd",
f"{project.name}.pcf",
], step_number=6, total_steps=6
], step_number=11, total_steps=12
)
def copy_trace_report(project: ProjectConfig):
copy_report_file(
copy_file(
project=project,
source_filename=f"{project.name}.twr",
destination_filename=f"{project.name}.TimingReport",
description="Timing Report"
description="Timing Report",
step_number=12, total_steps=12
)

View File

@@ -1,6 +1,6 @@
from typing import Optional
from models.config import DIRECTORIES
from tools.xilinx_ise.common import copy_report_file, run_tool
from tools.xilinx_ise.common import copy_file, run_tool
from utils.source_resolver import expand_sources
from models.project import ProjectConfig
import subprocess
@@ -50,13 +50,14 @@ def run_xst(project: ProjectConfig):
project=project,
tool_executable_name="xst",
mandatory_arguments=["-ifn", f"{project.name}.scr",
], step_number=1, total_steps=6
], step_number=1, total_steps=12
)
def copy_synthesis_report(project: ProjectConfig):
copy_report_file(
copy_file(
project=project,
source_filename=f"{project.name}.srp",
destination_filename=f"{project.name}.SynthesisReport",
description="Synthesebericht"
description="Synthesebericht",
step_number=2, total_steps=12
)