22 lines
946 B
Python
22 lines
946 B
Python
#!/usr/bin/env python3
|
|
"""Embed declaration sources verbatim; KIR remains their only parser."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("output", type=Path)
|
|
args = parser.parse_args()
|
|
root = Path(__file__).resolve().parents[1]
|
|
sources = sorted((root / "runtime").glob("*_props.kry"))
|
|
lines = ["/* Generated by scripts/embed-runtime-declarations.py. DO NOT EDIT. */",
|
|
"static const struct { const char *path; const char *source; } runtime_sources[] = {"]
|
|
for source in sources:
|
|
lines.append(" {" + json.dumps(source.relative_to(root).as_posix()) + ",")
|
|
lines.extend(" " + json.dumps(line, ensure_ascii=False)
|
|
for line in source.read_text().splitlines(keepends=True))
|
|
lines.append(" },")
|
|
lines.append("};")
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text("\n".join(lines) + "\n")
|