From 9efaf28142d2f0c8b14be6ef685ca1f542d043d5 Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 12 Apr 2024 19:14:37 +0200 Subject: [PATCH 1/6] Add git info to title screen & gameplay stats --- CMakeLists.txt | 18 ++++++++++++++++++ soh/include/variables.h | 4 +++- soh/soh/CrashHandlerExt.cpp | 2 ++ soh/soh/Enhancements/gameplaystats.cpp | 8 +++++++- .../randomizer/3drando/spoiler_log.cpp | 2 ++ soh/soh/OTRGlobals.cpp | 2 +- soh/src/boot/build.c.in | 2 ++ .../overlays/gamestates/ovl_title/z_title.c | 18 +++++++++++++++++- 8 files changed, 52 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5227169d4b..89f0d769851 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,24 @@ project(Ship VERSION 8.0.5 LANGUAGES C CXX) set(PROJECT_BUILD_NAME "MacReady Foxtrot" CACHE STRING "") set(PROJECT_TEAM "github.com/harbourmasters" CACHE STRING "") +execute_process( + COMMAND git branch --show-current + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +set(CMAKE_PROJECT_GIT_BRANCH "${GIT_BRANCH}" CACHE STRING "Git branch" FORCE) + +execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +set(CMAKE_PROJECT_GIT_COMMIT_HASH "${GIT_COMMIT_HASH}" CACHE STRING "Git commit hash" FORCE) + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT soh) add_compile_options($<$:/MP>) add_compile_options($<$:/utf-8>) diff --git a/soh/include/variables.h b/soh/include/variables.h index 9fd6b724788..021009b5a21 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -49,7 +49,9 @@ extern "C" extern u16 gBuildVersionMajor; extern u16 gBuildVersionMinor; extern u16 gBuildVersionPatch; - extern u8 gBuildTeam[]; + extern u8 gGitBranch[]; + extern u8 gGitCommitHash[]; + extern u8 gBuildTeam[]; extern u8 gBuildDate[]; extern u8 gBuildMakeOption[]; extern OSMesgQueue gPiMgrCmdQ; diff --git a/soh/soh/CrashHandlerExt.cpp b/soh/soh/CrashHandlerExt.cpp index 14f0714ffa9..c4a535f1216 100644 --- a/soh/soh/CrashHandlerExt.cpp +++ b/soh/soh/CrashHandlerExt.cpp @@ -69,6 +69,8 @@ extern "C" void CrashHandler_PrintSohData(char* buffer, size_t* pos) { char intCharBuffer[16]; append_line(buffer, pos, "Build Information:"); WRITE_VAR_LINE(buffer, pos, "Game Version: ", (const char*)gBuildVersion); + WRITE_VAR_LINE(buffer, pos, "Git Branch: ", (const char*)gGitBranch); + WRITE_VAR_LINE(buffer, pos, "Git Commit: ", (const char*)gGitCommitHash); WRITE_VAR_LINE(buffer, pos, "Build Date: ", (const char*)gBuildDate); if (gPlayState != nullptr) { diff --git a/soh/soh/Enhancements/gameplaystats.cpp b/soh/soh/Enhancements/gameplaystats.cpp index efcf44efb90..a32890595bd 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -436,7 +436,13 @@ void DrawGameplayStatsHeader() { ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, { 4.0f, 4.0f }); ImGui::BeginTable("gameplayStatsHeader", 1, ImGuiTableFlags_BordersOuter); ImGui::TableSetupColumn("stat", ImGuiTableColumnFlags_WidthStretch); - GameplayStatsRow("Build Version:", (char*) gBuildVersion); + GameplayStatsRow("Build Version:", (char*)gBuildVersion); + if (((char*)gGitBranch) != "develop") { + GameplayStatsRow("Git Branch:", (char*)gGitBranch); + } + if (CVarGetInteger("gGameplayStats.ShowDebugInfo", 0)) { + GameplayStatsRow("Git Commit Hash:", (char*)gGitCommitHash); + } if (gSaveContext.sohStats.rtaTiming) { GameplayStatsRow("Total Time (RTA):", formatTimestampGameplayStat(GAMEPLAYSTAT_TOTAL_TIME), gSaveContext.sohStats.gameComplete ? COLOR_GREEN : COLOR_WHITE); } else { diff --git a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp index ce885aec5b0..3a28b11ea01 100644 --- a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp @@ -864,6 +864,8 @@ const char* SpoilerLog_Write(int language) { jsonData.clear(); jsonData["version"] = (char*) gBuildVersion; + jsonData["git_branch"] = (char*) gGitBranch; + jsonData["git_commit"] = (char*) gGitCommitHash; jsonData["seed"] = Settings::seedString; jsonData["finalSeed"] = Settings::seed; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index c9cb3613081..570aca1d03e 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -323,7 +323,7 @@ OTRGlobals::OTRGlobals() { context->InitWindow(sohInputEditorWindow); context->InitAudio(); - SPDLOG_INFO("Starting Ship of Harkinian version {}", (char*)gBuildVersion); + SPDLOG_INFO("Starting Ship of Harkinian version {} (Branch: {} | Commit: {})", (char*)gBuildVersion, (char*)gGitBranch, (char*)gGitCommitHash); auto loader = context->GetResourceManager()->GetResourceLoader(); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Animation", static_cast(SOH::ResourceType::SOH_Animation), 0); diff --git a/soh/src/boot/build.c.in b/soh/src/boot/build.c.in index 4fc6a17f493..4ebd3a4f6db 100644 --- a/soh/src/boot/build.c.in +++ b/soh/src/boot/build.c.in @@ -4,6 +4,8 @@ const char gBuildVersion[] = "@PROJECT_BUILD_NAME@ (@CMAKE_PROJECT_VERSION_MAJOR const u16 gBuildVersionMajor = @CMAKE_PROJECT_VERSION_MAJOR@; const u16 gBuildVersionMinor = @CMAKE_PROJECT_VERSION_MINOR@; const u16 gBuildVersionPatch = @CMAKE_PROJECT_VERSION_PATCH@; +const char gGitBranch[] = "@CMAKE_PROJECT_GIT_BRANCH@"; +const char gGitCommitHash[] = "@CMAKE_PROJECT_GIT_COMMIT_HASH@"; const char gBuildTeam[] = "@PROJECT_TEAM@"; const char gBuildDate[] = __DATE__ " " __TIME__; const char gBuildMakeOption[] = ""; diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index d123e7e90ed..e7ec1fb1592 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -30,8 +30,24 @@ void Title_PrintBuildInfo(Gfx** gfxp) { GfxPrint_Open(&printer, g); GfxPrint_SetColor(&printer, 131, 154, 255, 255); - GfxPrint_SetPos(&printer, 1, 25); + bool showGitBranch = ((char*)gGitBranch) != "develop"; + bool showGitCommit = CVarGetInteger("gDebugEnabled", 0); + + GfxPrint_SetPos(&printer, 1, showGitBranch ? (showGitCommit ? 23 : 24) : (showGitCommit ? 24 : 25)); GfxPrint_Printf(&printer, "%s", gBuildVersion); + if (showGitBranch) { + GfxPrint_SetPos(&printer, 1, showGitCommit ? 24 : 25); + GfxPrint_Printf(&printer, "Git Branch: %s", gGitBranch); + } + if (showGitCommit) { + //truncate the commit to 7 characters + char gGitCommitHashTruncated[8]; + strncpy(gGitCommitHashTruncated, gGitCommitHash, 7); + gGitCommitHashTruncated[7] = 0; + + GfxPrint_SetPos(&printer, 1, 25); + GfxPrint_Printf(&printer, "Git Commit: %s", gGitCommitHashTruncated); + } GfxPrint_SetPos(&printer, 1, 26); GfxPrint_Printf(&printer, "%s", gBuildDate); From e27cc0aac9efa68d54cd64b4e5537d9ae8793893 Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 12 Apr 2024 19:40:41 +0200 Subject: [PATCH 2/6] Change the branch criteria to starting with `develop` --- soh/soh/Enhancements/gameplaystats.cpp | 3 ++- soh/src/overlays/gamestates/ovl_title/z_title.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/soh/soh/Enhancements/gameplaystats.cpp b/soh/soh/Enhancements/gameplaystats.cpp index a32890595bd..d9f99030bba 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -437,7 +437,8 @@ void DrawGameplayStatsHeader() { ImGui::BeginTable("gameplayStatsHeader", 1, ImGuiTableFlags_BordersOuter); ImGui::TableSetupColumn("stat", ImGuiTableColumnFlags_WidthStretch); GameplayStatsRow("Build Version:", (char*)gBuildVersion); - if (((char*)gGitBranch) != "develop") { + //if branch doesn't start with "develop" + if (strncmp((char*)gGitBranch, "develop", strlen("develop")) != 0) { GameplayStatsRow("Git Branch:", (char*)gGitBranch); } if (CVarGetInteger("gGameplayStats.ShowDebugInfo", 0)) { diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index e7ec1fb1592..e03a5c79e60 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -30,7 +30,8 @@ void Title_PrintBuildInfo(Gfx** gfxp) { GfxPrint_Open(&printer, g); GfxPrint_SetColor(&printer, 131, 154, 255, 255); - bool showGitBranch = ((char*)gGitBranch) != "develop"; + //if branch doesn't start with "develop" + bool showGitBranch = strncmp((char*)gGitBranch, "develop", strlen("develop")) != 0; bool showGitCommit = CVarGetInteger("gDebugEnabled", 0); GfxPrint_SetPos(&printer, 1, showGitBranch ? (showGitCommit ? 23 : 24) : (showGitCommit ? 24 : 25)); From 31db01be19de335c2bb21767ee5a71e9beb0e03a Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:23:17 +0200 Subject: [PATCH 3/6] Update z_title.c --- soh/src/overlays/gamestates/ovl_title/z_title.c | 1 + 1 file changed, 1 insertion(+) diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index e03a5c79e60..c3f3c396ba0 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "time.h" From 7c79fbd41f9fadebe37734b6e9751cd5fcf8e5b9 Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:57:34 +0200 Subject: [PATCH 4/6] Change the branch criteria to not having a tag --- CMakeLists.txt | 13 +++++++++++++ soh/include/variables.h | 1 + soh/soh/Enhancements/gameplaystats.cpp | 4 ++-- soh/src/boot/build.c.in | 1 + soh/src/overlays/gamestates/ovl_title/z_title.c | 4 ++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89f0d769851..8315e0e3858 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,19 @@ execute_process( set(CMAKE_PROJECT_GIT_COMMIT_HASH "${GIT_COMMIT_HASH}" CACHE STRING "Git commit hash" FORCE) +execute_process( + COMMAND git describe --tags --abbrev=0 --exact-match HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(NOT GIT_COMMIT_TAG) + set(GIT_COMMIT_TAG "" CACHE STRING "Git commit tag" FORCE) +endif() + +set(CMAKE_PROJECT_GIT_COMMIT_TAG "${GIT_COMMIT_TAG}" CACHE STRING "Git commit tag" FORCE) + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT soh) add_compile_options($<$:/MP>) add_compile_options($<$:/utf-8>) diff --git a/soh/include/variables.h b/soh/include/variables.h index 021009b5a21..b262ff089c5 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -51,6 +51,7 @@ extern "C" extern u16 gBuildVersionPatch; extern u8 gGitBranch[]; extern u8 gGitCommitHash[]; + extern u8 gGitCommitTag[]; extern u8 gBuildTeam[]; extern u8 gBuildDate[]; extern u8 gBuildMakeOption[]; diff --git a/soh/soh/Enhancements/gameplaystats.cpp b/soh/soh/Enhancements/gameplaystats.cpp index d9f99030bba..217f889f614 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -437,8 +437,8 @@ void DrawGameplayStatsHeader() { ImGui::BeginTable("gameplayStatsHeader", 1, ImGuiTableFlags_BordersOuter); ImGui::TableSetupColumn("stat", ImGuiTableColumnFlags_WidthStretch); GameplayStatsRow("Build Version:", (char*)gBuildVersion); - //if branch doesn't start with "develop" - if (strncmp((char*)gGitBranch, "develop", strlen("develop")) != 0) { + //if tag is empty (not a release build) + if (gGitCommitTag[0] == 0) { GameplayStatsRow("Git Branch:", (char*)gGitBranch); } if (CVarGetInteger("gGameplayStats.ShowDebugInfo", 0)) { diff --git a/soh/src/boot/build.c.in b/soh/src/boot/build.c.in index 4ebd3a4f6db..bcd4033de78 100644 --- a/soh/src/boot/build.c.in +++ b/soh/src/boot/build.c.in @@ -6,6 +6,7 @@ const u16 gBuildVersionMinor = @CMAKE_PROJECT_VERSION_MINOR@; const u16 gBuildVersionPatch = @CMAKE_PROJECT_VERSION_PATCH@; const char gGitBranch[] = "@CMAKE_PROJECT_GIT_BRANCH@"; const char gGitCommitHash[] = "@CMAKE_PROJECT_GIT_COMMIT_HASH@"; +const char gGitCommitTag[] = "@CMAKE_PROJECT_GIT_COMMIT_TAG@"; const char gBuildTeam[] = "@PROJECT_TEAM@"; const char gBuildDate[] = __DATE__ " " __TIME__; const char gBuildMakeOption[] = ""; diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index c3f3c396ba0..2b421dfa455 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -31,8 +31,8 @@ void Title_PrintBuildInfo(Gfx** gfxp) { GfxPrint_Open(&printer, g); GfxPrint_SetColor(&printer, 131, 154, 255, 255); - //if branch doesn't start with "develop" - bool showGitBranch = strncmp((char*)gGitBranch, "develop", strlen("develop")) != 0; + //if tag is empty (not a release build) + bool showGitBranch = gGitCommitTag[0] == 0; bool showGitCommit = CVarGetInteger("gDebugEnabled", 0); GfxPrint_SetPos(&printer, 1, showGitBranch ? (showGitCommit ? 23 : 24) : (showGitCommit ? 24 : 25)); From 1175b97541ca9b91e0d466ba66a558598d8995fb Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 23 Aug 2024 00:26:41 +0200 Subject: [PATCH 5/6] Always show both when not a release build --- soh/soh/Enhancements/gameplaystats.cpp | 2 -- soh/src/overlays/gamestates/ovl_title/z_title.c | 12 +++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/soh/soh/Enhancements/gameplaystats.cpp b/soh/soh/Enhancements/gameplaystats.cpp index 5a4e766758f..0ed936f6bb5 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -441,8 +441,6 @@ void DrawGameplayStatsHeader() { //if tag is empty (not a release build) if (gGitCommitTag[0] == 0) { GameplayStatsRow("Git Branch:", (char*)gGitBranch); - } - if (CVarGetInteger("gGameplayStats.ShowDebugInfo", 0)) { GameplayStatsRow("Git Commit Hash:", (char*)gGitCommitHash); } if (gSaveContext.sohStats.rtaTiming) { diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index 9b7eedf0b6a..fbbcfe6679f 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -32,16 +32,14 @@ void Title_PrintBuildInfo(Gfx** gfxp) { GfxPrint_SetColor(&printer, 131, 154, 255, 255); //if tag is empty (not a release build) - bool showGitBranch = gGitCommitTag[0] == 0; - bool showGitCommit = CVarGetInteger("gDebugEnabled", 0); + bool showGitInfo = gGitCommitTag[0] == 0; - GfxPrint_SetPos(&printer, 1, showGitBranch ? (showGitCommit ? 23 : 24) : (showGitCommit ? 24 : 25)); + GfxPrint_SetPos(&printer, 1, showGitInfo ? 23 : 25); GfxPrint_Printf(&printer, "%s", gBuildVersion); - if (showGitBranch) { - GfxPrint_SetPos(&printer, 1, showGitCommit ? 24 : 25); + if (showGitInfo) { + GfxPrint_SetPos(&printer, 1, 24); GfxPrint_Printf(&printer, "Git Branch: %s", gGitBranch); - } - if (showGitCommit) { + //truncate the commit to 7 characters char gGitCommitHashTruncated[8]; strncpy(gGitCommitHashTruncated, gGitCommitHash, 7); From f219c512394e9ca9603b2d7b74486701f6d81b59 Mon Sep 17 00:00:00 2001 From: Pepe20129 <72659707+Pepe20129@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:04:40 +0200 Subject: [PATCH 6/6] Only show build version in tagged releases --- soh/soh/Enhancements/gameplaystats.cpp | 3 ++- soh/src/overlays/gamestates/ovl_title/z_title.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/soh/soh/Enhancements/gameplaystats.cpp b/soh/soh/Enhancements/gameplaystats.cpp index 0ed936f6bb5..93cb672e3f3 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -437,11 +437,12 @@ void DrawGameplayStatsHeader() { ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, { 4.0f, 4.0f }); ImGui::BeginTable("gameplayStatsHeader", 1, ImGuiTableFlags_BordersOuter); ImGui::TableSetupColumn("stat", ImGuiTableColumnFlags_WidthStretch); - GameplayStatsRow("Build Version:", (char*)gBuildVersion); //if tag is empty (not a release build) if (gGitCommitTag[0] == 0) { GameplayStatsRow("Git Branch:", (char*)gGitBranch); GameplayStatsRow("Git Commit Hash:", (char*)gGitCommitHash); + } else { + GameplayStatsRow("Build Version:", (char*)gBuildVersion); } if (gSaveContext.sohStats.rtaTiming) { GameplayStatsRow("Total Time (RTA):", formatTimestampGameplayStat(GAMEPLAYSTAT_TOTAL_TIME), gSaveContext.sohStats.gameComplete ? COLOR_GREEN : COLOR_WHITE); diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index fbbcfe6679f..8893d9d5f5c 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -34,8 +34,6 @@ void Title_PrintBuildInfo(Gfx** gfxp) { //if tag is empty (not a release build) bool showGitInfo = gGitCommitTag[0] == 0; - GfxPrint_SetPos(&printer, 1, showGitInfo ? 23 : 25); - GfxPrint_Printf(&printer, "%s", gBuildVersion); if (showGitInfo) { GfxPrint_SetPos(&printer, 1, 24); GfxPrint_Printf(&printer, "Git Branch: %s", gGitBranch); @@ -47,6 +45,9 @@ void Title_PrintBuildInfo(Gfx** gfxp) { GfxPrint_SetPos(&printer, 1, 25); GfxPrint_Printf(&printer, "Git Commit: %s", gGitCommitHashTruncated); + } else { + GfxPrint_SetPos(&printer, 1, 25); + GfxPrint_Printf(&printer, "%s", gBuildVersion); } GfxPrint_SetPos(&printer, 1, 26); GfxPrint_Printf(&printer, "%s", gBuildDate);