-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
299 lines (259 loc) · 11.6 KB
/
Copy pathMakefile
File metadata and controls
299 lines (259 loc) · 11.6 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
# Makefile for the typed project (statically typed LFE with ADTs)
# ANSI color codes
BLUE := \033[1;34m
GREEN := \033[1;32m
YELLOW := \033[1;33m
RED := \033[1;31m
CYAN := \033[1;36m
RESET := \033[0m
# Variables
PROJECT_NAME := typed
APP_VERSION := $(shell grep vsn src/$(PROJECT_NAME).app.src | cut -d'"' -f2)
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
RUST_VERSION := $(shell rustc --version 2>/dev/null || echo "not installed")
OTP_VERSION := $(shell erl -noshell -eval 'io:format("~s",[erlang:system_info(otp_release)]),halt().' 2>/dev/null || echo "not installed")
REBAR := rebar3
CHECKER_DIR := checker
# Default target
.DEFAULT_GOAL := help
# Help target
.PHONY: help
help:
@echo ""
@echo "$(CYAN)╔══════════════════════════════════════════════════════════╗$(RESET)"
@echo "$(CYAN)║$(RESET) $(BLUE)$(PROJECT_NAME) v$(APP_VERSION) Build System$(RESET) $(CYAN)║$(RESET)"
@echo "$(CYAN)╚══════════════════════════════════════════════════════════╝$(RESET)"
@echo ""
@echo "$(GREEN)Building:$(RESET)"
@echo " $(YELLOW)make compile$(RESET) - Compile Erlang/LFE and Rust (debug)"
@echo " $(YELLOW)make compile-erl$(RESET) - Compile Erlang/LFE only"
@echo " $(YELLOW)make compile-rust$(RESET) - Compile Rust checker only"
@echo " $(YELLOW)make release$(RESET) - Build optimized Rust release"
@echo ""
@echo "$(GREEN)Testing:$(RESET)"
@echo " $(YELLOW)make test$(RESET) - Run all tests (Rust + Erlang CT)"
@echo " $(YELLOW)make test-rust$(RESET) - Run Rust tests only"
@echo " $(YELLOW)make test-erl$(RESET) - Run Erlang/LFE tests only"
@echo " $(YELLOW)make test-unit$(RESET) - Run eunit tests"
@echo " $(YELLOW)make test-ct$(RESET) - Run Common Test suites"
@echo ""
@echo "$(GREEN)Quality:$(RESET)"
@echo " $(YELLOW)make check$(RESET) - Full quality gate (lint + build + test)"
@echo " $(YELLOW)make lint$(RESET) - Run all linters (Rust + Erlang)"
@echo " $(YELLOW)make lint-rust$(RESET) - Run clippy + format check"
@echo " $(YELLOW)make lint-erl$(RESET) - Run xref + dialyzer"
@echo " $(YELLOW)make format$(RESET) - Auto-format Rust code"
@echo " $(YELLOW)make coverage$(RESET) - Generate test coverage reports"
@echo ""
@echo "$(GREEN)Cleaning:$(RESET)"
@echo " $(YELLOW)make clean$(RESET) - Clean build artifacts"
@echo " $(YELLOW)make distclean$(RESET) - Deep clean (including deps)"
@echo ""
@echo "$(GREEN)Documentation:$(RESET)"
@echo " $(YELLOW)make docs$(RESET) - Generate documentation"
@echo " $(YELLOW)make docs-rust$(RESET) - Generate Rust API docs"
@echo ""
@echo "$(GREEN)Information:$(RESET)"
@echo " $(YELLOW)make info$(RESET) - Show build information"
@echo " $(YELLOW)make check-tools$(RESET) - Verify required tools are installed"
@echo ""
@echo "$(CYAN)Current status:$(RESET) Branch: $(GIT_BRANCH) | Commit: $(GIT_COMMIT)"
@echo ""
# Info target
.PHONY: info
info:
@echo ""
@echo "$(CYAN)╔══════════════════════════════════════════════════════════╗$(RESET)"
@echo "$(CYAN)║$(RESET) $(BLUE)Build Information$(RESET) $(CYAN)║$(RESET)"
@echo "$(CYAN)╚══════════════════════════════════════════════════════════╝$(RESET)"
@echo ""
@echo "$(GREEN)Project:$(RESET)"
@echo " Name: $(PROJECT_NAME) v$(APP_VERSION)"
@echo " Workspace: $$(pwd)"
@echo ""
@echo "$(GREEN)Git:$(RESET)"
@echo " Branch: $(GIT_BRANCH)"
@echo " Commit: $(GIT_COMMIT)"
@echo ""
@echo "$(GREEN)Tools:$(RESET)"
@echo " OTP: $(OTP_VERSION)"
@echo " Rust: $(RUST_VERSION)"
@echo " Cargo: $$(cargo --version 2>/dev/null || echo 'not found')"
@echo " Clippy: $$(cargo clippy --version 2>/dev/null || echo 'not found')"
@echo " Rustfmt: $$(rustfmt --version 2>/dev/null || echo 'not found')"
@echo " Rebar3: $$($(REBAR) --version 2>/dev/null || echo 'not found')"
@echo ""
# Check tools target
.PHONY: check-tools
check-tools:
@echo "$(BLUE)Checking for required tools...$(RESET)"
@command -v erl >/dev/null 2>&1 && echo "$(GREEN)✓ erl found (OTP $(OTP_VERSION))$(RESET)" || echo "$(RED)✗ erl not found$(RESET)"
@command -v $(REBAR) >/dev/null 2>&1 && echo "$(GREEN)✓ rebar3 found$(RESET)" || echo "$(RED)✗ rebar3 not found$(RESET)"
@command -v rustc >/dev/null 2>&1 && echo "$(GREEN)✓ rustc found ($(RUST_VERSION))$(RESET)" || echo "$(RED)✗ rustc not found$(RESET)"
@command -v cargo >/dev/null 2>&1 && echo "$(GREEN)✓ cargo found$(RESET)" || echo "$(RED)✗ cargo not found$(RESET)"
@command -v rustfmt >/dev/null 2>&1 && echo "$(GREEN)✓ rustfmt found$(RESET)" || echo "$(RED)✗ rustfmt not found (install: rustup component add rustfmt)$(RESET)"
@cargo clippy --version >/dev/null 2>&1 && echo "$(GREEN)✓ clippy found$(RESET)" || echo "$(RED)✗ clippy not found (install: rustup component add clippy)$(RESET)"
# ============================================================
# Building
# ============================================================
.PHONY: compile compile-erl compile-rust release
compile: compile-rust compile-erl
compile-erl:
@echo "$(BLUE)Compiling Erlang/LFE...$(RESET)"
@$(REBAR) compile
@echo "$(GREEN)✓ Erlang/LFE compiled$(RESET)"
compile-rust:
@echo "$(BLUE)Compiling Rust checker...$(RESET)"
@cd $(CHECKER_DIR) && cargo build
@echo "$(GREEN)✓ Rust checker compiled$(RESET)"
release:
@echo "$(BLUE)Building Rust release...$(RESET)"
@cd $(CHECKER_DIR) && cargo build --release
@echo "$(GREEN)✓ Release build complete$(RESET)"
# ============================================================
# Testing
# ============================================================
.PHONY: test test-rust test-erl test-unit test-ct
test: test-rust test-erl
@echo ""
@echo "$(GREEN)✓ All tests passed (Rust + Erlang)$(RESET)"
@echo ""
test-rust:
@echo "$(BLUE)Running Rust tests...$(RESET)"
@cd $(CHECKER_DIR) && cargo test
@echo "$(GREEN)✓ Rust tests passed$(RESET)"
test-erl: compile-rust
@echo "$(BLUE)Running Erlang/LFE tests...$(RESET)"
@$(REBAR) do eunit, ct
@echo "$(GREEN)✓ Erlang/LFE tests passed$(RESET)"
test-unit:
@$(REBAR) eunit
test-ct: compile-rust
@$(REBAR) ct
# ============================================================
# Quality / Linting
# ============================================================
.PHONY: lint lint-rust lint-erl format check ci
lint: lint-rust lint-erl
@echo ""
@echo "$(GREEN)✓ All linters passed$(RESET)"
@echo ""
lint-rust:
@echo "$(BLUE)Running Rust linters...$(RESET)"
@echo "$(CYAN)• clippy...$(RESET)"
@cd $(CHECKER_DIR) && cargo clippy -- -D warnings
@echo "$(GREEN)✓ Clippy passed$(RESET)"
@echo "$(CYAN)• format check...$(RESET)"
@cd $(CHECKER_DIR) && cargo fmt -- --check
@echo "$(GREEN)✓ Format check passed$(RESET)"
lint-erl:
@echo "$(BLUE)Running Erlang linters...$(RESET)"
@echo "$(CYAN)• xref...$(RESET)"
@$(REBAR) xref
@echo "$(GREEN)✓ xref passed$(RESET)"
format:
@echo "$(BLUE)Formatting Rust code...$(RESET)"
@cd $(CHECKER_DIR) && cargo fmt
@echo "$(GREEN)✓ Code formatted$(RESET)"
check: lint compile test
@echo ""
@echo "$(GREEN)✓ All checks passed (lint + build + test)$(RESET)"
@echo ""
ci: check
@echo "$(GREEN)✓ CI gate passed$(RESET)"
# ============================================================
# Coverage
# ============================================================
.PHONY: coverage coverage-rust coverage-erl
coverage: coverage-rust coverage-erl
coverage-rust:
@echo "$(BLUE)Generating Rust coverage...$(RESET)"
@cd $(CHECKER_DIR) && cargo llvm-cov 2>/dev/null || echo "$(YELLOW)→ Install cargo-llvm-cov for Rust coverage$(RESET)"
coverage-erl:
@echo "$(BLUE)Generating Erlang coverage...$(RESET)"
@$(REBAR) do eunit --cover, ct --cover
@$(REBAR) cover
# ============================================================
# Cleaning
# ============================================================
.PHONY: clean distclean
clean:
@echo "$(BLUE)Cleaning build artifacts...$(RESET)"
@$(REBAR) clean
@rm -rf _build logs erl_crash.dump doc test/*.beam src/*.beam ebin
@cd $(CHECKER_DIR) && cargo clean
@echo "$(GREEN)✓ Clean complete$(RESET)"
distclean: clean
@rm -rf _build
@echo "$(GREEN)✓ Deep clean complete$(RESET)"
# ============================================================
# Documentation
# ============================================================
.PHONY: docs docs-rust
docs:
@echo "$(BLUE)Generating documentation...$(RESET)"
@$(REBAR) ex_doc 2>/dev/null || echo "$(YELLOW)→ ex_doc not configured$(RESET)"
@echo "$(GREEN)✓ Documentation generated$(RESET)"
docs-rust:
@echo "$(BLUE)Generating Rust API docs...$(RESET)"
@cd $(CHECKER_DIR) && cargo doc --no-deps
@echo "$(GREEN)✓ Rust docs generated at $(CHECKER_DIR)/target/doc/$(RESET)"
# ============================================================
# Erlang-specific
# ============================================================
.PHONY: dialyzer xref golden-generate golden-verify
dialyzer:
@$(REBAR) dialyzer
xref:
@$(REBAR) xref
# Expander oracle: generate and verify golden corpus
golden-generate:
@echo "$(BLUE)Generating golden outputs from oracle...$(RESET)"
@for f in test/golden/corpus/*.lfe.txt; do \
base=$$(basename "$$f" .lfe.txt); \
scripts/expand-oracle "$$f" > "test/golden/expected/$${base}.expanded" 2>&1; \
echo " $$base"; \
done
@echo "$(GREEN)✓ Goldens generated$(RESET)"
golden-rust-verify:
@echo "$(BLUE)Verifying Rust expander against Tier-1 oracle goldens (structural compare)...$(RESET)"
@fail=0; \
for base in backquote core-forms defrecord-t1 predef-macros-t1; do \
corpus="test/golden/corpus/$${base}.lfe.txt"; \
expected="test/golden/expected/$${base}.expanded"; \
tmpeetf="/tmp/typed_golden_$${base}.eetf"; \
$(CHECKER_DIR)/target/debug/typed-check "$$corpus" --expand-only --output "$$tmpeetf" 2>/dev/null; \
result=$$(scripts/golden-struct-compare "$$expected" "$$tmpeetf" 2>/dev/null | grep -v "Warning\|%"); \
if echo "$$result" | grep -q "ALL FORMS MATCH"; then \
echo " $(GREEN)✓$(RESET) $$base"; \
else \
echo " $(RED)✗$(RESET) $$base"; \
echo "$$result" | head -5; \
fail=1; \
fi; \
done; \
if [ $$fail -eq 1 ]; then \
echo "$(RED)Tier-1 golden gate FAILED$(RESET)"; \
exit 1; \
fi
@echo "$(GREEN)✓ Tier-1 golden gate PASSED — all forms match$(RESET)"
golden-verify:
@echo "$(BLUE)Verifying golden outputs against oracle...$(RESET)"
@fail=0; \
for f in test/golden/corpus/*.lfe.txt; do \
base=$$(basename "$$f" .lfe.txt); \
expected="test/golden/expected/$${base}.expanded"; \
actual=$$(scripts/expand-oracle "$$f" 2>&1); \
if [ "$$actual" = "$$(cat $$expected)" ]; then \
echo " $(GREEN)✓$(RESET) $$base"; \
else \
echo " $(RED)✗$(RESET) $$base (oracle output differs from committed golden)"; \
fail=1; \
fi; \
done; \
if [ $$fail -eq 1 ]; then \
echo "$(RED)Golden verification FAILED — run 'make golden-generate' to update$(RESET)"; \
exit 1; \
fi
@echo "$(GREEN)✓ All goldens verified$(RESET)"