Export a 10-char commit hash in the build version

This avoids collisions in the user report, fixes #7174.
Update the user report version to account for the new build version
format, fixes #7173.

The build version displayed in the GUI is kept at 5 characters for
main menu clutter concerns.
This commit is contained in:
Itms 2025-01-04 12:25:08 +01:00
parent 8ee48a164a
commit 9f023825e0
No known key found for this signature in database
GPG key ID: C7E52BD14CE14E09
3 changed files with 13 additions and 5 deletions

View file

@ -2,5 +2,5 @@
REM Generate a Unicode string constant from git's output, including branch
REM name and an abbreviated commit hash, and write it to build_version.txt
FOR /F %%b IN ('git branch --show-current') DO SET branch=%%b
FOR /F %%h IN ('git rev-parse --short^=5 HEAD') DO SET hash=%%h
FOR /F %%h IN ('git rev-parse --short HEAD') DO SET hash=%%h
ECHO L"%branch%, %hash%" > build_version.txt

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2024 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -406,7 +406,7 @@ void RunHardwareDetection(bool writeSystemInfoBeforeDetection, Renderer::Backend
Script::SetProperty(rq, settings, "random_device_entropy", std::random_device{}.entropy());
// The version should be increased for every meaningful change.
const int reportVersion = 21;
const int reportVersion = 22;
// Send the same data to the reporting system
g_UserReporter.SubmitReport(

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2024 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -80,11 +80,19 @@ double GetBuildTimestamp()
// hash and cached in lib/build_version.cpp. it is useful to know when attempting
// to reproduce bugs (the main EXE and PDB should be temporarily reverted to
// that commit so that they match user-submitted crashdumps).
std::wstring GetBuildVersion()
// - this function is used by the JS GUI to display the version in a size-constrained
// zone. when longerHash is false, the last 5 characters of the git hash are cut off.
std::wstring GetBuildVersion(bool longerHash = false)
{
std::wstring buildVersion(build_version);
if (buildVersion == L"custom build")
return wstring_from_utf8(g_L10n.Translate("custom build"));
// The hash is 10-char, which is a bit long for the GUI. Reduce it to 5-char by
// default for the main menu display.
if (!longerHash && buildVersion.length() > 5)
return buildVersion.substr(0, buildVersion.length() - 5);
return buildVersion;
}