Skip to content

Commit 085b61b

Browse files
committed
truncate the commit hash inside the c code
1 parent bdbf6a8 commit 085b61b

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

macos/makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ ifeq ($(VERSION),)
66
VERSION = unknown
77
endif
88

9-
SUB_VERSION := $(if $(GITHUB_SHA),$(shell echo $(GITHUB_SHA) | cut -c1-7),unknown)
9+
COMMIT_HASH := $(if $(GITHUB_SHA),$(GITHUB_SHA),unknown)
1010

1111
APP_MANIFEST = src/Info.plist
1212
APP_BUNDLE = $(APP_NAME).app
1313
APP_EXE = $(APP_NAME)
1414

1515
CC = clang++
16-
CFLAGS = -std=c++17 -Wall -mmacosx-version-min=11.0 -arch x86_64 -arch arm64 -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"'
16+
CFLAGS = -std=c++17 -Wall -mmacosx-version-min=11.0 -arch x86_64 -arch arm64 -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DCOMMIT_HASH='"$(COMMIT_HASH)"'
1717
LFLAGS = -mmacosx-version-min=11.0
1818
INCS = -I../external/sdl/build/include/ -I../external/imgui/ -I../shared/
1919
LIBS = -L../external/sdl/build/lib/ -lSDL2-2.0.0 -framework Cocoa -framework OpenGL
@@ -63,7 +63,7 @@ $(BOOTROM_HEADER): $(BOOTROM_SOURCE)
6363

6464
# Generate Info.plist from template with version substitution
6565
$(APP_MANIFEST): $(APP_MANIFEST).in
66-
sed -e 's/@APP_NAME@/$(APP_NAME)/g' -e 's/@VERSION@/$(VERSION)/g' -e 's/@SUB_VERSION@/$(SUB_VERSION)/g' $< > $@
66+
sed -e 's/@APP_NAME@/$(APP_NAME)/g' -e 's/@VERSION@/$(VERSION)/g' -e 's/@COMMIT_HASH@/$(COMMIT_HASH)/g' $< > $@
6767

6868
# Pattern rules for incremental compilation
6969
%.o: ../shared/%.cc $(LICENSE_HEADER) $(BOOTROM_HEADER)

shared/Chip8.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#define VERSION "unknown"
1919
#endif
2020

21-
// SUB_VERSION is defined by the compiler via -DSUB_VERSION="..."
21+
// COMMIT_HASH is defined by the compiler via -DCOMMIT_HASH="..."
2222
// Falls back to generic name if not defined (shouldn't happen in normal builds)
23-
#ifndef SUB_VERSION
24-
#define SUB_VERSION "unknown"
23+
#ifndef COMMIT_HASH
24+
#define COMMIT_HASH "unknown"
2525
#endif
2626

2727
#define MEM_SIZE 4096

shared/Gui.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,18 @@ void Gui::HelpWindows() {
220220
ImGui::SetNextWindowPosCenter(ImGuiSetCond_Appearing);
221221
ImGui::Begin("About", &show_about);
222222

223+
// Truncate COMMIT_HASH to first 7 characters for display
224+
char short_hash[8];
225+
snprintf(short_hash, sizeof(short_hash), "%.7s", COMMIT_HASH);
226+
223227
ImGui::TextWrapped(
224-
APP_NAME " " VERSION " (" SUB_VERSION ")\n"
228+
APP_NAME " " VERSION " (%s)\n"
225229
"\n"
226230
"A cross-platform Chip-8 interpreter written\n"
227231
"in C-Style C++ using SDL2, ImGui, and OpenGL.\n"
228232
"\n"
229-
"<https://github.com/Diesel-Net/kiwi-8>\n"
233+
"<https://github.com/Diesel-Net/kiwi-8>\n",
234+
short_hash
230235
);
231236

232237
ImGui::End();

windows/makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ VERSION = unknown
88
!ENDIF
99

1010
!IFDEF GITHUB_SHA
11-
# Extract first 7 characters of GITHUB_SHA
12-
SUB_VERSION = $(GITHUB_SHA:~0,7)
11+
COMMIT_HASH = $(GITHUB_SHA)
1312
!ELSE
14-
SUB_VERSION = unknown
13+
COMMIT_HASH = unknown
1514
!ENDIF
1615

1716
APP_EXE = $(APP_NAME).exe
1817
APP_PDB = $(APP_NAME).pdb
1918
APP_RES = $(APP_NAME).res
2019

2120
CC = CL
22-
CFLAGS = /std:c++17 /W4 /MD /nologo /w44996 "/DAPP_NAME=\"$(APP_NAME)\"" "/DVERSION=\"$(VERSION)\"" "/DSUB_VERSION=\"$(SUB_VERSION)\""
21+
CFLAGS = /std:c++17 /W4 /MD /nologo /w44996 "/DAPP_NAME=\"$(APP_NAME)\"" "/DVERSION=\"$(VERSION)\"" "/DCOMMIT_HASH=\"$(COMMIT_HASH)\""
2322
LFLAGS = /link \
2423
/LIBPATH:..\external\sdl\build\lib \
2524
/ENTRY:mainCRTStartup

0 commit comments

Comments
 (0)