kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit dbcdeb29cafba52aaf5256e95e6850b284982da9
parent e27a288d3c9368f4d151a39394fd6119ca284daf
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Mon,  1 Jun 2026 18:05:50 -0700

scripts: fail loudly on unmapped sources in gen_compile_commands

flags_for() returning None silently dropped the file from the compile
database, which is how the script drifts out of sync with the Makefile
(a new lang/ frontend or source root would vanish with zero signal).
Collect unmapped .c files under the walked roots and exit non-zero
listing them, so a new tree forces a matching flags_for() branch.

Also add -Idriver -Idriver/lib to the hosted (driver/env) flags for
exact parity with the Makefile's DRIVER_ENV_CFLAGS.

Diffstat:
Mscripts/gen_compile_commands.py | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py @@ -51,7 +51,8 @@ SDK = macos_sdk_path() if sys.platform == "darwin" else None HOSTED = ["-std=c11"] if SDK: HOSTED += ["-isysroot", SDK] -HOSTED += ["-D_XOPEN_SOURCE=600", "-D_DARWIN_C_SOURCE=1", "-Iinclude", "-Ilang"] +HOSTED += ["-D_XOPEN_SOURCE=600", "-D_DARWIN_C_SOURCE=1", + "-Iinclude", "-Ilang", "-Idriver", "-Idriver/lib"] # rt/lib/*.c: freestanding runtime, its own include layout (RT_LIB_INCS + the # lp64_le ABI headers for a 64-bit host). cfree compiles these per-target; this @@ -88,6 +89,7 @@ def flags_for(rel): def main(): roots = ["src", "lang", "driver", "rt/lib"] entries = [] + unmapped = [] for root in roots: base = os.path.join(REPO, root) for dirpath, _dirs, files in os.walk(base): @@ -98,6 +100,13 @@ def main(): rel = os.path.relpath(abspath, REPO) flags = flags_for(rel) if flags is None: + # Every .c under the walked roots must map to a flag set. + # A None here means a new source tree (e.g. a new lang/ + # frontend or source root) was added without a matching + # branch in flags_for(). Fail loudly rather than silently + # dropping the file from the database -- silent drops are + # how this script drifts out of sync with the Makefile. + unmapped.append(rel) continue args = ["clang"] + flags + ["-c", rel, "-o", "/dev/null"] entries.append({ @@ -105,6 +114,14 @@ def main(): "file": abspath, "arguments": args, }) + if unmapped: + sys.stderr.write( + "error: %d source file(s) under the walked roots have no flag " + "mapping in flags_for(); add a branch (or exclude them) so the " + "compile database stays in sync with the Makefile:\n" % len(unmapped)) + for rel in sorted(unmapped): + sys.stderr.write(" %s\n" % rel) + sys.exit(1) entries.sort(key=lambda e: e["file"]) out_dir = os.path.join(REPO, "build") os.makedirs(out_dir, exist_ok=True)