Stamp the build's identity into GameVersion.cpp from CMake

GameVersion.cpp becomes a configure_file template, so the version strings are a
build input rather than something a CI step seds into the working tree mid-run.
That is what lets a crash report be matched to its exact build's PDB for offline
symbolization.

The two strings get distinct jobs. czVersionString is the machine-readable build
identity: the bare short commit SHA and nothing else. A `git describe` string
cannot serve here -- czVersionString is 16 bytes because it is stored in the
savegame header as SAVED_GAME_HEADER::zGameVersionNumber and strcmp'd on load,
and describe puts the SHA last, so truncation ate exactly the discriminating part
and could make two different commits compare equal. CI passes 9 hex; anything
that would not fit is now a configure error rather than a silent clip.

zBuildInformation is the display string, untruncated, and it is no longer printed
beside czVersionString: that drops the duplication in the version line ("JA2 1.13
V4-555-G6A941C0 2026-07-25 V4-555-G6A941C06") and stops showing a token that is
now machine-only. CI's copy leads with GAME_VERSION, because the version line is
now the only place a player reads which release they are running.

Finish what the sed step's TODO asked for: the workflow pins GAME_BUILD_INFORMATION
and GIT_SHA once, next to the gamedir SHAs it already pins, and hands them to CMake
with -D. Every parallel build job therefore stamps one agreed identity, and the
compile checkout needs no git history at all.

A build nobody identifies is a local build and says so -- czVersionString reads
"local" -- rather than deriving a SHA from HEAD. A derived SHA could not stay
true: nothing re-runs configure once HEAD moves, so an incremental build would
keep whatever it was configured with, and keeping it honest would mean
reconfiguring on every commit. It would also buy nothing, because only packaged
builds are archived with their PDBs; a local build's crash reports are symbolized
against the PDB sitting next to the exe.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-28 10:25:47 -03:00
committed by majcosta
co-authored by Claude Opus 5
parent 00dad8aa12
commit 1e2ce70315
7 changed files with 81 additions and 25 deletions
+45 -1
View File
@@ -1,3 +1,47 @@
# Stamp the build's identity into GameVersion.cpp. Both strings come from the
# caller with -D, and CI passes them: it pins them once, where it decides what the
# release is, so the parallel build jobs cannot stamp identities that disagree.
#
# A build nobody identified is a local build, and says so rather than guessing
# from HEAD. Keeping such a guess honest would mean re-running configure on every
# commit, and it would buy nothing: only what we package is archived with its PDB,
# and a local crash report is symbolized against the PDB next to the exe.
#
# GIT_SHA lands in czVersionString, which is both the savegame compatibility key
# and the crash-report key. It is the bare short SHA and nothing else — a `git
# describe` string cannot serve here, because czVersionString is only 16 bytes and
# describe puts the SHA last, so it is exactly the discriminating part that would
# get clipped off. The budget is 15 chars + NUL: the string is stored in the
# savegame header as SAVED_GAME_HEADER::zGameVersionNumber (GAME_VERSION_LENGTH),
# so its size is a binary format constant and cannot grow. CI passes 9 hex, well
# past what uniqueness needs (git's own auto-abbrev picks 8 for this repo).
# Overshooting it is an error rather than a truncation, because a clipped SHA is
# how two different builds end up claiming to be the same one.
if(NOT GIT_SHA)
set(GIT_SHA "local")
endif()
string(LENGTH "${GIT_SHA}" _length)
if(_length GREATER 15)
message(FATAL_ERROR "GIT_SHA is ${_length} characters; czVersionString holds 15")
endif()
# zBuildInformation is the version line shown on screen, CHAR16[256]. Nothing
# parses it, so it carries the version in full and truncation costs only
# readability.
if(NOT GAME_BUILD_INFORMATION)
string(TIMESTAMP _buildDate "%Y-%m-%d" UTC)
set(GAME_BUILD_INFORMATION "local build ${_buildDate}")
endif()
string(LENGTH "${GAME_BUILD_INFORMATION}" _length)
if(_length GREATER 255)
string(SUBSTRING "${GAME_BUILD_INFORMATION}" 0 255 GAME_BUILD_INFORMATION)
endif()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/GameVersion.cpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/GameVersion.cpp"
@ONLY)
set(Ja2Src
"${CMAKE_CURRENT_SOURCE_DIR}/aniviewscreen.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Credits.cpp"
@@ -7,7 +51,7 @@ set(Ja2Src
"${CMAKE_CURRENT_SOURCE_DIR}/gameloop.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/gamescreen.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GameSettings.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GameVersion.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/GameVersion.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/HelpScreen.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Init.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Intro.cpp"
+1 -1
View File
@@ -4299,7 +4299,7 @@ void FreeGameExternalOptions()
void DisplayGameSettings( )
{
//Display the version number
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"%s: %s %S %s", pMessageStrings[ MSG_VERSION ], zProductLabel, czVersionString, zBuildInformation );
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"%s: %s %s", pMessageStrings[ MSG_VERSION ], zProductLabel, zBuildInformation );
//Display the difficulty level
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"%s: %s", gzGIOScreenText[ GIO_DIF_LEVEL_TEXT ], zDiffSetting[gGameOptions.ubDifficultyLevel].szDiffName );
@@ -39,7 +39,7 @@
#endif
CHAR8 czVersionString[16] = { "@Version@" };
CHAR16 zBuildInformation[256] = { L"@Build@" };
CHAR8 czVersionString[16] = { "@GIT_SHA@" };
CHAR16 zBuildInformation[256] = { L"@GAME_BUILD_INFORMATION@" };
// SAVE_GAME_VERSION is defined in header, change it there
+8 -2
View File
@@ -13,9 +13,15 @@ extern "C" {
// name of the product, Unfinished Business, Map Editor etc..
extern CHAR16 zProductLabel[64];
// used for save game comparison
// this build's identity, stamped in by CMake from -DGIT_SHA. A packaged build sets
// it to the bare short commit SHA and nothing else, so it names that build exactly;
// a build nobody identified reads "local". Used for save game comparison, and
// stamped into crash reports so a packaged build's report can be matched to the PDB
// archived beside it for offline symbolization.
extern CHAR8 czVersionString[16];
// can contain information regarding the build: what git ref was the base (tag, branch), by whom, commit date, build date, etc..
// human-readable build description, stamped in from -DGAME_BUILD_INFORMATION: the
// release name, its date and where it was built, or "local build <date>". For
// display only — never compared against, so it is free to change shape.
extern CHAR16 zBuildInformation[256];
//ADB: I needed these here so I moved them, and why put them in *.cpp anyways?
+2 -2
View File
@@ -354,9 +354,9 @@ UINT32 InitScreenHandle(void)
SetFontForeground( FONT_MCOLOR_WHITE );
#ifdef _DEBUG
mprintf( 10, 10, L"%s: %s Debug %S %s", pMessageStrings[ MSG_VERSION ], zProductLabel, czVersionString, zBuildInformation );
mprintf( 10, 10, L"%s: %s Debug %s", pMessageStrings[ MSG_VERSION ], zProductLabel, zBuildInformation );
#else
mprintf( 10, 10, L"%s: %s %S %s", pMessageStrings[ MSG_VERSION ], zProductLabel, czVersionString, zBuildInformation );
mprintf( 10, 10, L"%s: %s %s", pMessageStrings[ MSG_VERSION ], zProductLabel, zBuildInformation );
#endif
#if defined JA2BETAVERSION