forked from supabitapp/supacode
-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathMakefile
More file actions
423 lines (390 loc) · 19.3 KB
/
Copy pathMakefile
File metadata and controls
423 lines (390 loc) · 19.3 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# 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).
CURRENT_MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_MAKEFILE_DIR := $(patsubst %/,%,$(dir $(CURRENT_MAKEFILE_PATH)))
GHOSTTY_XCFRAMEWORK_PATH := $(CURRENT_MAKEFILE_DIR)/Frameworks/GhosttyKit.xcframework
GHOSTTY_RESOURCE_PATH := $(CURRENT_MAKEFILE_DIR)/Resources/ghostty
GHOSTTY_TERMINFO_PATH := $(CURRENT_MAKEFILE_DIR)/Resources/terminfo
GHOSTTY_BUILD_OUTPUTS := $(GHOSTTY_XCFRAMEWORK_PATH) $(GHOSTTY_RESOURCE_PATH) $(GHOSTTY_TERMINFO_PATH)
GHOSTTY_BUILD_STAMP := $(CURRENT_MAKEFILE_DIR)/.ghostty_build_stamp
GHOSTTY_HASH_FILE := $(CURRENT_MAKEFILE_DIR)/.ghostty_hash
SPM_CACHE_DIR := $(HOME)/Library/Caches/supacode-spm-cache/SourcePackages
CLI_DEBUG_RESOURCE_PATH := $(CURRENT_MAKEFILE_DIR)/Resources/prowl-cli/prowl
CLI_SOURCE_DIRS := $(CURRENT_MAKEFILE_DIR)/ProwlCLI $(CURRENT_MAKEFILE_DIR)/supacode/CLIService/Shared
CLI_SOURCE_INPUTS := \
$(CURRENT_MAKEFILE_PATH) \
$(CURRENT_MAKEFILE_DIR)/Package.swift \
$(CURRENT_MAKEFILE_DIR)/Package.resolved \
$(CURRENT_MAKEFILE_DIR)/supacode.xcodeproj/project.pbxproj \
$(shell find $(CLI_SOURCE_DIRS) -type f 2>/dev/null)
VERSION ?=
BUILD ?=
XCODEBUILD_FLAGS ?=
FORMAT_BASE_REF ?= origin/main
BUILD_SETTINGS_CACHE := $(CURRENT_MAKEFILE_DIR)/.build_settings_cache.json
PBXPROJ_PATH := $(CURRENT_MAKEFILE_DIR)/supacode.xcodeproj/project.pbxproj
# Release-only analytics/crash credentials. Included from Config/Secrets.env if present,
# or overridable from the environment (e.g. CI). Debug builds skip SDK init regardless.
-include Config/Secrets.env
PROWL_SENTRY_DSN ?=
PROWL_POSTHOG_API_KEY ?=
PROWL_POSTHOG_HOST ?=
.DEFAULT_GOAL := help
.PHONY: build-ghostty-xcframework ensure-ghostty sync-ghostty _record-ghostty-hash build-app build-cli build-cli-release embed-cli-debug embed-cli embed-docs run-app install-dev-build install-release archive export-archive format format-changed format-lint lint check test test-app test-cli-smoke test-cli-integration bump-version log-stream
help: # Display this help.
@-+echo "Run make with one of the following targets:"
@-+echo
@-+grep -Eh "^[a-z-]+:.*#" $(CURRENT_MAKEFILE_PATH) | sed -E 's/^(.*:)(.*#+)(.*)/ \1 @@@ \3 /' | column -t -s "@@@"
build-ghostty-xcframework: $(GHOSTTY_BUILD_STAMP) # Build ghostty framework
@$(MAKE) _record-ghostty-hash
# Internal: actually rebuild ghostty.
$(GHOSTTY_BUILD_STAMP):
git submodule update --init --recursive ThirdParty/ghostty
@cd $(CURRENT_MAKEFILE_DIR)/ThirdParty/ghostty && mise exec -- zig build -Doptimize=ReleaseFast -Demit-xcframework=true -Dsentry=false
rsync -a ThirdParty/ghostty/macos/GhosttyKit.xcframework Frameworks
@src="$(CURRENT_MAKEFILE_DIR)/ThirdParty/ghostty/zig-out/share/ghostty"; \
dst="$(GHOSTTY_RESOURCE_PATH)"; \
terminfo_src="$(CURRENT_MAKEFILE_DIR)/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/"
touch "$(GHOSTTY_BUILD_STAMP)"
# Public entry point: downloads pinned prebuilt artifacts when available, then
# falls back to a local Ghostty source build.
ensure-ghostty: # Ensure GhosttyKit is up-to-date (fast path when unchanged)
@set +e; \
"$(CURRENT_MAKEFILE_DIR)/scripts/ensure-ghosttykit-artifacts.sh"; \
status="$$?"; \
set -e; \
if [ "$$status" -eq 0 ]; then \
exit 0; \
fi; \
if [ "$$status" -ne 2 ]; then \
exit "$$status"; \
fi; \
current_sha="$$(git -C "$(CURRENT_MAKEFILE_DIR)" rev-parse HEAD:ThirdParty/ghostty)"; \
last_sha=""; \
if [ -f "$(GHOSTTY_HASH_FILE)" ]; then \
last_sha="$$(cat "$(GHOSTTY_HASH_FILE)")"; \
fi; \
echo "Building GhosttyKit locally for $$current_sha"; \
$(MAKE) -B build-ghostty-xcframework; \
if [ "$$current_sha" != "$$last_sha" ]; then \
rm -rf ~/Library/Developer/Xcode/DerivedData/supacode-*; \
echo "Cleared Xcode DerivedData for ghostty header/module changes"; \
fi
# Internal: record the current submodule SHA after a successful build.
_record-ghostty-hash:
@git -C "$(CURRENT_MAKEFILE_DIR)" rev-parse HEAD:ThirdParty/ghostty > "$(GHOSTTY_HASH_FILE)"
# Force a clean rebuild of GhosttyKit (ignores cached SHA, useful after submodule updates).
sync-ghostty: # Force sync GhosttyKit to current submodule HEAD (always rebuilds)
@echo "Forcing GhosttyKit rebuild..."
$(MAKE) -B build-ghostty-xcframework
rm -rf ~/Library/Developer/Xcode/DerivedData/supacode-*
@echo "Done. Xcode module cache cleared for fresh compilation."
embed-docs: # Stage docs/ into Resources for bundling into the app (.app/Contents/Resources/docs)
@set -euo pipefail; \
src="$(CURRENT_MAKEFILE_DIR)/docs"; \
dst="$(CURRENT_MAKEFILE_DIR)/Resources/docs"; \
mkdir -p "$$dst"; \
rsync -a --delete --exclude '.sync-meta.json' "$$src/" "$$dst/"; \
echo "embedded docs at $$dst"
build-app: ensure-ghostty embed-cli-debug embed-docs # Build the macOS app (Debug)
bash -o pipefail -c 'xcodebuild -project supacode.xcodeproj -scheme supacode -configuration Debug build -skipMacroValidation -clonedSourcePackagesDirPath $(SPM_CACHE_DIR) SWIFT_COMPILATION_MODE=incremental 2>&1 | mise exec -- xcsift -w --format toon'
sync-cli-version: # Sync app MARKETING_VERSION into ProwlCLIShared/ProwlVersion.swift
@version="$$(/usr/bin/awk -F' = ' '/MARKETING_VERSION = [0-9.]*;/{gsub(/;/,"",$$2);print $$2; exit}' \
"$(CURRENT_MAKEFILE_DIR)/supacode.xcodeproj/project.pbxproj")"; \
dst="$(CURRENT_MAKEFILE_DIR)/supacode/CLIService/Shared/ProwlVersion.swift"; \
tmp="$$(mktemp)"; \
trap 'rm -f "$$tmp"' EXIT; \
printf '// Auto-generated by Makefile (sync-cli-version). Do not edit.\n\npublic enum ProwlVersion {\n public static let current = "%s"\n}\n' "$$version" > "$$tmp"; \
if [ ! -f "$$dst" ] || ! cmp -s "$$tmp" "$$dst"; then \
mv "$$tmp" "$$dst"; \
echo "synced CLI version $$version"; \
fi
build-cli: sync-cli-version # Build Swift CLI binary (SPM)
swift build --product prowl
build-cli-release: sync-cli-version # Build universal CLI binary in release mode
swift build -c release --arch arm64 --arch x86_64 --product prowl
embed-cli-debug: $(CLI_DEBUG_RESOURCE_PATH) # Build debug CLI and copy into Resources for dev builds
$(CLI_DEBUG_RESOURCE_PATH): $(CLI_SOURCE_INPUTS)
$(MAKE) build-cli
@set -euo pipefail; \
bin="$$(swift build --show-bin-path)/prowl"; \
dst="$(CURRENT_MAKEFILE_DIR)/Resources/prowl-cli"; \
mkdir -p "$$dst"; \
if [ ! -f "$$dst/prowl" ] || ! cmp -s "$$bin" "$$dst/prowl"; then \
cp "$$bin" "$$dst/prowl"; \
else \
touch "$$dst/prowl"; \
fi; \
chmod +x "$$dst/prowl"; \
echo "embedded CLI binary at $$dst/prowl"
embed-cli: build-cli-release # Build release CLI and copy into Resources for distribution
@set -euo pipefail; \
bin="$$(swift build -c release --arch arm64 --arch x86_64 --show-bin-path)/prowl"; \
dst="$(CURRENT_MAKEFILE_DIR)/Resources/prowl-cli"; \
mkdir -p "$$dst"; \
cp "$$bin" "$$dst/prowl"; \
chmod +x "$$dst/prowl"; \
echo "embedded CLI binary at $$dst/prowl"
run-app: build-app # Build then launch (Debug) with log streaming
@set -euo pipefail; \
cache="$(BUILD_SETTINGS_CACHE)"; \
pbxproj="$(PBXPROJ_PATH)"; \
if [ -f "$$cache" ] && [ "$$cache" -nt "$$pbxproj" ]; then \
settings="$$(cat "$$cache")"; \
else \
settings="$$(xcodebuild -project supacode.xcodeproj -scheme supacode -configuration Debug -showBuildSettings -json 2>/dev/null)"; \
printf '%s' "$$settings" > "$$cache"; \
fi; \
build_dir="$$(echo "$$settings" | jq -er '.[0].buildSettings.BUILT_PRODUCTS_DIR')"; \
product="$$(echo "$$settings" | jq -er '.[0].buildSettings.FULL_PRODUCT_NAME')"; \
exec_name="$$(echo "$$settings" | jq -r '.[0].buildSettings.EXECUTABLE_NAME')"; \
if [ -z "$$build_dir" ] || [ -z "$$product" ] || [ "$$build_dir" = "null" ] || [ "$$product" = "null" ] || [ -z "$$exec_name" ] || [ "$$exec_name" = "null" ]; then \
echo "error: failed to resolve app path from build settings"; \
exit 1; \
fi; \
app_path="$$build_dir/$$product/Contents/MacOS/$$exec_name"; \
"$$app_path"
install-dev-build: build-app # Build Debug and install to /Applications
@set -euo pipefail; \
cache="$(BUILD_SETTINGS_CACHE)"; \
pbxproj="$(PBXPROJ_PATH)"; \
if [ -f "$$cache" ] && [ "$$cache" -nt "$$pbxproj" ]; then \
settings="$$(cat "$$cache")"; \
else \
settings="$$(xcodebuild -project supacode.xcodeproj -scheme supacode -configuration Debug -showBuildSettings -json 2>/dev/null)"; \
printf '%s' "$$settings" > "$$cache"; \
fi; \
build_dir="$$(echo "$$settings" | jq -er '.[0].buildSettings.BUILT_PRODUCTS_DIR')"; \
product="$$(echo "$$settings" | jq -er '.[0].buildSettings.FULL_PRODUCT_NAME')"; \
if [ -z "$$build_dir" ] || [ -z "$$product" ] || [ "$$build_dir" = "null" ] || [ "$$product" = "null" ]; then \
echo "error: failed to resolve app path from build settings"; \
exit 1; \
fi; \
if [ "$$product" != "$$(basename "$$product")" ]; then \
echo "error: invalid product name (contains path separators): $$product"; \
exit 1; \
fi; \
if [[ "$$product" != *.app ]]; then \
echo "error: unexpected product name: $$product"; \
exit 1; \
fi; \
src="$$build_dir/$$product"; \
dst="/Applications/$$product"; \
dst_parent="$$(cd "$$(dirname "$$dst")" && pwd -P)"; \
if [ "$$dst_parent" != "/Applications" ]; then \
echo "error: refusing to install outside /Applications: $$dst"; \
exit 1; \
fi; \
if [ "$$src" = "/" ] || [ "$$dst" = "/Applications" ] || [ "$$dst" = "/Applications/" ]; then \
echo "error: unsafe install path (src=$$src, dst=$$dst)"; \
exit 1; \
fi; \
case "$$dst" in \
/Applications/*.app) ;; \
*) \
echo "error: refusing to install outside /Applications/*.app: $$dst"; \
exit 1; \
;; \
esac; \
if [ ! -d "$$src" ]; then \
echo "app not found: $$src"; \
exit 1; \
fi; \
if [ ! -d "$$src/Contents" ]; then \
echo "error: source is not an app bundle: $$src"; \
exit 1; \
fi; \
echo "copying $$src -> $$dst"; \
if [ -e "$$dst" ]; then \
if ! command -v trash >/dev/null 2>&1; then \
echo "error: trash command not found; refusing to remove $$dst"; \
exit 1; \
fi; \
echo "moving existing app to Trash: $$dst"; \
trash "$$dst"; \
fi; \
ditto "$$src" "$$dst"; \
echo "installed $$dst"
install-release: build-ghostty-xcframework # Build Release, sign locally, install to /Applications
@set -euo pipefail; \
SIGNING_IDENTITY="$$(security find-identity -v -p codesigning 2>/dev/null | awk -F'"' '/Developer ID Application/ {print $$2; exit}')"; \
if [ -z "$$SIGNING_IDENTITY" ]; then \
echo "error: no Developer ID Application identity found"; \
exit 1; \
fi; \
IDENTITY_SHA="$$(security find-identity -v -p codesigning 2>/dev/null | grep "$$SIGNING_IDENTITY" | head -1 | awk '{print $$2}')"; \
TEAM_ID="$$(echo "$$SIGNING_IDENTITY" | grep -oE '\([A-Z0-9]{10}\)$$' | tr -d '()')"; \
echo "identity: $$SIGNING_IDENTITY"; \
echo "team: $$TEAM_ID"; \
APPLE_TEAM_ID="$$TEAM_ID" DEVELOPER_ID_IDENTITY_SHA="$$IDENTITY_SHA" $(MAKE) archive; \
mkdir -p build; \
printf '%s\n' \
'<?xml version="1.0" encoding="UTF-8"?>' \
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' \
'<plist version="1.0">' \
'<dict>' \
' <key>method</key>' \
' <string>developer-id</string>' \
' <key>signingStyle</key>' \
' <string>manual</string>' \
' <key>signingCertificate</key>' \
" <string>$$SIGNING_IDENTITY</string>" \
' <key>teamID</key>' \
" <string>$$TEAM_ID</string>" \
'</dict>' \
'</plist>' > build/ExportOptions.plist; \
$(MAKE) export-archive; \
APP_PATH="$$(find build/export -name '*.app' -maxdepth 3 -print -quit)"; \
if [ ! -d "$$APP_PATH" ]; then \
echo "error: exported app not found"; \
exit 1; \
fi; \
SPARKLE="$$APP_PATH/Contents/Frameworks/Sparkle.framework/Versions/B"; \
if [ -d "$$SPARKLE" ]; then \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp -v "$$SPARKLE/XPCServices/Installer.xpc"; \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp --preserve-metadata=entitlements -v "$$SPARKLE/XPCServices/Downloader.xpc"; \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp -v "$$SPARKLE/Updater.app"; \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp -v "$$SPARKLE/Autoupdate"; \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp -v "$$SPARKLE/Sparkle"; \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp -v "$$APP_PATH/Contents/Frameworks/Sparkle.framework"; \
fi; \
SENTRY="$$APP_PATH/Contents/Frameworks/Sentry.framework"; \
if [ -d "$$SENTRY" ]; then \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp -v "$$SENTRY/Versions/A/Sentry"; \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp -v "$$SENTRY"; \
fi; \
codesign -f -s "$$IDENTITY_SHA" -o runtime --timestamp --preserve-metadata=entitlements,requirements,flags -v "$$APP_PATH"; \
codesign -vvv --deep --strict "$$APP_PATH"; \
PRODUCT="$$(basename "$$APP_PATH")"; \
if [ -z "$$PRODUCT" ] || [ "$$PRODUCT" = "." ] || [[ "$$PRODUCT" != *.app ]]; then \
echo "error: unexpected release product name: $$PRODUCT"; \
exit 1; \
fi; \
DST="/Applications/$$PRODUCT"; \
if [ "$$DST" = "/Applications" ] || [ "$$DST" = "/Applications/" ]; then \
echo "error: unsafe install destination: $$DST"; \
exit 1; \
fi; \
case "$$DST" in \
/Applications/*.app) ;; \
*) \
echo "error: refusing to install outside /Applications/*.app: $$DST"; \
exit 1; \
;; \
esac; \
echo "copying $$APP_PATH -> $$DST"; \
if [ -e "$$DST" ]; then \
if ! command -v trash >/dev/null 2>&1; then \
echo "error: trash command not found; refusing to remove $$DST"; \
exit 1; \
fi; \
echo "moving existing app to Trash: $$DST"; \
trash "$$DST"; \
fi; \
ditto "$$APP_PATH" "$$DST"; \
echo "installed $$DST (Release build, locally signed)"
archive: build-ghostty-xcframework embed-cli embed-docs # 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" PROWL_SENTRY_DSN="$(PROWL_SENTRY_DSN)" PROWL_POSTHOG_API_KEY="$(PROWL_POSTHOG_API_KEY)" PROWL_POSTHOG_HOST="$(PROWL_POSTHOG_HOST)" -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: ensure-ghostty embed-cli-debug embed-docs test-app
test-app: ensure-ghostty # Run app/unit tests via xcodebuild
@set -euo pipefail; \
result_bundle="$(CURRENT_MAKEFILE_DIR)/build/test-results/supacode-tests.xcresult"; \
mkdir -p "$$(dirname "$$result_bundle")"; \
rm -rf "$$result_bundle"; \
set +e; \
xcodebuild test -project supacode.xcodeproj -scheme supacode -destination "platform=macOS" -resultBundlePath "$$result_bundle" CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" -skipMacroValidation -clonedSourcePackagesDirPath $(SPM_CACHE_DIR) SWIFT_COMPILATION_MODE=incremental 2>&1 | mise exec -- xcsift -w --format toon; \
xcodebuild_status=$${PIPESTATUS[0]}; \
set -e; \
if [ "$$xcodebuild_status" -ne 0 ]; then \
bash "$(CURRENT_MAKEFILE_DIR)/scripts/print-xcresult-failures.sh" "$$result_bundle" || true; \
fi; \
exit "$$xcodebuild_status"
test-cli-smoke: build-cli # Smoke test CLI executable
@set -euo pipefail; \
bin="$$(swift build --show-bin-path)/prowl"; \
help_output="$$("$$bin" --help)"; \
version_output="$$("$$bin" --version)"; \
echo "$$help_output" | grep -q "USAGE:"; \
echo "$$version_output" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.]+)?$$'; \
socket="/tmp/prowl-cli-smoke-$$RANDOM.sock"; \
PROWL_CLI_SOCKET="$$socket" "$$bin" list --json >/tmp/prowl-cli-smoke.json || true; \
jq -e '.error.code == "APP_NOT_RUNNING"' /tmp/prowl-cli-smoke.json >/dev/null
test-cli-integration: # Run CLI integration tests via SwiftPM
swift test --filter ProwlCLIIntegrationTests
format: # Format all Swift code with swift-format (full-tree cleanup)
swift-format -p --in-place --recursive --configuration ./.swift-format.json supacode supacodeTests
format-changed: # Format Swift files changed from FORMAT_BASE_REF (default: origin/main)
@base="$$(git merge-base HEAD "$(FORMAT_BASE_REF)" 2>/dev/null || git rev-parse HEAD)"; \
mapfile -t files < <( \
{ \
git diff --name-only --diff-filter=ACMR "$$base" -- supacode supacodeTests; \
git ls-files --others --exclude-standard -- supacode supacodeTests; \
} | awk '/\.swift$$/' | sort -u \
); \
if [ "$${#files[@]}" -eq 0 ]; then \
echo "No changed Swift files to format."; \
else \
printf 'Formatting %s changed Swift file(s) from %s\n' "$${#files[@]}" "$$base"; \
swift-format -p --in-place --configuration ./.swift-format.json "$${files[@]}"; \
fi
format-lint: # Check Swift formatting without rewriting files
swift-format lint --strict --recursive --configuration ./.swift-format.json supacode supacodeTests
lint: # Lint code with swiftlint
mise exec -- swiftlint lint --quiet --config .swiftlint.yml
check: format-changed format-lint lint # Format changed Swift files, then run swift-format lint and SwiftLint
log-stream: # Stream logs from the app via log stream
log stream --predicate 'subsystem == "com.onevcat.prowl"' --style compact --color always
bump-version: # Bump app version (usage: make bump-version [VERSION=YYYY.M.DD] [BUILD=YYYYMMDD])
@if [ -z "$(VERSION)" ]; then \
version="$$(date +%Y.%-m.%-d)"; \
suffix=1; \
while git rev-parse "v$$version" >/dev/null 2>&1; do \
suffix=$$((suffix + 1)); \
version="$$(date +%Y.%-m.%-d).$$suffix"; \
done; \
else \
if ! echo "$(VERSION)" | grep -qE '^[0-9]{4}\.[0-9]{1,2}\.[0-9]{1,2}(\.[0-9]+)?$$'; then \
echo "error: VERSION must be in YYYY.M.DD or YYYY.M.DD.N format"; \
exit 1; \
fi; \
version="$(VERSION)"; \
fi; \
if [ -z "$(BUILD)" ]; then \
base_build="$$(date +%Y%m%d)"; \
current_build="$$(/usr/bin/awk -F' = ' '/CURRENT_PROJECT_VERSION = [0-9]+;/{gsub(/;/,"",$$2);print $$2; exit}' "$(CURRENT_MAKEFILE_DIR)/supacode.xcodeproj/project.pbxproj")"; \
if [ "$$current_build" -ge "$$base_build" ] 2>/dev/null; then \
build="$$((current_build + 1))"; \
else \
build="$$base_build"; \
fi; \
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" \
"$(CURRENT_MAKEFILE_DIR)/supacode.xcodeproj/project.pbxproj"; \
sed -i '' "s/CURRENT_PROJECT_VERSION = [0-9]*;/CURRENT_PROJECT_VERSION = $$build;/g" \
"$(CURRENT_MAKEFILE_DIR)/supacode.xcodeproj/project.pbxproj"; \
printf '// Auto-generated by Makefile (sync-cli-version). Do not edit.\n\npublic enum ProwlVersion {\n public static let current = "%s"\n}\n' "$$version" > \
"$(CURRENT_MAKEFILE_DIR)/supacode/CLIService/Shared/ProwlVersion.swift"; \
git add "$(CURRENT_MAKEFILE_DIR)/supacode.xcodeproj/project.pbxproj" \
"$(CURRENT_MAKEFILE_DIR)/supacode/CLIService/Shared/ProwlVersion.swift"; \
git commit -m "bump v$$version"; \
git tag -s "v$$version" -m "v$$version"; \
echo "version bumped to $$version (build $$build), tagged v$$version"