-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
183 lines (159 loc) · 5.49 KB
/
Copy pathMakefile
File metadata and controls
183 lines (159 loc) · 5.49 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
# ============================================================================
# APPLE DOCS CLI MAKEFILE
# ============================================================================
# This Makefile provides automation for building, testing, and developing
# the apple-docs CLI. Run 'make help' to see all available commands.
# ============================================================================
# Default target - show help when running 'make' without arguments
.DEFAULT_GOAL := help
# ============================================================================
# BUILD CONFIGURATION
# ============================================================================
# Configurable build variables
CLI_NAME := apple-docs
DIST_DIR := dist
CLI_BINARY := $(DIST_DIR)/$(CLI_NAME)
RELEASE_BIN_DIR = $(shell swift build -c release --show-bin-path)
# Source files used to determine when the distribution binary needs rebuilding
SWIFT_SOURCES := $(shell find Sources Tests -type f -name '*.swift')
PACKAGE_FILES := Package.swift Package.resolved
# Ensure the distribution directory exists
$(DIST_DIR):
@mkdir -p $(DIST_DIR)
# ============================================================================
# SETUP & DEPENDENCIES
# ============================================================================
## Initialize the project for development
#
# Installs development tools from Brewfile and resolves SwiftPM dependencies.
# Run this once after cloning the repository.
.PHONY: init
init:
@if ! command -v brew >/dev/null 2>&1; then \
echo "Homebrew is required to install development tools."; \
exit 1; \
fi
brew bundle
swift package resolve
## Resolve SwiftPM dependencies
#
# Downloads package dependencies using the versions recorded in Package.resolved.
.PHONY: resolve
resolve:
swift package resolve
# ============================================================================
# BUILDING & RUNNING
# ============================================================================
## Build the release CLI binary
#
# Creates a standalone optimized binary at dist/apple-docs.
.PHONY: build
build: $(CLI_BINARY)
$(CLI_BINARY): $(SWIFT_SOURCES) $(PACKAGE_FILES) | $(DIST_DIR)
swift build -c release
cp "$(RELEASE_BIN_DIR)/$(CLI_NAME)" "$@"
## Build and run the CLI
#
# Pass command arguments through ARGS, for example:
# make run ARGS="types view MXHangDiagnostic --technology MetricKit"
.PHONY: run
run:
swift run $(CLI_NAME) $(ARGS)
# ============================================================================
# TESTING & QUALITY ASSURANCE
# ============================================================================
## Run all tests
#
# Executes the complete Swift Testing suite.
.PHONY: test
test:
swift test
## Run all tests in a Linux container
#
# Uses a Docker volume for SwiftPM build output so Linux artifacts do not conflict
# with the host build directory.
.PHONY: test-linux
test-linux:
docker run --rm \
--mount "type=bind,source=$(CURDIR),target=/workspace,readonly" \
--volume "apple-docs-cli-linux-build:/workspace/.build" \
--workdir /workspace \
swift:6.3.3 \
swift test --disable-automatic-resolution
## Run live CLI integration tests
#
# Builds the release executable and runs network-dependent command tests against Apple documentation.
.PHONY: test-integration
test-integration: build
APPLE_DOCS_EXECUTABLE="$(CURDIR)/$(CLI_BINARY)" swift test --filter CLIIntegrationTests
## Run SwiftLint
#
# Checks project-owned Swift files using .swiftlint.yml. Warnings fail the target.
.PHONY: lint
lint:
swiftlint lint --strict --config .swiftlint.yml
## Check project formatting
#
# Verifies Swift, JSON, YAML, Markdown, TOML, and GitHub Actions workflows without modifying them.
.PHONY: format-check
format-check:
swift format lint \
--configuration .swift-format.json \
--recursive \
--parallel \
--strict \
Sources Tests Package.swift
dprint check
actionlint
## Run all static quality checks
#
# Runs SwiftLint and verifies swift-format and dprint output.
.PHONY: analyze
analyze: lint format-check
## Format project files
#
# Rewrites Swift files with swift-format and supported config/docs with dprint.
.PHONY: format
format:
swift format format \
--configuration .swift-format.json \
--in-place \
--recursive \
--parallel \
Sources Tests Package.swift
dprint fmt
# ============================================================================
# MAINTENANCE
# ============================================================================
## Clean generated build artifacts
#
# Removes SwiftPM and distribution build output.
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
swift package clean
rm -rf "$(DIST_DIR)"
@echo "Clean complete."
# ============================================================================
# HELP & DOCUMENTATION
# ============================================================================
## Show this help message with all available commands
#
# Displays a formatted list of make targets generated from the comments above.
.PHONY: help
help:
@echo "=============================================="
@echo "APPLE DOCS CLI DEVELOPMENT COMMANDS"
@echo "=============================================="
@echo ""
@awk 'BEGIN { desc = ""; target = "" } \
/^## / { desc = substr($$0, 4) } \
/^\.PHONY: / && desc != "" { \
target = $$2; \
printf "\033[36m%-20s\033[0m %s\n", target, desc; \
desc = ""; target = "" \
}' $(MAKEFILE_LIST)
@echo ""
@echo "Use 'make <command>' to run any command above."
@echo "For detailed information, see comments in the Makefile."
@echo ""