From b5eea287d561f2c576e4a3dad36a16e6930b3792 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sat, 31 Aug 2024 13:22:29 +0200 Subject: [PATCH] add git commit hash to file version and log --- .gitignore | 2 ++ cnc-ddraw.vcxproj | 30 ++++++++++++++++++++++++++++++ inc/version.h | 1 + res.rc | 12 ++++++++++-- src/debug.c | 16 +++++++++++++++- 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 158b71e..1bffb6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +inc/version_tmp.h + # C++ Builder __astcache/ diff --git a/cnc-ddraw.vcxproj b/cnc-ddraw.vcxproj index fda7e42..498532a 100644 --- a/cnc-ddraw.vcxproj +++ b/cnc-ddraw.vcxproj @@ -230,6 +230,12 @@ if NOT "$(LocalDebuggerWorkingDirectory)" == "$(ProjectDir)" if exist "$(LocalDe ) + + echo | set /p dummyName=#define GIT_COMMIT > inc/version_tmp.h +"$(DevEnvDir)\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git" rev-parse --short HEAD >> inc/version_tmp.h || git rev-parse --verify HEAD >> inc/version_tmp.h || echo UNKNOWN >> inc/version_tmp.h + +SET ERRORLEVEL = 0 + @@ -257,6 +263,12 @@ if NOT "$(LocalDebuggerWorkingDirectory)" == "$(ProjectDir)" if exist "$(LocalDe ) + + echo | set /p dummyName=#define GIT_COMMIT > inc/version_tmp.h +"$(DevEnvDir)\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git" rev-parse --short HEAD >> inc/version_tmp.h || git rev-parse --verify HEAD >> inc/version_tmp.h || echo UNKNOWN >> inc/version_tmp.h + +SET ERRORLEVEL = 0 + @@ -284,6 +296,12 @@ if NOT "$(LocalDebuggerWorkingDirectory)" == "$(ProjectDir)" if exist "$(LocalDe ) + + echo | set /p dummyName=#define GIT_COMMIT > inc/version_tmp.h +"$(DevEnvDir)\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git" rev-parse --short HEAD >> inc/version_tmp.h || git rev-parse --verify HEAD >> inc/version_tmp.h || echo UNKNOWN >> inc/version_tmp.h + +SET ERRORLEVEL = 0 + @@ -311,6 +329,12 @@ if NOT "$(LocalDebuggerWorkingDirectory)" == "$(ProjectDir)" if exist "$(LocalDe ) + + echo | set /p dummyName=#define GIT_COMMIT > inc/version_tmp.h +"$(DevEnvDir)\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git" rev-parse --short HEAD >> inc/version_tmp.h || git rev-parse --verify HEAD >> inc/version_tmp.h || echo UNKNOWN >> inc/version_tmp.h + +SET ERRORLEVEL = 0 + @@ -338,6 +362,12 @@ if NOT "$(LocalDebuggerWorkingDirectory)" == "$(ProjectDir)" if exist "$(LocalDe ) + + echo | set /p dummyName=#define GIT_COMMIT > inc/version_tmp.h +"$(DevEnvDir)\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git" rev-parse --short HEAD >> inc/version_tmp.h || git rev-parse --verify HEAD >> inc/version_tmp.h || echo UNKNOWN >> inc/version_tmp.h + +SET ERRORLEVEL = 0 + diff --git a/inc/version.h b/inc/version.h index eeeaa0a..9fef507 100644 --- a/inc/version.h +++ b/inc/version.h @@ -3,6 +3,7 @@ #define str(s) #s #define ver_str(a,b,c,d) str(a) "." str(b) "." str(c) "." str(d) +#define git_str(a) str(a) #define VERSION_MAJOR 6 #define VERSION_MINOR 8 diff --git a/res.rc b/res.rc index 69ba76c..9c361ce 100644 --- a/res.rc +++ b/res.rc @@ -1,5 +1,13 @@ #include "inc/version.h" +#ifndef __GNUC__ +#include "inc/version_tmp.h" +#endif + +#ifndef GIT_COMMIT +#define GIT_COMMIT UNKNOWN +#endif + 1 VERSIONINFO FILEVERSION VERSION PRODUCTVERSION VERSION @@ -10,13 +18,13 @@ PRODUCTVERSION VERSION { VALUE "CompanyName", "github.com/FunkyFr3sh" VALUE "FileDescription", "DirectDraw replacement" - VALUE "FileVersion", VERSION_STRING + VALUE "FileVersion", VERSION_STRING " (git~" git_str(GIT_COMMIT) ")" VALUE "InternalName", "ddraw" VALUE "LegalCopyright", "Copyright (c) 2010-2024" VALUE "LegalTrademarks", "" VALUE "OriginalFileName", "ddraw.dll" VALUE "ProductName", "cnc-ddraw" - VALUE "ProductVersion", VERSION_STRING + VALUE "ProductVersion", VERSION_STRING " (git~" git_str(GIT_COMMIT) ")" VALUE "Comments", "https://github.com/FunkyFr3sh/cnc-ddraw" } } diff --git a/src/debug.c b/src/debug.c index 0e2c90e..b21bf11 100644 --- a/src/debug.c +++ b/src/debug.c @@ -10,6 +10,14 @@ #include "version.h" #include "versionhelpers.h" +#ifndef __GNUC__ +#include "version_tmp.h" +#endif + +#ifndef GIT_COMMIT +#define GIT_COMMIT UNKNOWN +#endif + double g_dbg_frame_time = 0; DWORD g_dbg_frame_count = 0; @@ -151,7 +159,13 @@ void dbg_init() setvbuf(g_dbg_log_file, NULL, _IOLBF, 1024); } - TRACE("cnc-ddraw version = %d.%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION); + TRACE( + "cnc-ddraw version = %d.%d.%d.%d (git~%s)\n", + VERSION_MAJOR, + VERSION_MINOR, + VERSION_BUILD, + VERSION_REVISION, + git_str(GIT_COMMIT)); HKEY hkey; LONG status =