From 5151b440b819ee8641805e5ef4318a23e9b13bd1 Mon Sep 17 00:00:00 2001 From: Diego Migotto Date: Sun, 1 Nov 2026 13:02:41 -0300 Subject: [PATCH] embed.py: from dasmig-core (dasmig/dasmig-core#11) The --files option, which embeds only the named files of a tier (country-generator 3.3.0 uses it for its second compiled-in part). Tooling only: the compiled-in data this library generates is unchanged. Co-Authored-By: Claude Opus 5.5 --- scripts/embed.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/embed.py b/scripts/embed.py index 52a9519..17b94cc 100644 --- a/scripts/embed.py +++ b/scripts/embed.py @@ -17,10 +17,12 @@ Usage: python embed.py RESOURCES_DIR --tier lite --name biodatagen \ - --output dasmig/biodatagen_data.hpp [--include core.hpp] [--chunk-bytes 16000] + --output dasmig/biodatagen_data.hpp [--include core.hpp] [--chunk-bytes 16000] \ + [--files a.tsv b.tsv] Every file below RESOURCES_DIR// is embedded, in sorted order, under -the path "/". +the path "/"; with --files, only those files, so a +library can split its tables between headers behind separate macros. """ import argparse @@ -89,11 +91,17 @@ def literal_pieces(chunk: bytes): return pieces -def generate(resources: Path, tier: str, name: str, include: str, chunk_bytes: int) -> str: +def generate(resources: Path, tier: str, name: str, include: str, chunk_bytes: int, only=None) -> str: root = resources / tier if not root.is_dir(): raise SystemExit(f"embed.py: {root} is not a directory") - files = sorted(p for p in root.rglob("*") if p.is_file()) + if only: + missing = [f for f in only if not (root / f).is_file()] + if missing: + raise SystemExit(f"embed.py: not below {root}: {', '.join(missing)}") + files = sorted(root / f for f in only) + else: + files = sorted(p for p in root.rglob("*") if p.is_file()) if not files: raise SystemExit(f"embed.py: no files below {root}") @@ -149,10 +157,11 @@ def main(argv=None): parser.add_argument("--output", type=Path, required=True, help="header to write") parser.add_argument("--include", default="core.hpp", help="how the header includes the core") parser.add_argument("--chunk-bytes", type=int, default=16000, help="bytes per chunk (default 16000)") + parser.add_argument("--files", nargs="+", help="embed only these files of the tier (default: all)") args = parser.parse_args(argv) if not args.name.isidentifier(): raise SystemExit("embed.py: --name must be a C++ identifier") - text = generate(args.resources, args.tier, args.name, args.include, args.chunk_bytes) + text = generate(args.resources, args.tier, args.name, args.include, args.chunk_bytes, args.files) args.output.write_text(text, encoding="ascii", newline="\n") print(f"wrote {args.output} ({len(text)} bytes)")