From 7e0b6926bff23d2c2d7c040d0bb1a6fb9f2a5f13 Mon Sep 17 00:00:00 2001 From: Prakriti Gupta Date: Wed, 7 Oct 2026 13:56:52 -0700 Subject: [PATCH] Update to put the tag into the binaries --- utils/build_date.h | 3 ++- utils/gen_version.cmake | 11 ++++++++++- utils/version.h.in | 4 +++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/utils/build_date.h b/utils/build_date.h index cb2d1c8e..39419a86 100644 --- a/utils/build_date.h +++ b/utils/build_date.h @@ -10,7 +10,8 @@ #include #include -/// git commit this binary was built from, with a "-dirty" marker when the tree +/// git commit this binary was built from, described relative to the latest +/// release tag (e.g. v1.10.0-12-gc719a4ac), with a "-dirty" marker when the tree /// carried uncommitted changes. Defined in provenance.cpp, which is the only /// translation unit that includes the generated version.h, so that a change of /// hash recompiles one file instead of everything including this header. diff --git a/utils/gen_version.cmake b/utils/gen_version.cmake index 8c253bd9..d6075256 100644 --- a/utils/gen_version.cmake +++ b/utils/gen_version.cmake @@ -11,7 +11,16 @@ # leave OUT_FILE alone when nothing changed, avoiding a rebuild. # ---------------------------------------------------------------------------- -execute_process( COMMAND git rev-parse --short HEAD +# Name the build relative to the most recent release tag, e.g. +# v1.10.0-12-gc719a4ac is 12 commits past v1.10.0 at commit c719a4ac. +# +# --long keeps the hash even on a tagged commit (v1.10.0-0-g...), because a +# tag can be moved or deleted but the hash always names the commit. +# --match restricts this to annotated release tags of the form vX.Y.Z. +# --always falls back to the bare hash when no tag is reachable, such as in +# a shallow clone. +# +execute_process( COMMAND git describe --long --always --match "v[0-9]*" WORKING_DIRECTORY ${SRC_DIR} OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE diff --git a/utils/version.h.in b/utils/version.h.in index 47969e5c..8dd5ab6f 100644 --- a/utils/version.h.in +++ b/utils/version.h.in @@ -11,4 +11,6 @@ */ #pragma once -#define GIT_COMMIT_HASH "@GIT_COMMIT_HASH@" ///< hash, hash-dirty, or "unknown" +/// git describe output, e.g. v1.10.0-12-gc719a4ac[-dirty]; a bare hash if no +/// release tag is reachable; or "unknown" if git is unavailable +#define GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"