-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
176 lines (150 loc) · 6.35 KB
/
Makefile
File metadata and controls
176 lines (150 loc) · 6.35 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
# (\_/)
# (o.o)
# / > [nix-shell] <-- for Rust commands
# Use Nix wrapper for Rust commands only (Swift needs native Xcode tools)
NIX_SHELL := ./Scripts/run-in-nix.sh -c
APP_NAME := ClipKitty
SCRIPT_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
# Version: override via `make all VERSION=1.2.3`
# BUILD_NUMBER defaults to VERSION so CFBundleVersion matches sparkle:version in the appcast.
# App Store CI overrides BUILD_NUMBER explicitly with an integer commit count.
VERSION ?= 1.0.0
BUILD_NUMBER ?= $(VERSION)
# Build configuration: Debug, Release (DMG), or AppStore (sandboxed)
CONFIGURATION ?= Release
# DerivedData location for deterministic output paths
DERIVED_DATA := $(SCRIPT_DIR)/DerivedData
# Signing identity: auto-detects Developer ID cert, falls back to ad-hoc (-)
SIGNING_IDENTITY ?= $(shell security find-identity -v -p codesigning 2>/dev/null | grep -q "Developer ID Application" && echo "Developer ID Application" || echo "-")
# Rust build marker and outputs
RUST_MARKER := .make/rust.marker
RUST_LIB := Sources/ClipKittyRust/libpurr.a
.PHONY: all clean rust rust-force generate build sign list-identities run run-perf test unittest uitest rust-test perf-test perf-db
all: rust generate build
# Marker-based Rust build - uses git tree hash for change detection
# This marker is shared with Xcode pre-build actions for consistency
$(RUST_MARKER): $(shell git ls-files purr 2>/dev/null)
@echo "Building Rust core..."
@$(NIX_SHELL) "cd purr && cargo run --release --bin generate-bindings"
@mkdir -p .make
@touch $(RUST_MARKER)
@git rev-parse HEAD:purr > .make/rust-tree-hash 2>/dev/null || true
# Also rebuild if the output library is missing
rust: $(RUST_MARKER)
@test -f $(RUST_LIB) || (rm -f $(RUST_MARKER) && $(MAKE) $(RUST_MARKER))
# Force rebuild Rust (ignore marker)
rust-force:
@rm -f $(RUST_MARKER)
@$(MAKE) rust
# Resolve dependencies and generate Xcode project from Tuist manifest
generate:
@echo "Resolving dependencies..."
@tuist install
@echo "Generating Xcode project..."
@tuist generate --no-open
# Build using xcodebuild
build:
@echo "Building $(APP_NAME) ($(CONFIGURATION))..."
@xcodebuild -workspace $(APP_NAME).xcworkspace \
-scheme $(APP_NAME) \
-configuration $(CONFIGURATION) \
-derivedDataPath $(DERIVED_DATA) \
MARKETING_VERSION=$(VERSION) \
CURRENT_PROJECT_VERSION=$(BUILD_NUMBER) \
build
# Sign the built app (for distribution)
sign:
@echo "Signing $(APP_NAME) (identity: $(SIGNING_IDENTITY), config: $(CONFIGURATION))..."
@codesign --force --options runtime \
--sign "$(SIGNING_IDENTITY)" \
"$(DERIVED_DATA)/Build/Products/$(CONFIGURATION)/$(APP_NAME).app"
# Build, kill any running instance, and open the app.
run: all
@echo "Closing existing $(APP_NAME)..."
@pkill -x $(APP_NAME) 2>/dev/null || true
@sleep 0.5
@echo "Opening $(APP_NAME)..."
@open "$(DERIVED_DATA)/Build/Products/$(CONFIGURATION)/$(APP_NAME).app"
# Run with synthetic perf test database (150 large items)
BUNDLE_ID := com.eviljuliette.clipkitty
APP_SUPPORT := $(HOME)/Library/Containers/$(BUNDLE_ID)/Data/Library/Application Support/ClipKitty
run-perf: all perf-db
@echo "Closing existing $(APP_NAME)..."
@pkill -9 $(APP_NAME) 2>/dev/null || true
@sleep 1
@echo "Setting up perf test database and index..."
@mkdir -p "$(APP_SUPPORT)"
@rm -f "$(APP_SUPPORT)/clipboard-screenshot.sqlite"*
@rm -rf "$(APP_SUPPORT)/tantivy_index_v4"
@cp distribution/SyntheticData_perf.sqlite "$(APP_SUPPORT)/clipboard-screenshot.sqlite"
@cp -r distribution/tantivy_index_v4 "$(APP_SUPPORT)/tantivy_index_v4"
@echo "Opening $(APP_NAME) with perf database..."
@open "$(DERIVED_DATA)/Build/Products/$(CONFIGURATION)/$(APP_NAME).app" --args --use-simulated-db
clean:
@rm -rf .make DerivedData
@tuist clean 2>/dev/null || true
# Run UI tests
# Usage: make uitest [TEST=testName]
# Example: make uitest TEST=testToastAppearsOnCopy
uitest: all
@echo "Ensuring Git LFS files are pulled..."
@git lfs pull 2>/dev/null || echo "Warning: git lfs pull failed (LFS not installed?)"
@echo "Setting up signing keychain..."
@./distribution/setup-dev-signing.sh
@echo "Running UI tests..."
@if [ -n "$(TEST)" ]; then \
xcodebuild test -workspace $(APP_NAME).xcworkspace \
-scheme ClipKittyUITests \
-destination "platform=macOS" \
-derivedDataPath $(DERIVED_DATA) \
-only-testing:ClipKittyUITests/ClipKittyUITests/$(TEST) \
2>&1 | grep -E "(Test Case|passed|failed|error:)" || true; \
else \
xcodebuild test -workspace $(APP_NAME).xcworkspace \
-scheme ClipKittyUITests \
-destination "platform=macOS" \
-derivedDataPath $(DERIVED_DATA) \
2>&1 | grep -E "(Test Case|passed|failed|error:)" || true; \
fi
# Run all tests (Rust + Swift unit + UI)
test: rust-test unittest uitest
# Run Rust tests
rust-test:
@echo "Running Rust tests..."
@$(NIX_SHELL) "cd purr && cargo test"
# Run Swift unit tests (requires workspace for STTextKitPlus dependency)
# Usage: make unittest [TEST=testName]
# Example: make unittest TEST=testNsRangeWithEmoji
unittest: rust generate
@echo "Running Swift unit tests..."
@if [ -n "$(TEST)" ]; then \
xcodebuild test -workspace $(APP_NAME).xcworkspace \
-scheme $(APP_NAME) \
-destination "platform=macOS" \
-derivedDataPath $(DERIVED_DATA) \
-only-testing:ClipKittyTests/$(TEST) \
2>&1 | grep -E "(Test Case|Test Suite|passed|failed|error:|warning:)" || true; \
else \
xcodebuild test -workspace $(APP_NAME).xcworkspace \
-scheme $(APP_NAME) \
-destination "platform=macOS" \
-derivedDataPath $(DERIVED_DATA) \
-only-testing:ClipKittyTests \
2>&1 | grep -E "(Test Case|Test Suite|passed|failed|error:|warning:)" || true; \
fi
# Show available signing identities (helpful for setup)
list-identities:
@echo "Available signing identities:"
@security find-identity -v -p codesigning | grep -E "(Developer|3rd Party)"
@echo ""
@echo "Set SIGNING_IDENTITY in your environment or pass to make:"
@echo " make sign SIGNING_IDENTITY=\"Developer ID Application: Your Name (TEAMID)\""
# Generate performance test database with large text items (uses native Rust)
perf-db:
@echo "Generating performance test database..."
@$(NIX_SHELL) "cd purr && cargo run --release --bin generate-perf-db"
# Run performance tests with Instruments tracing
# Usage: make perf-test [PERF_ARGS="--skip-build --fail-on-hangs"]
perf-test: all perf-db
@echo "Running performance tests with tracing..."
@./Scripts/run-perf-test.sh --skip-build $(PERF_ARGS)