From 9f023825e05fe1c2079c2ae90aac660a45175adf Mon Sep 17 00:00:00 2001 From: Itms Date: Sat, 4 Jan 2025 12:25:08 +0100 Subject: [PATCH] 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. --- build/build_version/build_version.bat | 2 +- source/ps/GameSetup/HWDetect.cpp | 4 ++-- source/ps/scripting/JSInterface_Debug.cpp | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/build/build_version/build_version.bat b/build/build_version/build_version.bat index 1a23077ed6..0f99039bf1 100644 --- a/build/build_version/build_version.bat +++ b/build/build_version/build_version.bat @@ -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 diff --git a/source/ps/GameSetup/HWDetect.cpp b/source/ps/GameSetup/HWDetect.cpp index 40a58134ba..14c2f6e6d8 100644 --- a/source/ps/GameSetup/HWDetect.cpp +++ b/source/ps/GameSetup/HWDetect.cpp @@ -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( diff --git a/source/ps/scripting/JSInterface_Debug.cpp b/source/ps/scripting/JSInterface_Debug.cpp index 78aa3bcc86..77d12cb6ac 100644 --- a/source/ps/scripting/JSInterface_Debug.cpp +++ b/source/ps/scripting/JSInterface_Debug.cpp @@ -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; }