Skip to content

Commit bdbf6a8

Browse files
committed
stop trying to get git branch and commit hash locally... it adds too much complexity for such a small task. just use CI magic vars and use sensible defaults where applicable
1 parent a4bb829 commit bdbf6a8

File tree

5 files changed

+30
-42
lines changed

5 files changed

+30
-42
lines changed

macos/makefile

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
APP_NAME = Kiwi8
22

3-
# Auto-detect version: use GITHUB_REF_NAME if set (CI), else git describe, else git branch
4-
ifeq ($(origin GITHUB_REF_NAME), environment)
5-
VERSION := $(GITHUB_REF_NAME)
6-
else
7-
VERSION := $(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
3+
# Use GITHUB_REF_NAME from GitHub Actions, or default values for local builds
4+
VERSION ?= $(GITHUB_REF_NAME)
5+
ifeq ($(VERSION),)
6+
VERSION = unknown
87
endif
98

10-
# CFBundleVersion: Use git commit hash (unique identifier)
11-
COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
9+
SUB_VERSION := $(if $(GITHUB_SHA),$(shell echo $(GITHUB_SHA) | cut -c1-7),unknown)
1210

13-
APP_NAME_VERSION = $(APP_NAME) $(VERSION)
1411
APP_MANIFEST = src/Info.plist
1512
APP_BUNDLE = $(APP_NAME).app
1613
APP_EXE = $(APP_NAME)
1714

1815
CC = clang++
19-
CFLAGS = -std=c++17 -Wall -mmacosx-version-min=11.0 -arch x86_64 -arch arm64 -MMD -MP -DAPP_NAME_VERSION='"$(APP_NAME_VERSION)"' -DCOMMIT_HASH='"$(COMMIT_HASH)"'
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)"'
2017
LFLAGS = -mmacosx-version-min=11.0
2118
INCS = -I../external/sdl/build/include/ -I../external/imgui/ -I../shared/
2219
LIBS = -L../external/sdl/build/lib/ -lSDL2-2.0.0 -framework Cocoa -framework OpenGL
@@ -66,7 +63,7 @@ $(BOOTROM_HEADER): $(BOOTROM_SOURCE)
6663

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

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

macos/src/Info.plist.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleExecutable</key>
6-
<string>Kiwi8</string>
6+
<string>@APP_NAME@</string>
77
<key>CFBundleIdentifier</key>
88
<string>net.kiwi-labs.kiwi8</string>
99
<key>CFBundleIconFile</key>
@@ -15,7 +15,7 @@
1515
<key>CFBundleShortVersionString</key>
1616
<string>@VERSION@</string>
1717
<key>CFBundleVersion</key>
18-
<string>@COMMIT_HASH@</string>
18+
<string>@SUB_VERSION@</string>
1919
<key>LSMinimumSystemVersion</key>
2020
<string>11.0</string>
2121
<key>NSHighResolutionCapable</key>

shared/Chip8.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66
#include "Input.h"
77
#include "Audio.h"
88

9-
// APP_NAME_VERSION is defined by the compiler via -DAPP_NAME_VERSION="..."
9+
// APP_NAME is defined by the compiler via -DAPP_NAME="..."
1010
// Falls back to generic name if not defined (shouldn't happen in normal builds)
11-
#ifndef APP_NAME_VERSION
12-
#define APP_NAME_VERSION "Kiwi8"
11+
#ifndef APP_NAME
12+
#define APP_NAME "Kiwi8"
1313
#endif
1414

15-
// COMMIT_HASH is defined by the compiler via -DCOMMIT_HASH="..."
15+
// VERSION is defined by the compiler via -DVERSION="..."
16+
// Falls back to unknown if not defined (shouldn't happen in normal builds)
17+
#ifndef VERSION
18+
#define VERSION "unknown"
19+
#endif
20+
21+
// SUB_VERSION is defined by the compiler via -DSUB_VERSION="..."
1622
// Falls back to generic name if not defined (shouldn't happen in normal builds)
17-
#ifndef COMMIT_HASH
18-
#define COMMIT_HASH "unknown"
23+
#ifndef SUB_VERSION
24+
#define SUB_VERSION "unknown"
1925
#endif
2026

2127
#define MEM_SIZE 4096

shared/Gui.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void Gui::HelpWindows() {
221221
ImGui::Begin("About", &show_about);
222222

223223
ImGui::TextWrapped(
224-
APP_NAME_VERSION " (" COMMIT_HASH ")\n"
224+
APP_NAME " " VERSION " (" SUB_VERSION ")\n"
225225
"\n"
226226
"A cross-platform Chip-8 interpreter written\n"
227227
"in C-Style C++ using SDL2, ImGui, and OpenGL.\n"

windows/makefile

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,25 @@
11
APP_NAME = Kiwi8
22

3-
# Auto-detect version: use GITHUB_REF_NAME if set (CI), else git describe, else git branch
4-
!IFNDEF GITHUB_REF_NAME
5-
# Try git describe for exact tag match
6-
!IF [git describe --tags --exact-match > .version.tmp 2>nul] == 0
7-
!INCLUDE .version.tmp
8-
# Try git branch name
9-
!ELSE IF [git rev-parse --abbrev-ref HEAD > .version.tmp 2>nul] == 0
10-
!INCLUDE .version.tmp
3+
# Use GITHUB_REF_NAME from GitHub Actions, or default values for local builds
4+
!IFDEF GITHUB_REF_NAME
5+
VERSION = $(GITHUB_REF_NAME)
116
!ELSE
127
VERSION = unknown
138
!ENDIF
14-
# Clean up temp file
15-
!IF [del .version.tmp 2>nul]
16-
!ENDIF
17-
!ELSE
18-
VERSION = $(GITHUB_REF_NAME)
19-
!ENDIF
209

21-
# Git commit hash (unique identifier for build)
22-
!IF [git rev-parse --short HEAD > .hash.tmp 2>nul && echo COMMIT_HASH = > .commit.tmp && type .hash.tmp >> .commit.tmp] == 0
23-
!INCLUDE .commit.tmp
10+
!IFDEF GITHUB_SHA
11+
# Extract first 7 characters of GITHUB_SHA
12+
SUB_VERSION = $(GITHUB_SHA:~0,7)
2413
!ELSE
25-
COMMIT_HASH = unknown
26-
!ENDIF
27-
# Clean up temp files
28-
!IF [del .hash.tmp .commit.tmp 2>nul]
14+
SUB_VERSION = unknown
2915
!ENDIF
3016

31-
APP_NAME_VERSION = $(APP_NAME) $(VERSION)
3217
APP_EXE = $(APP_NAME).exe
3318
APP_PDB = $(APP_NAME).pdb
3419
APP_RES = $(APP_NAME).res
3520

3621
CC = CL
37-
CFLAGS = /std:c++17 /W4 /MD /nologo /w44996 "/DAPP_NAME_VERSION=\"$(APP_NAME_VERSION)\"" "/DCOMMIT_HASH=\"$(COMMIT_HASH)\""
22+
CFLAGS = /std:c++17 /W4 /MD /nologo /w44996 "/DAPP_NAME=\"$(APP_NAME)\"" "/DVERSION=\"$(VERSION)\"" "/DSUB_VERSION=\"$(SUB_VERSION)\""
3823
LFLAGS = /link \
3924
/LIBPATH:..\external\sdl\build\lib \
4025
/ENTRY:mainCRTStartup

0 commit comments

Comments
 (0)