From e5c4fe003b9cfd1821fe81ae48f7d5069d75e865 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 21 Jan 2022 14:05:13 +0000 Subject: [PATCH] Build: Use git tag for file version on windows, attempt 2 --- cmake/Pcsx2Utils.cmake | 26 ++++++++++++++++++++++++-- common/vsprops/preBuild.cmd | 12 +++++++++++- pcsx2/PCSX2.rc | 17 ++++++++++++++++- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/cmake/Pcsx2Utils.cmake b/cmake/Pcsx2Utils.cmake index 5a59abf033..fc3eada5b2 100644 --- a/cmake/Pcsx2Utils.cmake +++ b/cmake/Pcsx2Utils.cmake @@ -77,9 +77,31 @@ endfunction() function(write_svnrev_h) if(PCSX2_GIT_TAG) - file(WRITE ${CMAKE_BINARY_DIR}/common/include/svnrev.h "#define SVN_REV ${PCSX2_WC_TIME}ll \n#define GIT_TAG \"${PCSX2_GIT_TAG}\"\n#define GIT_TAGGED_COMMIT 1\n#define GIT_REV \"\"\n") + if ("${PCSX2_GIT_TAG}" MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$") + file(WRITE ${CMAKE_BINARY_DIR}/common/include/svnrev.h + "#define SVN_REV ${PCSX2_WC_TIME}ll\n" + "#define GIT_TAG \"${PCSX2_GIT_TAG}\"\n" + "#define GIT_TAGGED_COMMIT 1\n" + "#define GIT_TAG_HI ${CMAKE_MATCH_1}\n" + "#define GIT_TAG_MID ${CMAKE_MATCH_2}\n" + "#define GIT_TAG_LO ${CMAKE_MATCH_3}\n" + "#define GIT_REV \"\"\n" + ) + else() + file(WRITE ${CMAKE_BINARY_DIR}/common/include/svnrev.h + "#define SVN_REV ${PCSX2_WC_TIME}ll\n" + "#define GIT_TAG \"${PCSX2_GIT_TAG}\"\n" + "#define GIT_TAGGED_COMMIT 1\n" + "#define GIT_REV \"\"\n" + ) + endif() else() - file(WRITE ${CMAKE_BINARY_DIR}/common/include/svnrev.h "#define SVN_REV ${PCSX2_WC_TIME}ll \n#define GIT_TAG \"${PCSX2_GIT_TAG}\"\n#define GIT_TAGGED_COMMIT 0\n#define GIT_REV \"${PCSX2_GIT_REV}\"\n") + file(WRITE ${CMAKE_BINARY_DIR}/common/include/svnrev.h + "#define SVN_REV ${PCSX2_WC_TIME}ll\n" + "#define GIT_TAG \"${PCSX2_GIT_TAG}\"\n" + "#define GIT_TAGGED_COMMIT 0\n" + "#define GIT_REV \"${PCSX2_GIT_REV}\"\n" + ) endif() endfunction() diff --git a/common/vsprops/preBuild.cmd b/common/vsprops/preBuild.cmd index a107662886..885cdf3a37 100644 --- a/common/vsprops/preBuild.cmd +++ b/common/vsprops/preBuild.cmd @@ -11,7 +11,7 @@ :: :: ProjectSrcDir - $(ProjectDir)\.. - Top-level Directory of project source code. -SETLOCAL ENABLEEXTENSIONS +SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS IF EXIST "%ProgramFiles(x86)%\Git\bin\git.exe" SET "GITPATH=%ProgramFiles(x86)%\Git\bin" IF EXIST "%ProgramFiles%\Git\bin\git.exe" SET "GITPATH=%ProgramFiles%\Git\bin" @@ -55,6 +55,16 @@ if %ERRORLEVEL% NEQ 0 ( echo #define SVN_REV 0ll >> "%CD%\svnrev.h" echo #define GIT_REV "" >> "%CD%\svnrev.h" echo #define GIT_TAG "%GIT_TAG%" >> "%CD%\svnrev.h" + + echo %GIT_TAG%|FINDSTR /R "^v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$" > NUL + if !ERRORLEVEL! EQU 0 ( + FOR /F "tokens=1,2,3 delims=v." %%a in ("%GIT_TAG%") DO ( + echo #define GIT_TAG_HI %%a >> "%CD%\svnrev.h" + echo #define GIT_TAG_MID %%b >> "%CD%\svnrev.h" + echo #define GIT_TAG_LO %%c >> "%CD%\svnrev.h" + ) + ) + echo #define GIT_TAGGED_COMMIT 1 >> "%CD%\svnrev.h" ) else ( echo #define SVN_REV %REV%ll > "%CD%\svnrev.h" diff --git a/pcsx2/PCSX2.rc b/pcsx2/PCSX2.rc index aaadf31bcc..e5686f29c6 100644 --- a/pcsx2/PCSX2.rc +++ b/pcsx2/PCSX2.rc @@ -2,6 +2,7 @@ // #include "resource.h" #include "SysForwardDefs.h" +#include "svnrev.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// @@ -31,7 +32,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 1 TEXTINCLUDE BEGIN "resource.h\r\n" - "SysForwardDefs.h\0" + "SysForwardDefs.h\r\n" + "svnrev.h\0" END 2 TEXTINCLUDE @@ -51,8 +53,13 @@ END // VS_VERSION_INFO VERSIONINFO +#if PCSX2_isReleaseVersion == false && GIT_TAGGED_COMMIT && defined(GIT_TAG_HI) + FILEVERSION GIT_TAG_HI, GIT_TAG_MID, GIT_TAG_LO, 0 + PRODUCTVERSION GIT_TAG_HI, GIT_TAG_MID, GIT_TAG_LO, 0 +#else FILEVERSION VER_FILE_VERSION PRODUCTVERSION VER_PRODUCT_VERSION +#endif FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -68,12 +75,20 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "FileDescription", VER_FILE_DESCRIPTION_STR "\0" +#if PCSX2_isReleaseVersion == false && GIT_TAGGED_COMMIT && defined(GIT_TAG_HI) + VALUE "FileVersion", STRINGIZE(GIT_TAG_HI) "." STRINGIZE(GIT_TAG_MID) "." STRINGIZE(GIT_TAG_LO) "." STRINGIZE(0) "\0" +#else VALUE "FileVersion", VER_FILE_VERSION_STR "\0" +#endif VALUE "InternalName", VER_INTERNAL_NAME_STR "\0" VALUE "LegalCopyright", VER_COPYRIGHT_STR "\0" VALUE "OriginalFilename", VER_ORIGINAL_FILENAME_STR "\0" VALUE "ProductName", VER_PRODUCTNAME_STR "\0" +#if PCSX2_isReleaseVersion == false && GIT_TAGGED_COMMIT && defined(GIT_TAG_HI) + VALUE "ProductVersion", STRINGIZE(GIT_TAG_HI) "." STRINGIZE(GIT_TAG_MID) "." STRINGIZE(GIT_TAG_LO) "." STRINGIZE(0) "\0" +#else VALUE "ProductVersion", VER_PRODUCT_VERSION_STR "\0" +#endif END END BLOCK "VarFileInfo"