Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
218 lines (181 loc) · 10 KB
/
Copy pathMakefile
File metadata and controls
218 lines (181 loc) · 10 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
# custos — developer entry points. `make verify` is the definition of done.
EA_PATH ?= $(HOME)/Sites/phpinspectionsea
RULE ?=
GO ?= go
BIN := bin/custos
STUBS_REPO ?= https://github.com/JetBrains/phpstorm-stubs
FIXCHECK ?= 1
FIXCHECK_TIMEOUT ?= 30m
.PHONY: doc-examples architecture deprecations examples coverage fixcheck mutations formatcheck corpus-baseline corpus-diff typecov stubs build test vet fmt fmt-check lint bench compare compare-doc fuzz extract rules-doc fixtures conformance cleanroom verify clean docs docs-dev
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
build:
$(GO) build -trimpath -ldflags "-X main.version=$(VERSION)" -o $(BIN) ./cmd/custos
test:
$(GO) test ./...
# Linters are pinned and run through `go run` (built once with the local Go,
# then cached); markdownlint comes from docs/package.json (`npm ci --prefix
# docs`). Set any of them empty to skip it, e.g. `make lint MDLINT=` offline.
GOLANGCI ?= $(GO) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0
ACTIONLINT ?= $(GO) run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12
ECCHECK ?= $(GO) run github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.11.3
MDLINT ?= docs/node_modules/.bin/markdownlint-cli2
# Rules: .golangci.yml, .editorconfig (+ .editorconfig-checker.json),
# .markdownlint-cli2.jsonc. See docs/contributing/index.md.
lint:
@$(if $(GOLANGCI),$(GOLANGCI) run ./...,echo "golangci-lint skipped")
@$(if $(ACTIONLINT),$(ACTIONLINT),echo "actionlint skipped")
@$(if $(ECCHECK),$(ECCHECK),echo "editorconfig-checker skipped")
@$(if $(MDLINT),if [ ! -x "$(MDLINT)" ]; then echo "markdownlint missing: run npm ci --prefix docs (or MDLINT= to skip)"; exit 1; fi; $(MDLINT),echo "markdownlint skipped")
# Apply the formatters (gofumpt, goimports) and markdownlint's fixes.
fmt:
$(GOLANGCI) fmt
@if [ -n "$(MDLINT)" ]; then $(MDLINT) --fix; fi
# Kept as shortcuts: both are part of `make lint`.
vet:
$(GOLANGCI) run --enable-only govet ./...
fmt-check:
$(GOLANGCI) fmt --diff
# Benchmarks on a real file need CUSTOS_BENCH_FILE (a large PHP source).
bench:
$(GO) test -run '^$$' -bench . -benchmem ./...
CUSTOS_PERF=1 $(GO) test -count=1 -run TestEditLatency -v ./internal/editor/lsp
# Compare custos with other PHP tools on real projects (bench/competitors.json):
# install the pinned tools and corpora under .cache/bench (needs PHP with the
# ast and pcntl extensions, Composer and git), measure, and regenerate
# docs/guide/benchmark.md. TOOL= and CORPUS= take comma-separated filters; a
# filtered run writes .cache/bench/results.json instead of bench/results.json.
TOOL ?=
CORPUS ?=
BENCH_RESULTS = $(if $(TOOL)$(CORPUS),.cache/bench/results.json,bench/results.json)
compare: build
$(GO) run ./tools/benchcmp install -tool "$(TOOL)" -corpus "$(CORPUS)"
$(GO) run ./tools/benchcmp run -tool "$(TOOL)" -corpus "$(CORPUS)" -results $(BENCH_RESULTS)
$(GO) run ./tools/benchcmp render -results $(BENCH_RESULTS) $(if $(TOOL)$(CORPUS),-page .cache/bench/benchmark.md -readme "")
# Regenerate docs/guide/benchmark.md and the README comparison from
# bench/results.json and bench/features.json.
compare-doc:
$(GO) run ./tools/benchcmp render
# Short fuzz smoke over every Fuzz* target.
fuzz:
@for pkg in $$($(GO) list ./...); do \
for f in $$($(GO) test -list '^Fuzz' $$pkg | grep '^Fuzz'); do \
$(GO) test -run '^$$' -fuzz "^$$f$$" -fuzztime 30s $$pkg || exit 1; \
done; \
done
# Regenerate DeprecatedFeature's table of PHP's deprecated functions,
# methods and constants by running one PHP binary per release from 8.0 on:
# DEPRECATION_PHP="8.0=/path/to/php8.0 8.1=/path/to/php8.1 ...".
DEPRECATION_PHP ?=
deprecations:
$(GO) run ./tools/gendeprecations $(foreach p,$(DEPRECATION_PHP),-php $(p))
# Rebuild the embedded builtin symbol index from phpstorm-stubs (Apache-2.0).
stubs:
@ls -d .cache/stubs-src/*phpstorm-stubs* >/dev/null 2>&1 || \
(mkdir -p .cache/stubs-src && git clone --depth 1 $(STUBS_REPO) .cache/stubs-src/phpstorm-stubs)
$(GO) run ./tools/genstubs
# Regenerate rule facts (committed) and the local-only EA case index (.cache/).
extract:
$(GO) run ./tools/extract -ea "$(EA_PATH)"
$(MAKE) rules-doc
rules-doc:
$(GO) generate ./internal/inspection/catalogue
$(GO) run ./tools/rulesdoc
$(GO) run ./tools/genexplain
$(GO) run ./tools/rulesref
$(GO) run ./tools/formatdoc
# Documentation site (VitePress, Node 20+): build to docs/.vitepress/dist, or
# serve with live reload.
docs: rules-doc
npm --prefix docs ci
npm --prefix docs run build
docs-dev: rules-doc
npm --prefix docs install
npm --prefix docs run dev
# custos' own fixtures (CI gate).
fixtures:
$(GO) test ./internal/testing/conformance -run 'TestOwnFixtures' -rule "$(RULE)"
# EA fixtures read from a local checkout; never copied into this repo.
conformance:
EA_PATH="$(EA_PATH)" $(GO) test ./internal/testing/conformance -run 'TestEA' -v -rule "$(RULE)"
# Verbatim-text scan against the local EA checkout (skipped when absent).
cleanroom:
$(GO) run ./tools/cleanroom -ea "$(EA_PATH)"
# Apply every quick-fix offered on the real-world corpus (CUSTOS_CORPUS, a list
# of directories) and require the result to still parse, to need no newer PHP
# than the target, and each fix to remove its finding (FIXCHECK=php
# additionally runs php -l on samples). FIXCHECK_PHP=5.6 sets the target
# (default: the newest supported version); PHP_BIN is the php binary of that version FIXCHECK=php uses.
# FIXCHECK_TIMEOUT bounds the run (laravel alone takes about an hour).
fixcheck:
CUSTOS_FIXCHECK=$(FIXCHECK) CUSTOS_FIXCHECK_PHP=$(FIXCHECK_PHP) CUSTOS_PHP=$(PHP_BIN) $(GO) test ./internal/inspection/catalogue -run TestFixesKeepCodeParsable -v -timeout $(FIXCHECK_TIMEOUT)
# Report the findings of each rule's own fixtures that survive when the calls
# assigned to the variables they read only build closures (`f(...)`,
# `f($a, ...)`): suspects for a rule reading a closure as the call's result.
# A report to triage, not a gate: .cache/mutations.json (RULE=<ID> to filter).
mutations:
@mkdir -p .cache
@CUSTOS_MUTATIONS=1 $(GO) test ./internal/testing/conformance -run TestClosureMutations -v -timeout 60m -rule "$(RULE)" >.cache/mutations.log 2>&1; \
rc=$$?; grep -E 'surviving|^(--- FAIL|FAIL|panic)' .cache/mutations.log; exit $$rc
# Record the findings of every rule on the pinned corpora of
# bench/competitors.json, then compare a later build with that record:
# corpus-diff fails on any added or removed finding and writes them to
# .cache/corpus-diff/<corpus>.diff. Both install the corpora with their
# development packages under .cache/bench/corpora-dev, apart from the
# measured ones, so that the rules needing every requirement installed
# run. CORPORA= takes a comma-separated list; by default corpus-diff takes
# every corpus, including those checked at an old PHP version (`"php"`,
# e.g. swiftmailer at 5.6), which compare neither measures nor
# formatchecks.
CORPORA ?=
corpus-baseline: build
$(GO) run ./tools/benchcmp install -dev -tool custos -corpus "$(CORPORA)"
$(GO) run ./tools/corpusdiff -record -corpora "$(CORPORA)"
corpus-diff: build
$(GO) run ./tools/benchcmp install -dev -tool custos -corpus "$(CORPORA)"
$(GO) run ./tools/corpusdiff -corpora "$(CORPORA)"
# Format a copy of each corpus with each preset (PRESETS=, default all) and
# run the preset's reference checker on it: PHP_CodeSniffer, PHP-CS-Fixer,
# Pint, and drupal/coder (installed under .cache/formatcheck). Fails when a
# finding remains that internal/format/testdata/divergences.json does not
# explain. Needs PHP and Composer, so it is not part of verify.
PRESETS ?=
formatcheck: build
$(GO) run ./tools/benchcmp install -tool phpcs,php-cs-fixer,pint -corpus "$(CORPORA)"
$(GO) run ./tools/formatcheck -corpora "$(CORPORA)" -presets "$(PRESETS)"
# Share of expressions whose inferred type is unknown on the corpora, by
# kind and cause (TYPECOV: root=srcdir pairs separated by ';'). Writes
# .cache/typecov/run.summary and run.unknown.tsv.
CORPORA_DIR = $(CURDIR)/.cache/bench/corpora
TYPECOV ?= $(CORPORA_DIR)/guzzle=src;$(CORPORA_DIR)/composer=src;$(CORPORA_DIR)/laravel=src
typecov:
mkdir -p .cache/typecov
CUSTOS_TYPECOV="$(TYPECOV)" CUSTOS_TYPECOV_OUT="$(CURDIR)/.cache/typecov/run" $(GO) test ./internal/project -run '^TestTypeCoverage$$' -count=1 -timeout 30m
architecture:
$(GO) run ./tools/architecture
# Example programs using the public Go API (their own modules).
examples:
cd examples/custom-binary && $(GO) vet . && $(GO) build -o /dev/null .
# PHP examples in handwritten documentation; rule extracts are generated by rulesref.
doc-examples:
$(GO) run ./tools/docphp
verify: architecture lint test examples fixtures coverage cleanroom doc-examples
# Coverage gates (the EA run and local corpora do not count):
# - every statement of internal/inspection/rules is covered by own fixtures and the rule
# packages' tests;
# - every statement of cmd/, internal/ and tools/ is covered by the whole test
# suite. tools/covercheck exempts only the body of a one-statement
# `func main()` in package main (each command's os.Exit(run(...)) wrapper),
# found from the source, so nothing has to be listed or kept in sync.
# Bound coverage test processes: each binary instruments the complete module.
COVER_SKIP := TestEA|TestNoCrashOnCorpus|TestFixesKeepCodeParsable
coverage:
@mkdir -p .cache
$(GO) test -p 4 ./internal/testing/conformance ./internal/inspection/catalogue ./internal/inspection/rules/... -skip '$(COVER_SKIP)' \
-coverpkg=./internal/inspection/rules/... -coverprofile=.cache/rules-cover.out >.cache/rules-cover.log 2>&1 \
|| { grep -E -B2 -A20 '^(--- FAIL|FAIL|panic:)' .cache/rules-cover.log; exit 1; }
@$(GO) run ./tools/covercheck -what internal/inspection/rules .cache/rules-cover.out
$(GO) test -p 4 ./... -skip '$(COVER_SKIP)' -coverpkg=./cmd/...,./internal/...,./tools/... -coverprofile=.cache/all-cover.out >.cache/all-cover.log 2>&1 \
|| { grep -E -B2 -A20 '^(--- FAIL|FAIL|panic:)' .cache/all-cover.log; exit 1; }
@$(GO) run ./tools/covercheck -what "cmd/, internal/ and tools/" .cache/all-cover.out
clean:
rm -rf bin dist docs/.vitepress/dist docs/.vitepress/cache