From a56b15320444fcfe3aabdd3768c81c733f3d776b Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sat, 29 Aug 2026 00:35:58 -0700 Subject: Bake the short git commit hash (plus -dirty suffix) into the binary and trace it at startup alongside the build timestamp. A --logfile trace could previously only be tied back to a build timestamp, not the exact source state -- distinguishing same-day rebuilds during A/B testing required diffing binaries. GIT_COMMIT is injected via GNUmakefile (git rev-parse --short HEAD, kept out of the PROFILE variable itself since PROFILE gets separately stringified whole for the "Make profile used" trace line, and this value's embedded quotes broke that outer string literal when first tried folded in there). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01EortUUkDVpsfrbqshBJYJg --- src/GNUmakefile | 15 ++++++++++++++- src/chess.h | 7 +++++++ src/main.c | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/GNUmakefile b/src/GNUmakefile index bba3ee6..9b42844 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -122,7 +122,20 @@ PROFILE += -DDUMP_TREE endif endif # EVERYTHING -CFLAGS = -DPROFILE="\"$(PROFILE)\"" $(PROFILE) -Wall -Wno-nan-infinity-disabled -Ifathom +# Short commit hash (plus a -dirty suffix if the working tree has +# uncommitted changes) baked into the binary so a --logfile trace can +# be tied back to the exact source state, not just a build timestamp -- +# distinguishing rebuilds of the same day/commit during A/B testing was +# previously only possible by diffing binaries. Placed here, after all +# the PROFILE-overwriting `=` assignments above (not `+=`), so it +# survives into CFLAGS instead of being wiped out by them. +GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) +GIT_DIRTY := $(shell git diff --quiet 2>/dev/null || echo -dirty) +# Kept out of PROFILE itself (not folded in via +=): PROFILE gets +# stringified whole into -DPROFILE="..." below for the "Make profile +# used" trace line, and this value's embedded quotes broke that outer +# string literal when it was included there. +CFLAGS = -DPROFILE="\"$(PROFILE)\"" -DGIT_COMMIT=\"$(GIT_COMMIT)$(GIT_DIRTY)\" $(PROFILE) -Wall -Wno-nan-infinity-disabled -Ifathom HEADERS = chess.h compiler.h FATHOM_CFLAGS = -std=gnu99 -O2 -Ifathom $(filter -m32 -m64,$(PROFILE)) diff --git a/src/chess.h b/src/chess.h index 15f6ca8..b6175f7 100755 --- a/src/chess.h +++ b/src/chess.h @@ -209,6 +209,13 @@ typedef struct _DLIST_ENTRY #define VERSION "1.00" #define REVISION "$Id: chess.h 354 2008-06-30 05:10:08Z scott $\n" +// GIT_COMMIT is normally injected by GNUmakefile via -DGIT_COMMIT (short +// hash, plus a -dirty suffix if the tree had uncommitted changes at build +// time); this is just a fallback for any build path that doesn't set it. +#ifndef GIT_COMMIT +#define GIT_COMMIT "unknown" +#endif + // // Function decorators // diff --git a/src/main.c b/src/main.c index b09c8f0..baafe12 100755 --- a/src/main.c +++ b/src/main.c @@ -47,7 +47,7 @@ Return value: { char *p; - Trace("Typhoon %s (built on %s %s):\n", VERSION, __DATE__, __TIME__); + Trace("Typhoon %s (built on %s %s, commit %s):\n", VERSION, __DATE__, __TIME__, GIT_COMMIT); Trace(" Copyright (C) 2000-2007, Scott Gasch (scott.gasch@gmail.com)\n"); Trace(" " REVISION); Trace(" " COMPILER_STRING); -- cgit v1.3