Files
git.stella-ops.org/tests/reachability/samples-public/scripts/update_manifest.py
StellaOps Bot 999e26a48e up
2025-12-13 02:22:15 +02:00

54 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""
Regenerate the public samples manifest deterministically.
Usage: python tests/reachability/samples-public/scripts/update_manifest.py
"""
from __future__ import annotations
import hashlib
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SAMPLES_ROOT = ROOT / "samples"
FILE_LIST = [
"callgraph.static.json",
"ground-truth.json",
"sbom.cdx.json",
"vex.openvex.json",
"repro.sh",
]
def sha256(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def main() -> int:
entries: list[dict] = []
for lang_dir in sorted(p for p in SAMPLES_ROOT.iterdir() if p.is_dir()):
for case_dir in sorted(p for p in lang_dir.iterdir() if p.is_dir()):
files: dict[str, str] = {}
for name in FILE_LIST:
path = case_dir / name
if not path.exists():
raise SystemExit(f"missing {path}")
files[name] = sha256(path)
entries.append(
{
"id": case_dir.name,
"language": lang_dir.name,
"files": files,
}
)
manifest_path = ROOT / "manifest.json"
manifest_path.write_text(json.dumps(entries, indent=2, sort_keys=True) + "\n")
print(f"wrote {manifest_path} ({len(entries)} entries)")
return 0
if __name__ == "__main__":
raise SystemExit(main())