-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
225 lines (180 loc) · 6.88 KB
/
Copy pathMakefile
File metadata and controls
225 lines (180 loc) · 6.88 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
# agent-calc developer and local-install workflow.
#
# Philosophy:
# - Fast targets should stay fast.
# - Heavy targets should be explicit.
# - Install should respect standard local prefixes.
# - CI/release targets should compose smaller targets without hiding failures.
SHELL := /usr/bin/env bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
BIN_NAME := agent-calc
PACKAGE := agent-calc
TARGET_DIR := target
PROFILE ?= release
PREFIX ?= $(HOME)/.local
BINDIR ?= $(PREFIX)/bin
INSTALL_PATH := $(BINDIR)/$(BIN_NAME)
CARGO ?= cargo
CARGO_FLAGS ?=
CARGO_TEST_FLAGS ?=
CARGO_MUTANTS_FLAGS ?=
RUST_SOURCES := $(shell find src tests -type f -name '*.rs' 2>/dev/null)
MANIFESTS := Cargo.toml Cargo.lock mutants.toml
.PHONY: help
help: ## Show available targets.
@awk 'BEGIN {FS = ":.*##"; printf "\nagent-calc Makefile\n\nUsage:\n make <target>\n\nTargets:\n"} /^[a-zA-Z0-9_.-]+:.*##/ {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@printf "\nVariables:\n"
@printf " PREFIX=%s\n" "$(PREFIX)"
@printf " BINDIR=%s\n" "$(BINDIR)"
@printf " PROFILE=%s\n" "$(PROFILE)"
@printf "\nExamples:\n"
@printf " make test\n"
@printf " make install PREFIX=$$HOME/.local\n"
@printf " make full\n\n"
.PHONY: all
all: fmt-check check test package ## Run the standard local release gate, excluding mutation.
.PHONY: full
full: all mutants ## Run the full release gate, including mutation testing.
.PHONY: ci
ci: all ## Alias for the non-mutating CI-safe gate.
.PHONY: ready
ready: full ## Alias for the strongest local readiness gate.
.PHONY: best
best: full ## Run the strongest Makefile target.
.PHONY: build
build: ## Build the debug binary.
$(CARGO) build $(CARGO_FLAGS)
.PHONY: release
release: ## Build the optimized release binary.
$(CARGO) build --release $(CARGO_FLAGS)
.PHONY: run
run: ## Run agent-calc with ARGS='...'.
$(CARGO) run $(CARGO_FLAGS) -- $(ARGS)
.PHONY: describe
describe: ## Emit the executable contract JSON.
$(CARGO) run $(CARGO_FLAGS) -- describe
.PHONY: schema
schema: ## Emit a JSON schema. Use DOMAIN=finance, solve, matrix, etc.
$(CARGO) run $(CARGO_FLAGS) -- schema $(DOMAIN)
.PHONY: fmt
fmt: ## Format Rust sources.
$(CARGO) fmt --all
.PHONY: fmt-check
fmt-check: ## Check Rust formatting without writing changes.
$(CARGO) fmt --all -- --check
.PHONY: check
check: ## Type-check all targets.
$(CARGO) check --all-targets $(CARGO_FLAGS)
.PHONY: clippy
clippy: ## Run clippy when the component is installed.
@if rustup component list --installed 2>/dev/null | grep -qx 'clippy'; then \
$(CARGO) clippy --all-targets $(CARGO_FLAGS) -- -D warnings; \
else \
echo "clippy component is not installed; run: rustup component add clippy"; \
exit 2; \
fi
.PHONY: test
test: ## Run the full test suite.
$(CARGO) test $(CARGO_FLAGS) $(CARGO_TEST_FLAGS)
.PHONY: test-quiet
test-quiet: ## Run tests with quiet cargo output.
$(CARGO) test --quiet $(CARGO_FLAGS) $(CARGO_TEST_FLAGS)
.PHONY: mutants
mutants: ## Run cargo-mutants.
$(CARGO) mutants $(CARGO_MUTANTS_FLAGS)
.PHONY: mutants-list
mutants-list: ## List discovered mutants without running them.
$(CARGO) mutants --list
.PHONY: bench
bench: ## Run benchmarks if any are present.
$(CARGO) bench $(CARGO_FLAGS)
.PHONY: package
package: ## Verify the crate can be packaged.
$(CARGO) package --allow-dirty --locked --offline $(CARGO_FLAGS)
.PHONY: audit
audit: ## Run cargo-audit if installed.
@if command -v cargo-audit >/dev/null 2>&1; then \
cargo audit; \
else \
echo "cargo-audit is not installed; install with: cargo install cargo-audit"; \
exit 2; \
fi
.PHONY: deny
deny: ## Run cargo-deny if installed.
@if command -v cargo-deny >/dev/null 2>&1; then \
cargo deny check; \
else \
echo "cargo-deny is not installed; install with: cargo install cargo-deny"; \
exit 2; \
fi
.PHONY: security
security: audit deny ## Run supply-chain checks that are available locally.
.PHONY: install
install: release ## Install optimized binary to BINDIR. Override PREFIX or BINDIR as needed.
install -d "$(BINDIR)"
install -m 0755 "$(TARGET_DIR)/release/$(BIN_NAME)" "$(INSTALL_PATH)"
@echo "installed $(BIN_NAME) -> $(INSTALL_PATH)"
@echo "make sure $(BINDIR) is on PATH"
.PHONY: install-local
install-local: install ## Explicit alias for local install.
.PHONY: install-cargo
install-cargo: ## Install via cargo install --path.
$(CARGO) install --path . --locked --force --root "$(PREFIX)"
@echo "installed $(BIN_NAME) under $(PREFIX)/bin"
.PHONY: uninstall
uninstall: ## Remove the locally installed binary from BINDIR.
@if [ -e "$(INSTALL_PATH)" ]; then \
rm -f "$(INSTALL_PATH)"; \
echo "removed $(INSTALL_PATH)"; \
else \
echo "$(INSTALL_PATH) is not installed"; \
fi
.PHONY: uninstall-local
uninstall-local: uninstall ## Explicit alias for local uninstall.
.PHONY: reinstall
reinstall: uninstall install ## Rebuild and reinstall the local binary.
.PHONY: install-hooks
install-hooks: ## Install git hooks from hooks/ via core.hooksPath (no file copying needed).
git config core.hooksPath hooks
@echo "git hooks active — hooks/ is now the hooks directory"
@echo "pre-commit: fmt + check + clippy + test + package + smoke"
@echo "pre-push: mutation testing on changed src/ files (main only)"
.PHONY: uninstall-hooks
uninstall-hooks: ## Remove the core.hooksPath override and revert to .git/hooks/.
git config --unset core.hooksPath || true
@echo "hooks directory reverted to .git/hooks/"
.PHONY: smoke
smoke: build ## Run cheap CLI smoke checks against the debug binary.
"$(TARGET_DIR)/debug/$(BIN_NAME)" --version
"$(TARGET_DIR)/debug/$(BIN_NAME)" describe >/dev/null
"$(TARGET_DIR)/debug/$(BIN_NAME)" schema >/dev/null
printf '%s\n' '{"expr":{"kind":"add","left":{"kind":"integer","value":"2"},"right":{"kind":"integer","value":"3"}}}' | "$(TARGET_DIR)/debug/$(BIN_NAME)" eval >/dev/null
printf '%s\n' '{"intent":"eval","expr":{"kind":"add","left":{"kind":"integer","value":"2"},"right":{"kind":"integer","value":"3"}}}' | "$(TARGET_DIR)/debug/$(BIN_NAME)" trace >/dev/null
.PHONY: clean
clean: ## Remove cargo build artifacts.
$(CARGO) clean
.PHONY: clean-mutants
clean-mutants: ## Remove cargo-mutants output directories.
rm -rf mutants.out mutants.out.old
.PHONY: distclean
distclean: clean clean-mutants ## Remove all generated local artifacts.
.PHONY: docs
docs: ## Build local Rust docs.
$(CARGO) doc --no-deps $(CARGO_FLAGS)
.PHONY: open-docs
open-docs: docs ## Print the local docs entry point.
@printf '%s\n' "$(PWD)/$(TARGET_DIR)/doc/$(subst -,_,$(PACKAGE))/index.html"
.PHONY: tree
tree: ## Show the important project files.
@printf "Package: %s\nBinary: %s\nPrefix: %s\n\n" "$(PACKAGE)" "$(BIN_NAME)" "$(PREFIX)"
@printf "Rust sources:\n"
@printf ' %s\n' $(RUST_SOURCES)
@printf "\nManifests:\n"
@printf ' %s\n' $(MANIFESTS)
.PHONY: version
version: ## Print toolchain and package versions.
@printf "package: %s\n" "$(PACKAGE)"
@$(CARGO) --version
@rustc --version
@rustup show active-toolchain 2>/dev/null || true