92 lines
2.7 KiB
Python
92 lines
2.7 KiB
Python
# Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
|
# Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import subprocess
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from rich.table import Table
|
|
from rich.console import Console
|
|
|
|
from neoecu.commands import build
|
|
from neoecu.common import load_config
|
|
|
|
|
|
def get_env(var: str) -> str | None:
|
|
return os.environ.get(var)
|
|
|
|
|
|
def run_cmd(cmd: list[str], cwd: Path | None = None) -> bool:
|
|
result = subprocess.run(cmd, cwd=cwd)
|
|
return result.returncode == 0
|
|
|
|
|
|
def run(root_path: Path):
|
|
console = Console()
|
|
|
|
ok_str = "[green]OK[/green]"
|
|
fail_str = "[red]FAILED[/red]"
|
|
|
|
print("Initializing project")
|
|
|
|
table = Table()
|
|
table.add_column("Step")
|
|
table.add_column("Status")
|
|
|
|
results: list[bool] = []
|
|
|
|
# Step 1 — Install west
|
|
west_ok = run_cmd(["uv", "pip", "install", "west"])
|
|
table.add_row("Install west", ok_str if west_ok else fail_str)
|
|
results.append(west_ok)
|
|
|
|
# Step 2 — Zephyr requirements
|
|
requirements = get_env("ZEPHYR_BASE")
|
|
if requirements is None:
|
|
table.add_row("Zephyr requirements", "[red]ZEPHYR_BASE not set[/red]")
|
|
console.print(table)
|
|
sys.exit(1)
|
|
|
|
requirements_path = Path(requirements) / "scripts" / "requirements.txt"
|
|
|
|
deps_ok = run_cmd(["uv", "pip", "install", "-r", str(requirements_path)])
|
|
table.add_row("Install Zephyr deps", ok_str if deps_ok else fail_str)
|
|
results.append(deps_ok)
|
|
|
|
# Step 3 — Load config
|
|
config = load_config(root_path)
|
|
m7_root = root_path / config["build"]["m7_dir"]
|
|
m4_root = root_path / config["build"]["m4_dir"]
|
|
|
|
# Step 4 — CMake Debug Init
|
|
debug_ok = run_cmd(["cmake", "--preset", "Debug"], cwd=m7_root)
|
|
table.add_row("CMake Debug Init", ok_str if debug_ok else fail_str)
|
|
results.append(debug_ok)
|
|
|
|
# Step 5 — CMake Release Init
|
|
release_ok = run_cmd(["cmake", "--preset", "Release"], cwd=m7_root)
|
|
table.add_row("CMake Release Init", ok_str if release_ok else fail_str)
|
|
results.append(release_ok)
|
|
|
|
# Step 6 - CMake Debug Build
|
|
build_ok = run_cmd(["cmake", "--build", "--preset", "Debug", "--clean-first", "--verbose"], cwd=m7_root)
|
|
table.add_row("CMake Debug Build", ok_str if build_ok else fail_str)
|
|
results.append(build_ok)
|
|
|
|
# Step 7 - Zephyr Debug
|
|
zephyr_ok = run_cmd(["west", "build","-p", "always", "-b", "arduino_giga_r1/stm32h747xx/m4"], cwd=m4_root)
|
|
table.add_row("Zephyr Build", ok_str if zephyr_ok else fail_str)
|
|
results.append(zephyr_ok)
|
|
|
|
# Print results table
|
|
console.print(table)
|
|
|
|
# Final result
|
|
if all(results):
|
|
print("Init success")
|
|
else:
|
|
print("Init failed")
|
|
sys.exit(1)
|