-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (131 loc) · 5.75 KB
/
Makefile
File metadata and controls
149 lines (131 loc) · 5.75 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
# Makefile for local gputrace development on macOS.
GPUTRACE_APP := $(HOME)/go/bin/gputrace.app
AXPERMS_APP := $(HOME)/go/bin/axperms.app
AXPERMS_BIN := $(HOME)/go/bin/axperms
BUNDLE_ID := com.tmc.gputrace
AXPERMS_BUNDLE_ID := com.github.tmc.gputrace.axperms
.PHONY: all build test vet install clean rebuild test-permissions reset-permissions axperms setup-axperms sign-bundle help
all: build
build:
go install ./cmd/gputrace
test:
go test ./...
vet:
go vet ./...
install: clean build setup-permissions
@echo "Reinstall complete with fresh permissions"
reinstall: build
@# macgo detects the new binary hash and re-creates the bundle.
@# Trigger bundle creation, then check the bundle's current TCC state.
@echo "Updating bundle..."
@tmp=$$(mktemp); \
gputrace xp check-permissions --no-prompt --json >$$tmp 2>&1 || true; \
if grep -q "macgo.*failed" $$tmp; then \
cat $$tmp; \
rm -f $$tmp; \
exit 1; \
fi; \
if grep -q '"all_granted": true' $$tmp; then \
echo "✓ Permissions OK"; \
else \
echo "⚠ Accessibility permission not granted — run 'make setup-permissions' or approve in System Settings"; \
fi; \
rm -f $$tmp
# Clean app bundle to force macgo to recreate it
clean:
rm -rf $(GPUTRACE_APP)
# Sign the app bundle for local development.
# Ad-hoc signing avoids team-specific Gatekeeper/notarization failures.
sign-bundle:
@if [ ! -d "$(GPUTRACE_APP)" ]; then \
echo "No app bundle found, triggering creation..."; \
gputrace xp check-status --no-prompt 2>/dev/null || true; \
fi
@# Remove stale .dev_target if present (left over from DevMode, breaks codesign).
@rm -f "$(GPUTRACE_APP)/Contents/.dev_target"
@echo "Signing bundle with ad-hoc identity"; \
codesign --force --sign - --identifier $(BUNDLE_ID) "$(GPUTRACE_APP)"
# Setup permissions after clean rebuild
setup-permissions: sign-bundle
@echo "Step 1: Resetting TCC for Accessibility (clears stale code requirement)..."
-tccutil reset Accessibility $(BUNDLE_ID) 2>/dev/null || true
@echo "Step 2: Resetting TCC for Screen Recording..."
-tccutil reset ScreenCapture $(BUNDLE_ID) 2>/dev/null || true
@echo "Step 3: Re-triggering permission prompt (adds app to list with fresh signature)..."
-gputrace xp check-status --no-prompt 2>/dev/null || true
@sleep 2
@echo "Step 4: Opening System Settings Accessibility pane..."
$(AXPERMS_BIN) -open 2>/dev/null || true
@sleep 2
@echo "Step 5: Enabling accessibility permission..."
$(AXPERMS_BIN) -enable gputrace.app 2>/dev/null | grep -v "macgo:" || true
@sleep 2
@echo "Step 6: Verifying permissions..."
@gputrace xp check-status --no-prompt && echo "✓ Accessibility OK" || echo "✗ Accessibility permission may need manual intervention"
# Full permission reset (use when TCC database is stale)
reset-permissions:
@echo "Resetting TCC entries..."
tccutil reset Accessibility $(BUNDLE_ID) 2>/dev/null || true
tccutil reset ScreenCapture $(BUNDLE_ID) 2>/dev/null || true
tccutil reset Accessibility $(AXPERMS_BUNDLE_ID) 2>/dev/null || true
@echo "Re-triggering permission prompts..."
-$(AXPERMS_BIN) -prompt 2>&1 | grep -v "macgo:" || true
-gputrace xp check-status --no-prompt 2>/dev/null || true
-gputrace xp screenshot --no-prompt -o /tmp/test-screenshot.png 2>/dev/null || true
@echo ""
@echo "Please manually enable axperms and gputrace in System Settings,"
@echo "then run 'make setup-permissions'"
fullreinstall: clean build setup-permissions
@echo "Full reinstall complete (bundle recreated, permissions reset)"
reset: clean build setup-permissions
# Quick test that permissions work
test-permissions:
gputrace xp check-status --no-prompt
# Build axperms helper and update bundle
axperms:
go build -o $(AXPERMS_BIN) ./cmd/axperms
@# Update the binary inside the app bundle if it exists
@if [ -d "$(AXPERMS_APP)/Contents/MacOS" ]; then \
cp $(AXPERMS_BIN) $(AXPERMS_APP)/Contents/MacOS/axperms; \
fi
# First-time setup for axperms - requires manual user action
# Run this ONCE before using axperms to manage permissions
setup-axperms: axperms
@echo "Setting up axperms Accessibility permission..."
@echo "This is a ONE-TIME setup - axperms needs Accessibility permission"
@echo "to manipulate System Settings UI for other apps."
@echo ""
@echo "Resetting any stale axperms TCC entry..."
-tccutil reset Accessibility $(AXPERMS_BUNDLE_ID) 2>/dev/null || true
@echo ""
@echo "Triggering permission prompt..."
@# Run axperms to trigger the prompt - it will fail but add itself to the list
-$(AXPERMS_BIN) -prompt 2>&1 | grep -v "macgo:" || true
@echo ""
@echo "============================================"
@echo "ACTION REQUIRED:"
@echo "1. System Settings should now be open to Privacy & Security > Accessibility"
@echo "2. Find 'axperms' in the list"
@echo "3. Toggle it ON"
@echo "4. You may need to authenticate with your password"
@echo "5. Then run 'make setup-permissions' to configure gputrace"
@echo "============================================"
help:
@echo "gputrace Makefile"
@echo ""
@echo "Development targets:"
@echo " build - Build gputrace"
@echo " test - Run Go tests"
@echo " vet - Run go vet"
@echo " reinstall - Rebuild binary and refresh signed app bundle"
@echo " fullreinstall - Clean + rebuild + fresh permissions (resets TCC)"
@echo " clean - Remove app bundle (forces macgo to recreate)"
@echo ""
@echo "Permission setup (run in order for first-time setup):"
@echo " setup-axperms - ONE-TIME: Grant axperms Accessibility (manual step)"
@echo " setup-permissions - Setup gputrace Accessibility + Screen Recording"
@echo " reset-permissions - Full TCC reset + setup (for stale permissions)"
@echo " test-permissions - Quick test that permissions work"
@echo ""
@echo "Helper tools:"
@echo " axperms - Build axperms helper tool"