60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Run the configured C/C++ build and tests once: python scripts/execute.py."""
|
|
|
|
import argparse
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
from msvc_harness.adapters.base import AdapterError
|
|
from msvc_harness.adapters.cmake import CMakeAdapter
|
|
from msvc_harness.adapters.msbuild import MSBuildAdapter
|
|
from msvc_harness.config import ConfigError, load_config
|
|
from msvc_harness.discovery import DiscoveryError, discover_project
|
|
from msvc_harness.models import ProjectKind
|
|
from msvc_harness.process import ValidationFailure, execute_plan
|
|
from msvc_harness.toolchain import ToolchainError, discover_toolchain
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def run_validations(root: Path) -> int:
|
|
deadline = time.monotonic() + 1800
|
|
try:
|
|
config = load_config(root)
|
|
selection = discover_project(root, config).selection
|
|
if selection is None:
|
|
print("not configured: no CMake or MSBuild project found", file=sys.stderr)
|
|
return 2
|
|
tools = discover_toolchain(selection.kind, deadline=deadline)
|
|
adapter = CMakeAdapter() if selection.kind is ProjectKind.CMAKE else MSBuildAdapter()
|
|
plan = adapter.create_plan(root, selection, config, tools)
|
|
results = execute_plan(plan, root, deadline=deadline)
|
|
except (ConfigError, DiscoveryError, ToolchainError, AdapterError, ValidationFailure, OSError) as exc:
|
|
print(str(exc), file=sys.stderr)
|
|
return 1
|
|
|
|
for result in results:
|
|
print(f"{result.command.stage}: argv={list(result.command.argv)!r}; "
|
|
f"cwd={str(result.command.cwd)!r}; exit {result.returncode}")
|
|
if result.command.stage == "test":
|
|
output = (result.stdout + "\n" + result.stderr).strip()
|
|
tail = "\n".join(output.splitlines()[-8:])[-2000:]
|
|
if tail != output:
|
|
print("[test output tail]")
|
|
if tail:
|
|
print(tail)
|
|
print(f"Validation passed ({len(results)} commands).")
|
|
return 0
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.parse_args(argv)
|
|
return run_validations(ROOT)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|