-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (188 loc) · 6.72 KB
/
Makefile
File metadata and controls
208 lines (188 loc) · 6.72 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
# ============================================================================
# MAKEFILE
# ============================================================================
# This Makefile provides automation for building, testing, and developing
# the SystemMetrics app. Run 'make help' to see all available commands.
# ============================================================================
# ============================================================================
# SETUP
# ============================================================================
## Setup the project by installing dependencies and pre-commit hooks.
#
# Sets up a fresh machine for development by installing dependencies and git hooks.
# Safe to re-run if you need to reinitialize dependencies or hooks.
.PHONY: setup
setup: install-dependencies install-pre-commit
## Install the project dependencies using Homebrew.
#
# Installs all tools declared in the Brewfile.
.PHONY: install-dependencies
install-dependencies:
brew bundle
## Install the pre-commit hooks.
#
# Installs repository git hooks to enforce formatting and checks before commits.
.PHONY: install-pre-commit
install-pre-commit:
pre-commit install
# ============================================================================
# BUILDING
# ============================================================================
## Build App target for macOS.
#
# Builds the main app for macOS.
# Outputs raw logs to raw-build-macos-app.log and pretty-prints with xcbeautify.
.PHONY: build
build:
set -o pipefail && NSUnbufferedIO=YES xcrun xcodebuild -project SystemMetrics.xcodeproj -scheme SystemMetrics -destination 'platform=macOS' build | tee raw-build.log | xcbeautify --preserve-unbeautified
# ============================================================================
# TESTING
# ============================================================================
## Run unit tests for SystemMetrics scheme on macOS.
#
# Runs unit tests for the SystemMetrics scheme on macOS.
# Writes logs to raw-test-macos-app.log and formats output with xcbeautify.
.PHONY: test
test:
@echo "not implemented" && exit 1
# ============================================================================
# FORMATTING
# ============================================================================
## Format Swift, Markdown, JSON, and YAML files using project tools.
#
# Runs all formatting tasks for Swift, JSON, Markdown, and YAML files in the project.
.PHONY: format
format: format-swift format-json format-markdown format-yaml
## Format Swift sources and apply SwiftLint auto-fixes.
#
# Runs swift-format and SwiftLint to format and autofix Swift code.
.PHONY: format-swift
format-swift:
swift format --configuration .swift-format.json --in-place --recursive Source
swiftlint --config .swiftlint.yml --strict --fix
## Format all JSON files with dprint.
#
# Runs dprint to format all JSON files.
.PHONY: format-json
format-json:
dprint fmt "**/*.json"
## Format all Markdown files with dprint.
#
# Runs dprint to format all Markdown files.
.PHONY: format-markdown
format-markdown:
dprint fmt "**/*.md"
## Format all YAML files with dprint.
#
# Runs dprint to format all YAML and YML files.
.PHONY: format-yaml
format-yaml:
dprint fmt "**/*.{yaml,yml}"
## Run SwiftLint and dprint checks without fixes.
#
# Runs SwiftLint and dprint checks without modifying files.
.PHONY: lint
lint:
swiftlint --config .swiftlint.yml --strict
dprint check "**/*.{md,json,yaml,yml}"
# ============================================================================
# HELP & DOCUMENTATION
# ============================================================================
# Reusable awk script for detailed help output
define HELP_DETAIL_AWK
BEGIN { summary = ""; detailsCount = 0; printed = 0; lookingForDeps = 0 } \
/^## / { summary = substr($$0, 4); delete details; detailsCount = 0; next } \
/^#($$| )/ { \
if (summary != "") { \
line = $$0; \
if (substr(line,1,2)=="# ") detailLine = substr(line,3); else detailLine = ""; \
details[detailsCount++] = detailLine; \
} \
if (lookingForDeps && $$0 !~ /^#/) { lookingForDeps = 0 } \
next \
} \
/^\.PHONY: / && summary != "" { \
for (i = 2; i <= NF; i++) { \
if ($$i == T) { \
found = 1; \
lookingForDeps = 1; \
break \
} \
} \
if (!found) { summary = ""; detailsCount = 0; delete details } \
next \
} \
lookingForDeps && /^[A-Za-z0-9_.-]+[ \t]*:/ && $$0 !~ /^\.PHONY:/ && $$0 !~ /^\t/ && index($$0,"=")==0 { \
raw = $$0; \
split(raw, parts, ":"); \
tn = parts[1]; \
if (tn == T) { \
depStr = substr(raw, index(raw, ":")+1); \
gsub(/^[ \t]+|[ \t]+$$/, "", depStr); \
firstDep = depStr; \
split(depStr, depParts, /[ \t]+/); \
if (length(depParts[1]) > 0) firstDep = depParts[1]; \
lookingForDeps = 0; \
} \
next \
} \
found && !lookingForDeps { \
printf "%s\n\n", summary; \
for (j = 0; j < detailsCount; j++) { \
if (length(details[j]) > 0) printf "%s\n", details[j]; else print ""; \
} \
print ""; \
printf "Usage:\n"; \
if (length(firstDep) > 0) { \
printf " make %s\n", firstDep; \
} else { \
printf " make %s\n", T; \
} \
printed = 1; \
found = 0; summary = ""; detailsCount = 0; delete details; firstDep = ""; \
next \
} \
END { if (!printed) { printf "No detailed help found for target: %s\n", T } }
endef
## Show this help message with all available commands
#
# Displays a formatted list of all available make targets with descriptions.
# Commands are organized by topic for easy navigation.
.PHONY: help
help:
@if [ -n "$(name)" ]; then \
$(MAKE) --no-print-directory help-target name="$(name)"; \
else \
echo "=============================================="; \
echo "🚀 SENTRY SYSTEM STATS DEVELOPMENT COMMANDS"; \
echo "=============================================="; \
echo ""; \
awk 'BEGIN { summary = ""; n = 0; maxlen = 0 } \
/^## / { summary = substr($$0, 4); delete details; detailsCount = 0; next } \
/^\.PHONY: / && summary != "" { \
for (i = 2; i <= NF; i++) { \
targets[n] = $$i; \
summaries[n] = summary; \
if (length($$i) > maxlen) maxlen = length($$i); \
n++; \
} \
summary = ""; next \
} \
END { \
for (i = 0; i < n; i++) { \
printf "\033[36m%-*s\033[0m %s\n", maxlen, targets[i], summaries[i]; \
} \
}' $(MAKEFILE_LIST); \
echo ""; \
echo "💡 Use 'make <command>' to run any command above."; \
echo "📖 For detailed help on a command, run: make help-<command> (e.g., make help-build)"; \
echo "📖 Or: make help name=<command> (e.g., make help name=build)"; \
echo ""; \
fi
.PHONY: help-% help-target
help-%:
@target="$*"; \
awk -v T="$$target" '$(HELP_DETAIL_AWK)' $(MAKEFILE_LIST)
help-target:
@[ -n "$(name)" ] || { echo "Usage: make help name=<target>"; exit 1; }; \
awk -v T="$(name)" '$(HELP_DETAIL_AWK)' $(MAKEFILE_LIST)