Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git info to title screen & gameplay stats #4053

Merged
merged 8 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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($<$<CXX_COMPILER_ID:MSVC>:/MP>)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
Expand Down
5 changes: 4 additions & 1 deletion soh/include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/CrashHandlerExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion soh/soh/Enhancements/gameplaystats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LUS::ResourceFactoryBinaryTextureV0>(), RESOURCE_FORMAT_BINARY, "Texture", static_cast<uint32_t>(LUS::ResourceType::Texture), 0);
Expand Down
4 changes: 4 additions & 0 deletions soh/src/boot/build.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = "";
21 changes: 19 additions & 2 deletions soh/src/overlays/gamestates/ovl_title/z_title.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <soh/Enhancements/bootcommands.h>
#include <GameVersions.h>
#include <soh/SaveManager.h>
#include <string.h>

#include "time.h"

Expand All @@ -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);

Expand Down
Loading