diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d200a2d7..64975a34b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,37 @@ include(CMake/lus-cvars.cmake) set(PROJECT_BUILD_NAME "MacReady Golf" CACHE STRING "" FORCE) set(PROJECT_TEAM "github.com/harbourmasters" CACHE STRING "" FORCE) +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) + +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 2c226f2c6..692d1b2f8 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -49,7 +49,10 @@ extern "C" extern u16 gBuildVersionMajor; extern u16 gBuildVersionMinor; extern u16 gBuildVersionPatch; - extern u8 gBuildTeam[]; + extern u8 gGitBranch[]; + extern u8 gGitCommitHash[]; + extern u8 gGitCommitTag[]; + 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 14f0714ff..c4a535f12 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 61eb88a6f..93cb672e3 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -437,7 +437,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); + //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); } else { diff --git a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp index 235996273..d03c735e6 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 456e07eaa..6e41eb7a8 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -340,7 +340,7 @@ OTRGlobals::OTRGlobals() { 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, "Texture", static_cast(LUS::ResourceType::Texture), 0); diff --git a/soh/src/boot/build.c.in b/soh/src/boot/build.c.in index 4d6a07ce6..4467d04c8 100644 --- a/soh/src/boot/build.c.in +++ b/soh/src/boot/build.c.in @@ -5,6 +5,10 @@ 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 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 51d0ac62b..8893d9d5f 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" @@ -30,8 +31,24 @@ void Title_PrintBuildInfo(Gfx** gfxp) { GfxPrint_Open(&printer, g); GfxPrint_SetColor(&printer, 131, 154, 255, 255); - GfxPrint_SetPos(&printer, 1, 25); - GfxPrint_Printf(&printer, "%s", gBuildVersion); + //if tag is empty (not a release build) + bool showGitInfo = gGitCommitTag[0] == 0; + + if (showGitInfo) { + GfxPrint_SetPos(&printer, 1, 24); + GfxPrint_Printf(&printer, "Git Branch: %s", gGitBranch); + + //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); + } else { + GfxPrint_SetPos(&printer, 1, 25); + GfxPrint_Printf(&printer, "%s", gBuildVersion); + } GfxPrint_SetPos(&printer, 1, 26); GfxPrint_Printf(&printer, "%s", gBuildDate);