-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
474 lines (413 loc) · 19.4 KB
/
Makefile
File metadata and controls
474 lines (413 loc) · 19.4 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# =============================================================================
# Functional Library Makefile
# =============================================================================
# Project: functional
# Purpose: Result, Option, Either for type-safe functional computation
#
# This Makefile provides:
# - Build targets (build, clean, rebuild)
# - Test infrastructure (test, test-coverage)
# - Quality/check targets (check, check-arch, stats)
# =============================================================================
PROJECT_NAME := functional
.PHONY: all build build-dev build-opt build-release build-tests check check-arch \
clean clean-clutter clean-coverage clean-deep compress deps \
help prereqs rebuild refresh stats test test-all test-coverage \
test-unit test-integration test-e2e test-python test-windows \
install-tools build-coverage-runtime \
docs-formal \
submodule-init submodule-update submodule-status spark-check spark-prove
# FIX: ENABLE AFTER THE TARGETS CONVERT TO USING OUR ADAFMT TOOL, WHICH IS IN DEVELOPMENT.
# format format-all format-src format-tests
# =============================================================================
# OS Detection
# =============================================================================
UNAME := $(shell uname -s)
# =============================================================================
# Colors for Output
# =============================================================================
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
BLUE := \033[0;34m
ORANGE := \033[38;5;208m
CYAN := \033[0;36m
BOLD := \033[1m
NC := \033[0m
# =============================================================================
# Tool Paths
# =============================================================================
ALR := alr
GPRBUILD := gprbuild
GNATFORMAT := gnatformat
PYTHON3 := python3
# =============================================================================
# Tool Flags
# =============================================================================
ALR_BUILD_FLAGS := -j8
# Build wrapper: filters output to diagnostics only while propagating the
# build exit code. See scripts/python/shared/makefile/alr_build.py.
ALR_BUILD_WRAPPER := $(PYTHON3) scripts/python/shared/makefile/alr_build.py
# =============================================================================
# Directories
# =============================================================================
SRC_DIR := src
TEST_DIR := test
BUILD_DIR := obj
BIN_DIR := bin
COVERAGE_DIR := coverage
# =============================================================================
# Default Target
# =============================================================================
all: build
# =============================================================================
# Help Target
# =============================================================================
help: ## Display this help message
@echo "$(CYAN)$(BOLD)╔══════════════════════════════════════════════════╗$(NC)"
@echo "$(CYAN)$(BOLD)║ Functional Library - Ada 2022 ║$(NC)"
@echo "$(CYAN)$(BOLD)╚══════════════════════════════════════════════════╝$(NC)"
@echo " "
@echo "$(YELLOW)Build Commands:$(NC)"
@echo " build - Build library (development mode)"
@echo " build-dev - Build with development flags"
@echo " build-opt - Build with optimization (-O2)"
@echo " build-release - Build in release mode"
@echo " build-tests - Build test suite"
@echo " clean - Clean build artifacts"
@echo " clean-clutter - Remove temporary files and backups"
@echo " clean-coverage - Clean coverage data"
@echo " clean-deep - Deep clean (includes Alire cache)"
@echo " compress - Create compressed source archive (tgz)"
@echo " rebuild - Clean and rebuild"
@echo ""
@echo "$(YELLOW)Testing Commands:$(NC)"
@echo " test - Run comprehensive test suite"
@echo " test-all - Run all test executables"
@echo " test-unit - Run unit tests only"
@echo " test-integration - Run integration tests only"
@echo " test-e2e - Run E2E tests only"
@echo " test-python - Run Python script tests (arch_guard.py validation)"
@echo " test-coverage - Run tests with coverage analysis"
@echo " test-windows - Trigger Windows CI validation on GitHub"
@echo ""
@echo "$(YELLOW)Quality & Architecture Commands:$(NC)"
@echo " check - Run static analysis"
@echo " check-arch - Validate architecture boundaries"
@echo " spark-check - Run SPARK CHECK formal verification"
@echo " spark-prove - Run SPARK PROVE formal verification"
# FIX: ENABLE AFTER THE TARGETS CONVERT TO USING OUR ADAFMT TOOL, WHICH IS IN DEVELOPMENT.
# @echo " format-src - Auto-format source code only"
# @echo " format-tests - Auto-format test code only"
# @echo " format-all - Auto-format all code"
# @echo " format - Alias for format-all"
@echo " stats - Display project statistics"
@echo ""
@echo "$(YELLOW)Utility Commands:$(NC)"
@echo " deps - Show dependency information"
@echo " prereqs - Verify prerequisites are satisfied"
@echo " refresh - Refresh Alire dependencies"
@echo " install-tools - Install development tools (GMP, gcovr, gnatformat)"
@echo " build-coverage-runtime - Build GNATcoverage runtime library"
@echo ""
@echo "$(YELLOW)Workflow Shortcuts:$(NC)"
@echo " all - Build library (default)"
@echo ""
@echo "$(YELLOW)Submodule Commands:$(NC)"
@echo " submodule-init - Initialize submodules after fresh clone"
@echo " submodule-update - Pull latest from all submodule repos"
@echo " submodule-status - Show submodule commit status"
# =============================================================================
# Build Commands
# =============================================================================
prereqs:
@echo "$(GREEN)✓ All prerequisites satisfied$(NC)"
build: build-dev
build-dev: check-arch prereqs
@echo "$(GREEN)Building $(PROJECT_NAME) (development mode)...$(NC)"
@$(ALR_BUILD_WRAPPER) $(ALR) build --development -- $(ALR_BUILD_FLAGS)
@echo "$(GREEN)✓ Development build complete$(NC)"
build-opt: check-arch prereqs
@echo "$(GREEN)Building $(PROJECT_NAME) (optimized -O2)...$(NC)"
@$(ALR_BUILD_WRAPPER) $(ALR) build -- -O2 $(ALR_BUILD_FLAGS)
@echo "$(GREEN)✓ Optimized build complete$(NC)"
build-release: check-arch prereqs
@echo "$(GREEN)Building $(PROJECT_NAME) (release mode)...$(NC)"
@$(ALR_BUILD_WRAPPER) $(ALR) build --release -- $(ALR_BUILD_FLAGS)
@echo "$(GREEN)✓ Release build complete$(NC)"
build-tests: check-arch prereqs
@echo "$(GREEN)Building test suites...$(NC)"
@if [ -f "$(TEST_DIR)/unit/unit_tests.gpr" ]; then \
$(ALR_BUILD_WRAPPER) $(ALR) exec -- $(GPRBUILD) -P $(TEST_DIR)/unit/unit_tests.gpr -p $(ALR_BUILD_FLAGS); \
echo "$(GREEN)✓ Unit tests built$(NC)"; \
else \
echo "$(YELLOW)Unit test project not found$(NC)"; \
fi
clean:
@echo "$(YELLOW)Cleaning project build artifacts (keeps dependencies)...$(NC)"
@# Use gprclean WITHOUT -r to clean only our project, not dependencies
@$(ALR) exec -- gprclean -P $(PROJECT_NAME).gpr -q 2>/dev/null || true
@$(ALR) exec -- gprclean -P $(TEST_DIR)/unit/unit_tests.gpr -q 2>/dev/null || true
@rm -rf $(BUILD_DIR) $(BIN_DIR) lib $(TEST_DIR)/bin $(TEST_DIR)/obj
@# Delete platform-specific lock file (see README: Platform Build Constraint)
@rm -f alire/alire.lock
@find . -name "*.backup" -delete 2>/dev/null || true
@echo "$(GREEN)✓ Project artifacts cleaned (dependencies preserved for fast rebuild)$(NC)"
clean-deep:
@echo "$(YELLOW)Deep cleaning ALL artifacts including dependencies...$(NC)"
@echo "$(YELLOW)⚠️ This will require rebuilding all dependencies (slow!)$(NC)"
@$(ALR) clean
@rm -rf $(BUILD_DIR) $(BIN_DIR) lib $(TEST_DIR)/bin $(TEST_DIR)/obj
@rm -rf alire .build $(COVERAGE_DIR)
@find . -name "*.backup" -delete 2>/dev/null || true
@echo "$(GREEN)✓ Deep clean complete (next build will be slow)$(NC)"
clean-coverage:
@echo "$(YELLOW)Cleaning coverage artifacts...$(NC)"
@find . -name "*.srctrace" -delete 2>/dev/null || true
@find . -name "*.traces" -delete 2>/dev/null || true
@find . -name "*.sid" -delete 2>/dev/null || true
@find . -name "*.gcda" -o -name "*.gcno" -o -name "*.gcov" | \
xargs rm -f 2>/dev/null || true
@rm -rf $(COVERAGE_DIR)/ 2>/dev/null || true
@rm -rf gnatcov-instr/ 2>/dev/null || true
@echo "$(GREEN)✓ Coverage artifacts cleaned$(NC)"
clean-clutter: ## Remove temporary files, backups, and clutter
@echo "$(CYAN)Cleaning temporary files and clutter...$(NC)"
@$(PYTHON3) scripts/python/shared/makefile/cleanup_temp_files.py
@echo "$(GREEN)✓ Temporary files removed$(NC)"
compress:
@echo "$(CYAN)Creating compressed source archive...$(NC)"
git archive --format=tar.gz -o "$(PROJECT_NAME).tar.gz" HEAD
@echo "$(GREEN)✓ Archive created: $(PROJECT_NAME).tar.gz$(NC)"
rebuild: clean build
# =============================================================================
# Testing Commands
# =============================================================================
test: test-all
test-all: build build-tests
@echo "$(GREEN)Running all test executables...$(NC)"
@failed=0; \
if [ -d "$(TEST_DIR)/bin" ]; then \
for test in $(TEST_DIR)/bin/*_runner; do \
if [ -x "$$test" ] && [ -f "$$test" ]; then \
echo "$(CYAN)Running $$test...$(NC)"; \
$$test || failed=1; \
echo ""; \
fi; \
done; \
else \
echo "$(YELLOW)No test executables found in $(TEST_DIR)/bin$(NC)"; \
fi; \
if [ $$failed -eq 0 ]; then \
echo ""; \
echo "\033[1;92m########################################"; \
echo "###"; \
echo "### ALL TEST SUITES: SUCCESS"; \
echo "### All tests passed!"; \
echo "###"; \
echo "########################################\033[0m"; \
echo ""; \
else \
echo ""; \
echo "\033[1;91m########################################"; \
echo "###"; \
echo "### ALL TEST SUITES: FAILURE"; \
echo "### Some tests failed!"; \
echo "###"; \
echo "########################################\033[0m"; \
echo ""; \
exit 1; \
fi
test-unit: build build-tests
@echo "$(GREEN)Running unit tests...$(NC)"
@if [ -f "$(TEST_DIR)/bin/unit_runner" ]; then \
$(TEST_DIR)/bin/unit_runner; \
if [ $$? -eq 0 ]; then \
echo "$(GREEN)✓ Unit tests passed$(NC)"; \
else \
echo "$(RED)✗ Unit tests failed$(NC)"; \
exit 1; \
fi; \
else \
echo "$(YELLOW)Unit test runner not found at $(TEST_DIR)/bin/unit_runner$(NC)"; \
exit 1; \
fi
test-integration: build build-tests
@echo "$(GREEN)Running integration tests...$(NC)"
@echo "$(YELLOW)No integration tests defined for functional library$(NC)"
test-e2e: build build-tests
@echo "$(GREEN)Running E2E tests...$(NC)"
@echo "$(YELLOW)No E2E tests defined for functional library$(NC)"
test-coverage: ## Run tests with GNATcoverage analysis
@echo "$(GREEN)Running tests with GNATcoverage analysis...$(NC)"
@$(PYTHON3) scripts/python/shared/makefile/coverage_ada.py
test-python: ## Run Python script tests (arch_guard.py validation)
@echo "$(GREEN)Running Python script tests...$(NC)"
@cd test/scripts/python/shared && $(PYTHON3) -m pytest -v
@echo "$(GREEN)✓ Python tests complete$(NC)"
test-windows: ## Trigger Windows CI validation on GitHub Actions
@echo "$(CYAN)Triggering Windows CI validation...$(NC)"
@if [ ! -f ".github/workflows/windows-release.yml" ]; then \
echo "$(RED)✗ Windows workflow not found$(NC)"; \
exit 1; \
fi
@if ! command -v gh >/dev/null 2>&1; then \
echo "$(RED)✗ GitHub CLI (gh) not installed$(NC)"; \
echo " Install from: https://cli.github.com/"; \
exit 1; \
fi
@REF=$$(git rev-parse HEAD); \
echo "$(CYAN) Ref: $${REF:0:8}$(NC)"; \
gh workflow run windows-release.yml -f version=dev -f ref=$$REF; \
echo "$(GREEN)✓ Workflow triggered$(NC)"; \
echo ""; \
echo "$(YELLOW)Waiting for workflow to start...$(NC)"; \
sleep 5; \
RUN_ID=$$(gh run list --workflow=windows-release.yml --limit=1 --json databaseId -q '.[0].databaseId'); \
if [ -n "$$RUN_ID" ]; then \
echo "$(CYAN) Run ID: $$RUN_ID$(NC)"; \
echo "$(YELLOW)Watching workflow (Ctrl+C to detach)...$(NC)"; \
gh run watch $$RUN_ID --exit-status && \
echo "$(GREEN)$(BOLD)✓ Windows validation passed$(NC)" || \
(echo "$(RED)$(BOLD)✗ Windows validation failed$(NC)" && exit 1); \
else \
echo "$(RED)✗ Could not find workflow run$(NC)"; \
exit 1; \
fi
# =============================================================================
# Quality & Code Formatting Commands
# =============================================================================
check:
@echo "$(GREEN)Running code checks...$(NC)"
@$(ALR_BUILD_WRAPPER) $(ALR) build --development -- $(ALR_BUILD_FLAGS)
@echo "$(GREEN)✓ Code checks complete$(NC)"
check-arch: ## Validate architecture boundaries
@echo "$(GREEN)Validating architecture boundaries...$(NC)"
-@PYTHONPATH=scripts/python/shared $(PYTHON3) -m arch_guard --project-root .
@echo "$(YELLOW)⚠ Architecture validation complete (violations are warnings, not errors)$(NC)"
spark-check: ## Run SPARK CHECK formal verification
@echo "$(GREEN)Running SPARK CHECK verification...$(NC)"
@if [ ! -f "$(PROJECT_NAME)_spark.gpr" ]; then \
echo "$(RED)✗ SPARK project file not found: $(PROJECT_NAME)_spark.gpr$(NC)"; \
exit 1; \
fi
@cd $(TEST_DIR) && $(ALR) exec -- gnatprove -j12 -P ../$(PROJECT_NAME)_spark.gpr --mode=check 2>&1; \
if [ $$? -eq 0 ]; then \
echo "$(GREEN)✓ SPARK CHECK verification passed$(NC)"; \
else \
echo "$(RED)✗ SPARK CHECK verification failed$(NC)"; \
exit 1; \
fi
spark-prove: ## Run SPARK PROVE formal verification
@echo "$(GREEN)Running SPARK PROVE verification...$(NC)"
@if [ ! -f "$(PROJECT_NAME)_spark.gpr" ]; then \
echo "$(RED)✗ SPARK project file not found: $(PROJECT_NAME)_spark.gpr$(NC)"; \
exit 1; \
fi
@cd $(TEST_DIR) && $(ALR) exec -- gnatprove -j0 -P ../$(PROJECT_NAME)_spark.gpr --mode=prove --level=2 2>&1; \
if [ $$? -eq 0 ]; then \
echo "$(GREEN)✓ SPARK PROVE verification passed$(NC)"; \
else \
echo "$(RED)✗ SPARK PROVE verification failed$(NC)"; \
exit 1; \
fi
# FIXME: REPLACE WITH THE ADAFMT TOOL WE ARE CREATING WHEN IT IS COMPLETED.
# THE CURRENT SCRIPT IS COMMENTING COMMENTS AND MESSING UP WITH INDEXED COMMENTS.
# format-src:
# @echo "$(GREEN)Formatting source code...$(NC)"
# @if [ ! -f "scripts/python/shared/makefile/ada_formatter_pipeline.donotuse.py" ]; then \
# echo "$(RED)Error: scripts/python/shared/makefile/ada_formatter_pipeline.donotuse.py not found$(NC)"; \
# exit 1; \
# fi
# @for dir in $(SRC_DIR); do \
# if [ -d "$$dir" ]; then \
# find "$$dir" -name "*.ads" -o -name "*.adb" | \
# while read file; do \
# echo " Formatting $$file..."; \
# $(PYTHON3) scripts/python/shared/makefile/ada_formatter_pipeline.donotuse.py "$(PWD)/$(PROJECT_NAME).gpr" --include-path "$(PWD)/$$file" || true; \
# done; \
# fi; \
# done
# @echo "$(GREEN)✓ Source formatting complete$(NC)"
# format-tests:
# @echo "$(GREEN)Formatting test code...$(NC)"
# @if [ ! -f "scripts/python/shared/makefile/ada_formatter_pipeline.donotuse.py" ]; then \
# echo "$(RED)Error: scripts/python/shared/makefile/ada_formatter_pipeline.donotuse.py not found$(NC)"; \
# exit 1; \
# fi
# @if [ -d "$(TEST_DIR)" ] && [ -f "$(TEST_DIR)/tests.gpr" ]; then \
# find $(TEST_DIR) -name "*.ads" -o -name "*.adb" | \
# while read file; do \
# echo " Formatting $$file..."; \
# $(PYTHON3) scripts/python/shared/makefile/ada_formatter_pipeline.donotuse.py "$(PWD)/$(TEST_DIR)/tests.gpr" --include-path "$(PWD)/$$file" || true; \
# done; \
# echo "$(GREEN)✓ Test formatting complete$(NC)"; \
# fi
# format-all: format-src format-tests
# @echo "$(GREEN)✓ All code formatting complete$(NC)"
# format: format-all
# =============================================================================
# Development Commands
# =============================================================================
stats:
@echo "$(CYAN)$(BOLD)Project Statistics for $(PROJECT_NAME)$(NC)"
@echo "$(YELLOW)════════════════════════════════════════$(NC)"
@echo ""
@echo "Ada Source Files:"
@echo " Library specs: $$(find $(SRC_DIR) -name "*.ads" 2>/dev/null | wc -l | tr -d ' ')"
@echo " Library bodies: $$(find $(SRC_DIR) -name "*.adb" 2>/dev/null | wc -l | tr -d ' ')"
@echo " Test specs: $$(find $(TEST_DIR) -name "*.ads" 2>/dev/null | wc -l | tr -d ' ')"
@echo " Test bodies: $$(find $(TEST_DIR) -name "*.adb" 2>/dev/null | wc -l | tr -d ' ')"
@echo ""
@echo "Lines of Code:"
@find $(SRC_DIR) $(TEST_DIR) -name "*.ads" -o -name "*.adb" 2>/dev/null | \
xargs wc -l 2>/dev/null | tail -1 | awk '{printf " Total: %d lines\n", $$1}' || \
echo " Total: 0 lines"
@echo ""
@echo "Build Artifacts:"
@if [ -f "./lib/libfunctional.a" ]; then \
echo " Library: $$(ls -lh ./lib/libfunctional.a 2>/dev/null | awk '{print $$5}')"; \
else \
echo " No library found (run 'make build')"; \
fi
# =============================================================================
# Advanced Targets
# =============================================================================
deps: ## Display project dependencies
@echo "$(CYAN)Project dependencies from alire.toml:$(NC)"
@grep -A 10 "\[\[depends-on\]\]" alire.toml || echo "$(YELLOW)No dependencies found$(NC)"
@echo ""
@echo "$(CYAN)Alire dependency tree:$(NC)"
@$(ALR) show --solve || echo "$(YELLOW)Could not resolve dependencies$(NC)"
refresh: ## Refresh Alire dependencies
@echo "$(CYAN)Refreshing Alire dependencies...$(NC)"
@$(ALR) update
@echo "$(GREEN)✓ Dependencies refreshed$(NC)"
install-tools: ## Install development tools (GMP, gcovr, gnatformat)
@echo "$(CYAN)Installing development tools...$(NC)"
@$(PYTHON3) scripts/python/shared/makefile/install_tools.py
@echo "$(GREEN)✓ Tool installation complete$(NC)"
build-coverage-runtime: ## Force rebuild GNATcoverage runtime library
@echo "$(CYAN)Rebuilding GNATcoverage runtime...$(NC)"
@$(PYTHON3) scripts/python/shared/makefile/coverage_ada.py --rebuild-runtime --unit-only
@echo "$(GREEN)✓ GNATcov runtime rebuilt (run 'make test-coverage' for full analysis)$(NC)"
.DEFAULT_GOAL := help
## ---------------------------------------------------------------------------
## Documentation
## ---------------------------------------------------------------------------
docs-formal: ## Compile Typst formal docs (SRS, SDS, STG) to PDF
@python3 scripts/python/shared/makefile/compile_formal_docs.py
## ---------------------------------------------------------------------------
## Submodule Management
## ---------------------------------------------------------------------------
submodule-init: ## Initialize submodules after fresh clone
git submodule update --init --recursive
submodule-update: ## Pull latest from all submodule repos
git submodule update --remote --merge
@echo ""
@echo "Submodules updated. Review changes, then run:"
@echo " git add docs/common scripts/python test/scripts/python/shared"
@echo " git commit -m 'chore: update submodules'"
@echo " git push"
submodule-status: ## Show submodule commit status
git submodule status