42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Generate the C X-macro list from the read-only JSON manifest."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def render(manifest_path: Path) -> str:
|
|
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
symbols = manifest["symbols"]
|
|
lines = ["/* Generated from manifests/ps5_gnm_symbols.json. Do not edit. */"]
|
|
lines.extend(f'CHIMERA_GNM_SYMBOL("{entry["name"]}")' for entry in symbols)
|
|
return "\n".join(lines) + "\n"
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--manifest", type=Path, required=True)
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
parser.add_argument("--check", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
expected = render(args.manifest)
|
|
if args.check:
|
|
if not args.output.exists() or args.output.read_text(encoding="utf-8") != expected:
|
|
print(f"stale generated file: {args.output}")
|
|
return 1
|
|
print(f"generated file is current: {args.output}")
|
|
return 0
|
|
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(expected, encoding="utf-8", newline="\n")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|