forked from supabitapp/supacode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
141 lines (125 loc) · 6.64 KB
/
Makefile
File metadata and controls
141 lines (125 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Sensible defaults
.ONESHELL:
SHELL := bash
.SHELLFLAGS := -e -u -c -o pipefail
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# Derived values (DO NOT TOUCH).
GHOSTTY_XCFRAMEWORK_PATH := Frameworks/GhosttyKit.xcframework
GHOSTTY_RESOURCE_PATH := Resources/ghostty
GHOSTTY_TERMINFO_PATH := Resources/terminfo
GHOSTTY_BUILD_OUTPUTS := $(GHOSTTY_XCFRAMEWORK_PATH) $(GHOSTTY_RESOURCE_PATH) $(GHOSTTY_TERMINFO_PATH)
PROJECT_FILE_PATH := supacode.xcodeproj/project.pbxproj
SPM_CACHE_DIR := /tmp/supacode-spm-cache/SourcePackages
VERSION ?=
BUILD ?=
XCODEBUILD_FLAGS ?=
.DEFAULT_GOAL := help
.PHONY: build-ghostty-xcframework build-app run-app install-dev-build archive export-archive format lint check test bump-version bump-and-release log-stream
help: # Display this help.
@-+echo "Run make with one of the following targets:"
@-+echo
@-+grep -Eh "^[a-z-]+:.*#" Makefile | sed -E 's/^(.*:)(.*#+)(.*)/ \1 @@@ \3 /' | column -t -s "@@@"
build-ghostty-xcframework: $(GHOSTTY_BUILD_OUTPUTS) # Build ghostty framework
$(GHOSTTY_BUILD_OUTPUTS):
@cd ThirdParty/ghostty && mise exec -- zig build -Doptimize=ReleaseFast -Demit-xcframework=true -Dsentry=false
rsync -a ThirdParty/ghostty/macos/GhosttyKit.xcframework Frameworks
@src="ThirdParty/ghostty/zig-out/share/ghostty"; \
dst="$(GHOSTTY_RESOURCE_PATH)"; \
terminfo_src="ThirdParty/ghostty/zig-out/share/terminfo"; \
terminfo_dst="$(GHOSTTY_TERMINFO_PATH)"; \
mkdir -p "$$dst"; \
rsync -a --delete "$$src/" "$$dst/"; \
mkdir -p "$$terminfo_dst"; \
rsync -a --delete "$$terminfo_src/" "$$terminfo_dst/"
build-app: build-ghostty-xcframework # Build the macOS app (Debug)
bash -o pipefail -c 'xcodebuild -project supacode.xcodeproj -scheme supacode -configuration Debug build -skipMacroValidation -clonedSourcePackagesDirPath "$(SPM_CACHE_DIR)" 2>&1 | mise exec -- xcsift -qw --format toon'
run-app: build-app # Build then launch (Debug) with log streaming
@settings="$$(xcodebuild -project supacode.xcodeproj -scheme supacode -configuration Debug -showBuildSettings -json 2>/dev/null)"; \
build_dir="$$(echo "$$settings" | jq -r '.[0].buildSettings.BUILT_PRODUCTS_DIR')"; \
product="$$(echo "$$settings" | jq -r '.[0].buildSettings.FULL_PRODUCT_NAME')"; \
exec_name="$$(echo "$$settings" | jq -r '.[0].buildSettings.EXECUTABLE_NAME')"; \
"$$build_dir/$$product/Contents/MacOS/$$exec_name"
install-dev-build: build-app # install dev build to /Applications
@settings="$$(xcodebuild -project supacode.xcodeproj -scheme supacode -configuration Debug -showBuildSettings -json 2>/dev/null)"; \
build_dir="$$(echo "$$settings" | jq -r '.[0].buildSettings.BUILT_PRODUCTS_DIR')"; \
product="$$(echo "$$settings" | jq -r '.[0].buildSettings.FULL_PRODUCT_NAME')"; \
src="$$build_dir/$$product"; \
dst="/Applications/$$product"; \
if [ ! -d "$$src" ]; then \
echo "app not found: $$src"; \
exit 1; \
fi; \
echo "copying $$src -> $$dst"; \
rm -rf "$$dst"; \
ditto "$$src" "$$dst"; \
echo "installed $$dst"
archive: build-ghostty-xcframework # Archive Release build for distribution
bash -o pipefail -c 'xcodebuild -project supacode.xcodeproj -scheme supacode -configuration Release -archivePath build/supacode.xcarchive archive CODE_SIGN_STYLE=Manual DEVELOPMENT_TEAM="$$APPLE_TEAM_ID" CODE_SIGN_IDENTITY="$$DEVELOPER_ID_IDENTITY_SHA" OTHER_CODE_SIGN_FLAGS="--timestamp" -skipMacroValidation -clonedSourcePackagesDirPath "$(SPM_CACHE_DIR)" $(XCODEBUILD_FLAGS) 2>&1 | mise exec -- xcsift -qw --format toon'
export-archive: # Export xarchive
bash -o pipefail -c 'xcodebuild -exportArchive -archivePath build/supacode.xcarchive -exportPath build/export -exportOptionsPlist build/ExportOptions.plist 2>&1 | mise exec -- xcsift -qw --format toon'
test: build-ghostty-xcframework
xcodebuild test -project supacode.xcodeproj -scheme supacode -destination "platform=macOS" CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" -skipMacroValidation -parallel-testing-enabled NO -clonedSourcePackagesDirPath "$(SPM_CACHE_DIR)" 2>&1
format: # Format code with swift-format (local only)
swift-format -p --in-place --recursive --configuration ./.swift-format.json supacode supacodeTests
lint: # Lint code with swiftlint
mise exec -- swiftlint --fix --quiet
mise exec -- swiftlint lint --quiet --config .swiftlint.yml
check: format lint # Format and lint
log-stream: # Stream logs from the app via log stream
log stream --predicate 'subsystem == "app.supabit.supacode"' --style compact --color always
bump-version: # Bump app version (usage: make bump-version [VERSION=x.x.x] [BUILD=123])
@if [ -z "$(VERSION)" ]; then \
current="$$(/usr/bin/awk -F' = ' '/MARKETING_VERSION = [0-9.]+;/{gsub(/;/,"",$$2);print $$2; exit}' "$(PROJECT_FILE_PATH)")"; \
if [ -z "$$current" ]; then \
echo "error: MARKETING_VERSION not found"; \
exit 1; \
fi; \
major="$$(echo "$$current" | cut -d. -f1)"; \
minor="$$(echo "$$current" | cut -d. -f2)"; \
patch="$$(echo "$$current" | cut -d. -f3)"; \
version="$$major.$$minor.$$((patch + 1))"; \
else \
if ! echo "$(VERSION)" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \
echo "error: VERSION must be in x.x.x format"; \
exit 1; \
fi; \
version="$(VERSION)"; \
fi; \
if [ -z "$(BUILD)" ]; then \
build="$$(/usr/bin/awk -F' = ' '/CURRENT_PROJECT_VERSION = [0-9]+;/{gsub(/;/,"",$$2);print $$2; exit}' "$(PROJECT_FILE_PATH)")"; \
if [ -z "$$build" ]; then \
echo "error: CURRENT_PROJECT_VERSION not found"; \
exit 1; \
fi; \
build="$$((build + 1))"; \
else \
if ! echo "$(BUILD)" | grep -qE '^[0-9]+$$'; then \
echo "error: BUILD must be an integer"; \
exit 1; \
fi; \
build="$(BUILD)"; \
fi; \
sed -i '' "s/MARKETING_VERSION = [0-9.]*;/MARKETING_VERSION = $$version;/g" \
"$(PROJECT_FILE_PATH)"; \
sed -i '' "s/CURRENT_PROJECT_VERSION = [0-9]*;/CURRENT_PROJECT_VERSION = $$build;/g" \
"$(PROJECT_FILE_PATH)"; \
git add "$(PROJECT_FILE_PATH)"; \
git commit -m "bump v$$version"; \
git tag -s "v$$version" -m "v$$version"; \
echo "version bumped to $$version (build $$build), tagged v$$version"
bump-and-release: bump-version # Bump version and push tags to trigger release
git push --follow-tags
@tag="$$(git describe --tags --abbrev=0)"; \
repo="$$(gh repo view --json nameWithOwner -q .nameWithOwner)"; \
prev="$$(gh release view --json tagName -q .tagName 2>/dev/null || echo '')"; \
tmp="$$(mktemp)"; \
if [ -n "$$prev" ]; then \
gh api "repos/$$repo/releases/generate-notes" -f tag_name="$$tag" -f previous_tag_name="$$prev" --jq '.body' > "$$tmp"; \
else \
gh api "repos/$$repo/releases/generate-notes" -f tag_name="$$tag" --jq '.body' > "$$tmp"; \
fi; \
$${EDITOR:-vim} "$$tmp"; \
gh release create "$$tag" --notes-file "$$tmp"; \
rm -f "$$tmp"