### 下线 hosted runner - .gitea/workflows、.github/workflows 归档到 docs/ci-templates/(仅自备 runner 可选启用,不作为门禁);活跃 workflow 目录移除; - 新增 tools/vde_local_check.py:--quick(构建+快速 ctest)、--full(全量 ctest)、--module、--wp-check、--build-dir/--no-configure/--jobs/--timeout; 日志/summary 落 build-local-check/<timestamp>/;实测 quick 168/168、full 7475/7475、wp-check PASS; - testing/reference 76/cross-platform 文档改为本地验证 + verifier 门禁; ### 拉取式任务计划 - 根 NEXT_STEPS.md:10 分钟上手/优先队列/T1–T8 下一步目标表/回报约定; - docs/planning/team-briefs/T1..T8.md(使命/边界/下一步/验证/交接); - WP 工具新增 --next/--team-plan/--export-all,非法 --status RC=2;WP-P4-19(1.0.81,Delivered),统计 41=29+12; - issue/PR/流程/多团队文档验证证据改为 local check + verifier; ### 工程 - 版本 1.0.81;全量构建 0 error(353 targets);全量 ctest 7570 注册、7475/7475 PASS(0 failed,25 skipped,221.94s)。
626 lines
21 KiB
Python
626 lines
21 KiB
Python
#!/usr/bin/env python3
|
||
"""VDE 本地验证协议(无托管 runner)。
|
||
|
||
在没有 hosted CI/runner 的环境中,用本脚本完成可复现在本地配置/构建/测试,
|
||
并把 PASS/FAIL 摘要与完整日志写入 build-local-check/<timestamp>/,随 PR/报告提交。
|
||
|
||
用法(在仓库根目录)::
|
||
|
||
python tools/vde_local_check.py --quick
|
||
python tools/vde_local_check.py --full
|
||
python tools/vde_local_check.py --module brep --ctest-regex "Brep|test_brep"
|
||
python tools/vde_local_check.py --wp-check
|
||
python tools/vde_local_check.py --quick --no-configure --build-dir build-fb-123
|
||
|
||
退出码:0 PASS,1 FAIL(构建/测试/校验失败),2 用法错误或环境缺失。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import argparse
|
||
import datetime as _dt
|
||
import json
|
||
import os
|
||
import re
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
import time
|
||
from dataclasses import dataclass, field
|
||
from pathlib import Path
|
||
from typing import Optional
|
||
|
||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||
DEFAULT_LOG_ROOT = REPO_ROOT / "build-local-check"
|
||
DEFAULT_BUILD_DIR = DEFAULT_LOG_ROOT / "build"
|
||
|
||
# 快速子集:架构守卫 + 插件/工具(ABI/索引/吊销/scaffold/mesher)+ 插件 SDK 包 +
|
||
# 模块包/版本;排除 benchmark/fuzz 等耗时项。
|
||
QUICK_CTEST_REGEX = (
|
||
r"VDE_DependencyDirection_Guard|VDE_KernelAggregateBoundary|"
|
||
r"VDE_Plugin|VDE_PluginTool|Plugin|"
|
||
r"VDE_PluginSdkConsumerSmoke|ModulePackage|module_package|"
|
||
r"Version|test_version"
|
||
)
|
||
QUICK_CTEST_EXCLUDE = r"Benchmark|Bench|Fuzz|fuzz"
|
||
FULL_CTEST_EXCLUDE = r"Benchmark|Bench"
|
||
|
||
CONFIGURE_BASE_OPTIONS = [
|
||
"-DCMAKE_BUILD_TYPE=Release",
|
||
"-DBUILD_TESTS=ON",
|
||
"-DBUILD_EXAMPLES=OFF",
|
||
"-DBUILD_BENCHMARKS=OFF",
|
||
"-DVDE_BUILD_PYTHON=OFF",
|
||
"-DVDE_BUILD_CPP_SHARED=OFF",
|
||
]
|
||
|
||
|
||
@dataclass
|
||
class Step:
|
||
name: str
|
||
status: str = "PENDING" # PASS / FAIL / SKIP
|
||
seconds: float = 0.0
|
||
command: list[str] = field(default_factory=list)
|
||
returncode: Optional[int] = None
|
||
log: str = ""
|
||
note: str = ""
|
||
details: dict = field(default_factory=dict)
|
||
|
||
|
||
class LocalCheckError(Exception):
|
||
"""用法/环境错误(退出码 2)。"""
|
||
|
||
|
||
def _timestamp() -> str:
|
||
return _dt.datetime.now().strftime("%Y%m%d-%H%M%S")
|
||
|
||
|
||
def _unique_dir(parent: Path, name: str) -> Path:
|
||
candidate = parent / name
|
||
n = 2
|
||
while candidate.exists():
|
||
candidate = parent / f"{name}-{n}"
|
||
n += 1
|
||
candidate.mkdir(parents=True, exist_ok=False)
|
||
return candidate
|
||
|
||
|
||
def _tail(text: str, lines: int = 60) -> str:
|
||
rows = text.splitlines()
|
||
return "\n".join(rows[-lines:])
|
||
|
||
|
||
def _print_step(step: Step) -> None:
|
||
mark = {"PASS": "PASS", "FAIL": "FAIL", "SKIP": "SKIP"}[step.status]
|
||
print(f"[{mark}] {step.name} ({step.seconds:.1f}s) log={step.log}")
|
||
if step.status == "FAIL" and step.note:
|
||
print(" " + step.note.replace("\n", "\n "))
|
||
elif step.status == "SKIP" and step.note:
|
||
print(f" {step.note}")
|
||
|
||
|
||
def _run_command(
|
||
step: Step,
|
||
cmd: list[str],
|
||
log_path: Path,
|
||
timeout: Optional[float],
|
||
cwd: Path = REPO_ROOT,
|
||
) -> tuple[int, str]:
|
||
"""执行命令,完整输出写入日志;返回 (returncode, output)。"""
|
||
step.command = cmd
|
||
step.log = str(log_path)
|
||
print("[run] " + " ".join(cmd))
|
||
started = time.monotonic()
|
||
try:
|
||
proc = subprocess.run(
|
||
cmd,
|
||
cwd=str(cwd),
|
||
stdout=subprocess.PIPE,
|
||
stderr=subprocess.STDOUT,
|
||
text=True,
|
||
encoding="utf-8",
|
||
errors="replace",
|
||
timeout=timeout if timeout and timeout > 0 else None,
|
||
)
|
||
rc = proc.returncode
|
||
output = proc.stdout or ""
|
||
except subprocess.TimeoutExpired as exc:
|
||
rc = 124
|
||
output = (exc.stdout or "") if isinstance(exc.stdout, str) else ""
|
||
output += f"\n[timeout] command exceeded {timeout:.0f}s\n"
|
||
except FileNotFoundError as exc:
|
||
rc = 127
|
||
output = f"[error] executable not found: {exc}\n"
|
||
step.seconds = time.monotonic() - started
|
||
step.returncode = rc
|
||
log_path.write_text(output, encoding="utf-8", errors="replace")
|
||
return rc, output
|
||
|
||
|
||
def _require_tool(name: str) -> str:
|
||
path = shutil.which(name)
|
||
if not path:
|
||
raise LocalCheckError(
|
||
f"未找到 {name};请安装 CMake >= 3.20 + Ninja 并加入 PATH"
|
||
)
|
||
return path
|
||
|
||
|
||
def _fetchcontent_options() -> list[str]:
|
||
"""本地依赖存在时自动透传离线 FetchContent 参数(不联网)。"""
|
||
local = {
|
||
"JSON": REPO_ROOT / "json",
|
||
"GOOGLETEST": REPO_ROOT / "googletest",
|
||
"EIGEN3": REPO_ROOT / "eigen3",
|
||
}
|
||
flags: list[str] = []
|
||
present = 0
|
||
for name, path in local.items():
|
||
if path.is_dir():
|
||
flags.append(f"-DFETCHCONTENT_SOURCE_DIR_{name}={path}")
|
||
present += 1
|
||
if present == len(local):
|
||
flags.append("-DFETCHCONTENT_FULLY_DISCONNECTED=ON")
|
||
return flags
|
||
|
||
|
||
def _configure(
|
||
step: Step,
|
||
cmake: str,
|
||
build_dir: Path,
|
||
log_path: Path,
|
||
timeout: Optional[float],
|
||
) -> tuple[int, str]:
|
||
cmd = [cmake, "-S", str(REPO_ROOT), "-B", str(build_dir)]
|
||
if shutil.which("ninja"):
|
||
cmd.extend(["-G", "Ninja"])
|
||
else:
|
||
print("[warn] 未找到 ninja;使用 CMake 默认 generator(构建会慢很多)")
|
||
cmd.extend(CONFIGURE_BASE_OPTIONS)
|
||
cmd.extend(_fetchcontent_options())
|
||
return _run_command(step, cmd, log_path, timeout)
|
||
|
||
|
||
def _build(
|
||
step: Step,
|
||
cmake: str,
|
||
build_dir: Path,
|
||
jobs: int,
|
||
log_path: Path,
|
||
timeout: Optional[float],
|
||
target: Optional[str] = None,
|
||
) -> tuple[int, str]:
|
||
cmd = [cmake, "--build", str(build_dir), "--parallel", str(jobs)]
|
||
if target:
|
||
cmd.extend(["--target", target])
|
||
return _run_command(step, cmd, log_path, timeout)
|
||
|
||
|
||
def _find_ctest(cmake: str) -> str:
|
||
ctest = shutil.which("ctest")
|
||
if ctest:
|
||
return ctest
|
||
# WinGet/标准安装中 ctest 与 cmake 同目录
|
||
candidate = Path(cmake).with_name("ctest.exe" if os.name == "nt" else "ctest")
|
||
if candidate.exists():
|
||
return str(candidate)
|
||
raise LocalCheckError("未找到 ctest;请确认 CMake 安装完整并加入 PATH")
|
||
|
||
|
||
def _ctest_list_count(ctest: str, build_dir: Path, regex: Optional[str],
|
||
exclude: Optional[str], timeout: Optional[float]) -> Optional[int]:
|
||
cmd = [ctest, "--test-dir", str(build_dir), "-N"]
|
||
if regex:
|
||
cmd.extend(["-R", regex])
|
||
if exclude:
|
||
cmd.extend(["-E", exclude])
|
||
try:
|
||
proc = subprocess.run(
|
||
cmd, cwd=str(REPO_ROOT), stdout=subprocess.PIPE,
|
||
stderr=subprocess.STDOUT, text=True, encoding="utf-8",
|
||
errors="replace", timeout=timeout if timeout and timeout > 0 else None,
|
||
)
|
||
except (OSError, subprocess.TimeoutExpired):
|
||
return None
|
||
m = re.search(r"Total Tests:\s*(\d+)", proc.stdout or "")
|
||
return int(m.group(1)) if m else None
|
||
|
||
|
||
def _parse_ctest_summary(output: str) -> dict:
|
||
result = {"passed": None, "failed": None, "executed": None, "seconds": None}
|
||
m = re.search(r"(\d+)% tests passed,\s*(\d+) tests failed out of\s*(\d+)", output)
|
||
if m:
|
||
failed = int(m.group(2))
|
||
total = int(m.group(3))
|
||
result.update(failed=failed, executed=total, passed=total - failed)
|
||
m = re.search(r"Total Test time \(real\)\s*=\s*([0-9.]+)\s*sec", output)
|
||
if m:
|
||
result["seconds"] = float(m.group(1))
|
||
return result
|
||
|
||
|
||
def _ctest_run(
|
||
step: Step,
|
||
ctest: str,
|
||
build_dir: Path,
|
||
jobs: int,
|
||
regex: Optional[str],
|
||
exclude: Optional[str],
|
||
log_path: Path,
|
||
timeout: Optional[float],
|
||
) -> tuple[int, str]:
|
||
cmd = [
|
||
ctest,
|
||
"--test-dir", str(build_dir),
|
||
"--parallel", str(jobs),
|
||
"--output-on-failure",
|
||
]
|
||
if regex:
|
||
cmd.extend(["-R", regex])
|
||
if exclude:
|
||
cmd.extend(["-E", exclude])
|
||
return _run_command(step, cmd, log_path, timeout)
|
||
|
||
|
||
def _step_wp_check(timeout: Optional[float]) -> Step:
|
||
step = Step(name="wp-check")
|
||
wp_tool = REPO_ROOT / "tools" / "vde_work_package.py"
|
||
step.log = ""
|
||
if not wp_tool.is_file():
|
||
step.status = "SKIP"
|
||
step.note = f"未找到 {wp_tool};跳过 WP 目录校验"
|
||
return step
|
||
log_path = _CURRENT_LOG_DIR / "wp-check.log"
|
||
step.log = str(log_path)
|
||
rc, output = _run_command(
|
||
step, [sys.executable, str(wp_tool), "--check"], log_path, timeout
|
||
)
|
||
if rc == 0:
|
||
step.status = "PASS"
|
||
m = re.search(r"\[check\]\s*(\d+) work packages", output)
|
||
if m:
|
||
step.details["work_packages"] = int(m.group(1))
|
||
else:
|
||
step.status = "FAIL"
|
||
step.note = _tail(output)
|
||
_print_step(step)
|
||
return step
|
||
|
||
|
||
def _finish(
|
||
mode: str,
|
||
build_dir: Optional[Path],
|
||
log_dir: Path,
|
||
steps: list[Step],
|
||
started: float,
|
||
) -> int:
|
||
failed = [s for s in steps if s.status == "FAIL"]
|
||
skipped = [s for s in steps if s.status == "SKIP"]
|
||
overall = "FAIL" if failed else "PASS"
|
||
elapsed = time.monotonic() - started
|
||
lines = [
|
||
f"LOCAL_CHECK_{overall} mode={mode} steps={len(steps)} "
|
||
f"pass={sum(1 for s in steps if s.status == 'PASS')} "
|
||
f"fail={len(failed)} skip={len(skipped)} elapsed={elapsed:.1f}s",
|
||
f"log_dir={log_dir}",
|
||
]
|
||
if build_dir is not None:
|
||
lines.append(f"build_dir={build_dir}")
|
||
for s in steps:
|
||
detail = ""
|
||
if s.details:
|
||
detail = " " + " ".join(f"{k}={v}" for k, v in s.details.items())
|
||
lines.append(
|
||
f" - {s.name}: {s.status} {s.seconds:.1f}s rc={s.returncode}"
|
||
f"{detail} log={s.log}"
|
||
)
|
||
text = "\n".join(lines) + "\n"
|
||
(log_dir / "summary.txt").write_text(text, encoding="utf-8")
|
||
(log_dir / "summary.json").write_text(
|
||
json.dumps(
|
||
{
|
||
"mode": mode,
|
||
"result": overall,
|
||
"elapsed_seconds": round(elapsed, 1),
|
||
"build_dir": str(build_dir) if build_dir else None,
|
||
"log_dir": str(log_dir),
|
||
"steps": [
|
||
{
|
||
"name": s.name,
|
||
"status": s.status,
|
||
"seconds": round(s.seconds, 1),
|
||
"command": s.command,
|
||
"returncode": s.returncode,
|
||
"log": s.log,
|
||
"note": s.note,
|
||
"details": s.details,
|
||
}
|
||
for s in steps
|
||
],
|
||
},
|
||
ensure_ascii=False,
|
||
indent=2,
|
||
)
|
||
+ "\n",
|
||
encoding="utf-8",
|
||
)
|
||
print("")
|
||
print(text, end="")
|
||
if failed:
|
||
print("RESULT: FAIL - see logs above (attach to PR/task report)")
|
||
return 1
|
||
print("RESULT: PASS - attach summary.txt/logs to PR/task report")
|
||
return 0
|
||
|
||
|
||
def _run_build_mode(
|
||
mode: str,
|
||
build_dir: Path,
|
||
args: argparse.Namespace,
|
||
cmake: str,
|
||
ctest: str,
|
||
log_dir: Path,
|
||
started: float,
|
||
) -> int:
|
||
steps: list[Step] = []
|
||
timeout = args.timeout
|
||
jobs = args.jobs
|
||
|
||
if args.no_configure:
|
||
if not (build_dir / "CMakeCache.txt").is_file():
|
||
raise LocalCheckError(
|
||
f"--no-configure 但 {build_dir} 没有 CMakeCache.txt;请先不带该参数运行"
|
||
)
|
||
else:
|
||
step = Step(name="configure")
|
||
rc, output = _configure(step, cmake, build_dir, log_dir / "configure.log", timeout)
|
||
if rc == 0:
|
||
step.status = "PASS"
|
||
else:
|
||
step.status = "FAIL"
|
||
step.note = _tail(output)
|
||
_print_step(step)
|
||
steps.append(step)
|
||
if rc != 0:
|
||
return _finish(mode, build_dir, log_dir, steps, started)
|
||
|
||
if args.module:
|
||
name = args.module
|
||
module = name[4:] if name.startswith("vde_") else name
|
||
target = name if name.startswith("vde_") else f"vde_{module}"
|
||
step = Step(name=f"build-target:{target}")
|
||
rc, output = _build(
|
||
step, cmake, build_dir, jobs, log_dir / "build-target.log", timeout,
|
||
target=target,
|
||
)
|
||
step.status = "PASS" if rc == 0 else "FAIL"
|
||
if rc != 0:
|
||
step.note = _tail(output)
|
||
_print_step(step)
|
||
steps.append(step)
|
||
if rc != 0:
|
||
return _finish(mode, build_dir, log_dir, steps, started)
|
||
|
||
test_target = f"test_{module}"
|
||
step = Step(name=f"build-test-target:{test_target} (optional)")
|
||
rc, output = _build(
|
||
step, cmake, build_dir, jobs, log_dir / "build-test-target.log", timeout,
|
||
target=test_target,
|
||
)
|
||
if rc == 0:
|
||
step.status = "PASS"
|
||
else:
|
||
step.status = "SKIP"
|
||
step.note = f"测试可执行目标 {test_target} 不存在或未构建;ctest 可能仅运行已构建测试"
|
||
_print_step(step)
|
||
steps.append(step)
|
||
|
||
regex = args.ctest_regex or rf"(test_{re.escape(module)}|{re.escape(module)})"
|
||
ctest_step = Step(name="ctest:module")
|
||
ctest_step.details["regex"] = regex
|
||
rc, output = _ctest_run(
|
||
ctest_step, ctest, build_dir, jobs, regex, None,
|
||
log_dir / "ctest-module.log", timeout,
|
||
)
|
||
summary = _parse_ctest_summary(output)
|
||
ctest_step.details.update(
|
||
{k: v for k, v in summary.items() if v is not None}
|
||
)
|
||
if rc == 0 and summary.get("failed") in (0, None):
|
||
ctest_step.status = "PASS"
|
||
else:
|
||
ctest_step.status = "FAIL"
|
||
ctest_step.note = _tail(output)
|
||
_print_step(ctest_step)
|
||
steps.append(ctest_step)
|
||
return _finish(mode, build_dir, log_dir, steps, started)
|
||
|
||
step = Step(name="build")
|
||
rc, output = _build(step, cmake, build_dir, jobs, log_dir / "build.log", timeout)
|
||
if rc == 0:
|
||
step.status = "PASS"
|
||
else:
|
||
step.status = "FAIL"
|
||
step.note = _tail(output)
|
||
_print_step(step)
|
||
steps.append(step)
|
||
if rc != 0:
|
||
return _finish(mode, build_dir, log_dir, steps, started)
|
||
|
||
if mode == "full":
|
||
registered = _ctest_list_count(
|
||
ctest, build_dir, None, FULL_CTEST_EXCLUDE, timeout
|
||
)
|
||
ctest_step = Step(name="ctest:full")
|
||
ctest_step.details["registered"] = registered if registered is not None else "unknown"
|
||
rc, output = _ctest_run(
|
||
ctest_step, ctest, build_dir, jobs, None, FULL_CTEST_EXCLUDE,
|
||
log_dir / "ctest-full.log", timeout,
|
||
)
|
||
summary = _parse_ctest_summary(output)
|
||
ctest_step.details.update(
|
||
{k: v for k, v in summary.items() if v is not None}
|
||
)
|
||
if rc == 0 and summary.get("failed") == 0:
|
||
ctest_step.status = "PASS"
|
||
elif rc == 0 and summary.get("failed") is None:
|
||
ctest_step.status = "FAIL"
|
||
ctest_step.note = "无法解析 ctest 汇总(输出异常)"
|
||
else:
|
||
ctest_step.status = "FAIL"
|
||
ctest_step.note = _tail(output)
|
||
_print_step(ctest_step)
|
||
steps.append(ctest_step)
|
||
return _finish(mode, build_dir, log_dir, steps, started)
|
||
|
||
# quick
|
||
registered = _ctest_list_count(
|
||
ctest, build_dir, QUICK_CTEST_REGEX, QUICK_CTEST_EXCLUDE, timeout
|
||
)
|
||
ctest_step = Step(name="ctest:quick")
|
||
ctest_step.details["registered"] = registered if registered is not None else "unknown"
|
||
rc, output = _ctest_run(
|
||
ctest_step, ctest, build_dir, jobs, QUICK_CTEST_REGEX, QUICK_CTEST_EXCLUDE,
|
||
log_dir / "ctest-quick.log", timeout,
|
||
)
|
||
summary = _parse_ctest_summary(output)
|
||
ctest_step.details.update({k: v for k, v in summary.items() if v is not None})
|
||
if rc == 0 and summary.get("failed") in (0, None):
|
||
ctest_step.status = "PASS"
|
||
elif rc == 0 and summary.get("failed") is None:
|
||
ctest_step.status = "FAIL"
|
||
ctest_step.note = "无法解析 ctest 汇总(输出异常)"
|
||
else:
|
||
ctest_step.status = "FAIL"
|
||
ctest_step.note = _tail(output)
|
||
_print_step(ctest_step)
|
||
steps.append(ctest_step)
|
||
return _finish(mode, build_dir, log_dir, steps, started)
|
||
|
||
|
||
_CURRENT_LOG_DIR = DEFAULT_LOG_ROOT
|
||
|
||
|
||
def build_parser() -> argparse.ArgumentParser:
|
||
parser = argparse.ArgumentParser(
|
||
prog="vde_local_check.py",
|
||
description=(
|
||
"VDE 本地验证协议(无托管 runner):配置/构建/测试并输出 PASS/FAIL 摘要与日志。"
|
||
),
|
||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||
epilog=(
|
||
"示例:\n"
|
||
" python tools/vde_local_check.py --quick\n"
|
||
" python tools/vde_local_check.py --full\n"
|
||
" python tools/vde_local_check.py --module brep --ctest-regex \"Brep\"\n"
|
||
" python tools/vde_local_check.py --wp-check\n"
|
||
" python tools/vde_local_check.py --quick --no-configure --build-dir build-fb-123\n"
|
||
"\n日志: build-local-check/<timestamp>/(configure/build/ctest/wp-check + summary.txt/json)\n"
|
||
"退出码: 0 PASS / 1 FAIL / 2 用法或环境错误"
|
||
),
|
||
)
|
||
mode = parser.add_mutually_exclusive_group(required=True)
|
||
mode.add_argument(
|
||
"--quick", action="store_true",
|
||
help="快速验证:配置+构建+ctest 快速子集(plugin/工具/模块包/WP/版本)",
|
||
)
|
||
mode.add_argument(
|
||
"--full", action="store_true",
|
||
help="全量验证:配置+构建+全量 ctest(排除 Benchmark|Bench)",
|
||
)
|
||
mode.add_argument(
|
||
"--module", metavar="NAME",
|
||
help="模块验证:构建 vde_<name>(可带 --ctest-regex)并运行相关 ctest",
|
||
)
|
||
mode.add_argument(
|
||
"--wp-check", action="store_true",
|
||
help="只校验工作包目录(调用 tools/vde_work_package.py --check)",
|
||
)
|
||
parser.add_argument(
|
||
"--ctest-regex", metavar="REGEX",
|
||
help="配合 --module 指定 ctest 过滤正则(默认 test_<name>|<name>)",
|
||
)
|
||
parser.add_argument(
|
||
"--build-dir", metavar="DIR", default=None,
|
||
help=f"构建目录(默认 {DEFAULT_BUILD_DIR};相对路径按仓库根解析)",
|
||
)
|
||
parser.add_argument(
|
||
"--no-configure", action="store_true",
|
||
help="跳过 configure(要求 build-dir 已有 CMakeCache.txt)",
|
||
)
|
||
parser.add_argument(
|
||
"--jobs", "-j", type=int, default=max(1, os.cpu_count() or 8),
|
||
help="并行度(默认 CPU 核数)",
|
||
)
|
||
parser.add_argument(
|
||
"--timeout", type=float, default=7200.0, metavar="SEC",
|
||
help="单条命令超时秒数(默认 7200;0 = 不超时)",
|
||
)
|
||
return parser
|
||
|
||
|
||
def main(argv: Optional[list[str]] = None) -> int:
|
||
parser = build_parser()
|
||
args = parser.parse_args(argv)
|
||
if args.ctest_regex and not args.module:
|
||
parser.error("--ctest-regex 只能与 --module 一起使用")
|
||
if args.jobs < 1:
|
||
parser.error("--jobs 必须 >= 1")
|
||
if args.timeout < 0:
|
||
parser.error("--timeout 必须 >= 0")
|
||
|
||
started = time.monotonic()
|
||
DEFAULT_LOG_ROOT.mkdir(parents=True, exist_ok=True)
|
||
global _CURRENT_LOG_DIR
|
||
_CURRENT_LOG_DIR = _unique_dir(DEFAULT_LOG_ROOT, _timestamp())
|
||
log_dir = _CURRENT_LOG_DIR
|
||
print(f"[info] log_dir={log_dir}")
|
||
|
||
def _write_env(cmake: str, ctest: str) -> None:
|
||
(log_dir / "env.txt").write_text(
|
||
"\n".join(
|
||
[
|
||
f"repo={REPO_ROOT}",
|
||
f"cmake={cmake}",
|
||
f"ctest={ctest}",
|
||
f"ninja={shutil.which('ninja') or '-'}",
|
||
f"python={sys.executable} ({sys.version.split()[0]})",
|
||
f"platform={sys.platform}",
|
||
f"jobs={args.jobs}",
|
||
f"timeout={args.timeout}",
|
||
f"timestamp={_dt.datetime.now().isoformat(timespec='seconds')}",
|
||
]
|
||
) + "\n",
|
||
encoding="utf-8",
|
||
)
|
||
|
||
try:
|
||
if args.wp_check:
|
||
_write_env("-", "-")
|
||
steps = [_step_wp_check(args.timeout)]
|
||
return _finish("wp-check", None, log_dir, steps, started)
|
||
|
||
cmake = _require_tool("cmake")
|
||
ctest = _find_ctest(cmake)
|
||
_write_env(cmake, ctest)
|
||
mode = "module" if args.module else ("full" if args.full else "quick")
|
||
if args.build_dir:
|
||
build_dir = Path(args.build_dir)
|
||
if not build_dir.is_absolute():
|
||
build_dir = (REPO_ROOT / build_dir).resolve()
|
||
else:
|
||
build_dir = DEFAULT_BUILD_DIR
|
||
build_dir = build_dir.resolve()
|
||
print(f"[info] mode={mode} build_dir={build_dir}")
|
||
return _run_build_mode(mode, build_dir, args, cmake, ctest, log_dir, started)
|
||
except LocalCheckError as exc:
|
||
print(f"[error] {exc}", file=sys.stderr)
|
||
return 2
|
||
except KeyboardInterrupt:
|
||
print("\n[error] 中断", file=sys.stderr)
|
||
return 1
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|