summaryrefslogtreecommitdiff
path: root/rola-devtools/scripts/build.py
blob: c63ca231c1d6ad7a4dc0c241779f752094b83f7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3

import shutil
import subprocess
import sys
from pathlib import Path

script_dir = Path(__file__).resolve().parent
root_dir = script_dir.parent.parent


def get_exe_names():
    """Return the list of executable file names to copy (with or without .exe suffix)."""
    return [
        "rola",
    ]


steps = [
    ("cargo check --workspace", [
        "cargo", "check", "--workspace",
    ]),
    ("cargo clippy --workspace -- -D warnings", [
        "cargo", "clippy", "--workspace", "--", "-D", "warnings",
    ]),
    ("cargo build --workspace --release", [
        "cargo", "build", "--workspace", "--release",
    ]),
    ("dotnet restore", [
        "dotnet", "restore", "rola-desktop.sln",
    ]),
    ("dotnet build", [
        "dotnet", "build", "rola-desktop.sln", "--nologo",
    ]),
]

ok = True
for label, cmd in steps:
    print(f"\nSTEP - \"{label}\": ", flush=True)
    result = subprocess.run(cmd, cwd=root_dir)
    if result.returncode != 0:
        print(f"  [FAILED] Failed (exit code {result.returncode})", flush=True)
        ok = False
        break
    print(f"  [SUCCESS] Passed", flush=True)

if ok:
    print(f"\nSTEP - \"Copy executables to .temp/bin\": ", flush=True)
    src_dir = root_dir / ".temp" / "target" / "release"
    dst_dir = root_dir / ".temp" / "bin"
    dst_dir.mkdir(parents=True, exist_ok=True)
    all_ok = True
    for exe_name in get_exe_names():
        candidates = []
        for suffix in ("", ".exe"):
            p = src_dir / f"{exe_name}{suffix}"
            if p.is_file():
                candidates.append(p)
        if not candidates:
            print(f"  [FAILED] Executable '{exe_name}' not found in {src_dir}", flush=True)
            all_ok = False
            continue
        for p in candidates:
            dst_path = dst_dir / p.name
            try:
                shutil.copy2(p, dst_path)
                print(f"  [SUCCESS] Copied {p.name} -> {dst_path}", flush=True)
            except Exception as e:
                print(f"  [FAILED] Failed to copy {p.name}: {e}", flush=True)
                all_ok = False
    if not all_ok:
        ok = False

sys.exit(0 if ok else 1)