-
Notifications
You must be signed in to change notification settings - Fork 594
Expand file tree
/
Copy pathMakefile
More file actions
293 lines (266 loc) · 16.7 KB
/
Copy pathMakefile
File metadata and controls
293 lines (266 loc) · 16.7 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
.PHONY: tests
build: cs tests phpstan
tests: install-paratest
XDEBUG_MODE=off php tests/vendor/bin/paratest --runner WrapperRunner --no-coverage
tests-integration: install-paratest
php tests/vendor/bin/paratest --runner WrapperRunner --no-coverage --group exec
tests-golden-reflection:
php vendor/bin/phpunit tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php
lint:
XDEBUG_MODE=off php vendor/bin/parallel-lint --colors \
--exclude tests/PHPStan/Analyser/data \
--exclude tests/bench/data \
--exclude tests/PHPStan/Analyser/nsrt \
--exclude tests/PHPStan/Rules/Methods/data \
--exclude tests/PHPStan/Rules/Functions/data \
--exclude tests/PHPStan/Rules/Names/data \
--exclude tests/PHPStan/Rules/Operators/data/invalid-inc-dec.php \
--exclude tests/PHPStan/Rules/Arrays/data/offset-access-without-dim-for-reading.php \
--exclude tests/PHPStan/Rules/Classes/data/bug-11891.php \
--exclude tests/PHPStan/Rules/Classes/data/bug-13768.php \
--exclude tests/PHPStan/Rules/Classes/data/duplicate-declarations.php \
--exclude tests/PHPStan/Rules/Classes/data/duplicate-enum-cases.php \
--exclude tests/PHPStan/Rules/Classes/data/enum-sanity.php \
--exclude tests/PHPStan/Rules/Classes/data/extends-error.php \
--exclude tests/PHPStan/Rules/Classes/data/implements-error.php \
--exclude tests/PHPStan/Rules/Classes/data/interface-extends-error.php \
--exclude tests/PHPStan/Rules/Classes/data/trait-use-error.php \
--exclude tests/PHPStan/Rules/Methods/data/method-in-enum-without-body.php \
--exclude tests/PHPStan/Rules/Properties/data/default-value-for-native-property-type.php \
--exclude tests/PHPStan/Rules/Arrays/data/empty-array-item.php \
--exclude tests/PHPStan/Rules/Classes/data/invalid-promoted-properties.php \
--exclude tests/PHPStan/Rules/Classes/data/duplicate-promoted-property.php \
--exclude tests/PHPStan/Rules/Properties/data/default-value-for-promoted-property.php \
--exclude tests/PHPStan/Rules/Operators/data/invalid-assign-var.php \
--exclude tests/PHPStan/Rules/Functions/data/arrow-function-nullsafe-by-ref.php \
--exclude tests/PHPStan/Levels/data/namedArguments.php \
--exclude tests/PHPStan/Rules/Keywords/data/continue-break.php \
--exclude tests/PHPStan/Rules/Keywords/data/continue-break-property-hook.php \
--exclude tests/PHPStan/Rules/Keywords/data/goto-undefined-label.php \
--exclude tests/PHPStan/Rules/Keywords/data/goto-undefined-label-property-hook.php \
--exclude tests/PHPStan/Rules/Keywords/data/unused-label-property-hook.php \
--exclude tests/PHPStan/Rules/Keywords/data/bug-13790-break.php \
--exclude tests/PHPStan/Rules/Keywords/data/bug-13790-continue.php \
--exclude tests/PHPStan/Rules/Properties/data/invalid-callable-property-type.php \
--exclude tests/PHPStan/Rules/Properties/data/properties-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/read-only-property.php \
--exclude tests/PHPStan/Rules/Properties/data/read-only-property-phpdoc-and-native.php \
--exclude tests/PHPStan/Rules/Properties/data/read-only-property-readonly-class.php \
--exclude tests/PHPStan/Rules/Properties/data/overriding-property.php \
--exclude tests/PHPStan/Rules/Constants/data/overriding-final-constant.php \
--exclude tests/PHPStan/Rules/Properties/data/intersection-types.php \
--exclude tests/PHPStan/Rules/Classes/data/first-class-instantiation-callable.php \
--exclude tests/PHPStan/Rules/Classes/data/instantiation-callable.php \
--exclude tests/PHPStan/Rules/Classes/data/bug-9402.php \
--exclude tests/PHPStan/Rules/Constants/data/class-as-class-constant.php \
--exclude tests/PHPStan/Rules/Constants/data/value-assigned-to-class-constant-native-type.php \
--exclude tests/PHPStan/Rules/Constants/data/overriding-constant-native-types.php \
--exclude tests/PHPStan/Rules/Methods/data/bug-10043.php \
--exclude tests/PHPStan/Rules/Methods/data/bug-7859.php \
--exclude tests/PHPStan/Rules/Methods/data/bug-8081.php \
--exclude tests/PHPStan/Rules/Methods/data/bug-9014.php \
--exclude tests/PHPStan/Rules/Methods/data/bug-10101.php \
--exclude tests/PHPStan/Rules/Methods/data/final-method-by-phpdoc.php \
--exclude tests/PHPStan/Rules/Traits/data/conflicting-trait-constants-types.php \
--exclude tests/PHPStan/Rules/Types/data/invalid-union-with-mixed.php \
--exclude tests/PHPStan/Rules/Types/data/invalid-union-with-never.php \
--exclude tests/PHPStan/Rules/Types/data/invalid-union-with-void.php \
--exclude tests/PHPStan/Rules/Constants/data/dynamic-class-constant-fetch.php \
--exclude tests/PHPStan/Rules/Keywords/data/declare-position.php \
--exclude tests/PHPStan/Rules/Keywords/data/declare-position2.php \
--exclude tests/PHPStan/Rules/Keywords/data/declare-position-nested.php \
--exclude tests/PHPStan/Rules/Keywords/data/declare-strict-nonsense.php \
--exclude tests/PHPStan/Rules/Keywords/data/declare-strict-nonsense-bool.php \
--exclude tests/PHPStan/Rules/Keywords/data/declare-inline-html.php \
--exclude tests/PHPStan/Rules/Classes/data/extends-readonly-class.php \
--exclude tests/PHPStan/Rules/Classes/data/instantiation-promoted-properties.php \
--exclude tests/PHPStan/Rules/Classes/data/bug-11592.php \
--exclude tests/PHPStan/Rules/Properties/data/property-hooks-bodies-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/property-hooks-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/property-hooks-visibility-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/abstract-hooked-properties-in-class.php \
--exclude tests/PHPStan/Rules/Properties/data/abstract-hooked-properties-with-bodies.php \
--exclude tests/PHPStan/Rules/Properties/data/abstract-non-hooked-properties-in-abstract-class.php \
--exclude tests/PHPStan/Rules/Properties/data/non-abstract-hooked-properties-in-abstract-class.php \
--exclude tests/PHPStan/Rules/Properties/data/non-abstract-hooked-properties-in-class.php \
--exclude tests/PHPStan/Rules/Properties/data/hooked-properties-in-class.php \
--exclude tests/PHPStan/Rules/Properties/data/hooked-properties-without-bodies-in-class.php \
--exclude tests/PHPStan/Rules/Properties/data/readonly-property-hooks.php \
--exclude tests/PHPStan/Rules/Properties/data/readonly-property-hooks-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/static-hooked-properties.php \
--exclude tests/PHPStan/Rules/Properties/data/static-hooked-property-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/virtual-hooked-properties.php \
--exclude tests/PHPStan/Rules/Classes/data/bug-12281.php \
--exclude tests/PHPStan/Rules/Traits/data/bug-12281.php \
--exclude tests/PHPStan/Rules/Classes/data/invalid-hooked-properties.php \
--exclude tests/PHPStan/Parser/data/cleaning-property-hooks-before.php \
--exclude tests/PHPStan/Parser/data/cleaning-property-hooks-after.php \
--exclude tests/PHPStan/Rules/Properties/data/abstract-private-property-hook.php \
--exclude tests/PHPStan/Rules/Properties/data/existing-classes-property-hooks.php \
--exclude tests/PHPStan/Rules/Properties/data/set-property-hook-parameter.php \
--exclude tests/PHPStan/Rules/Properties/data/overriding-final-property.php \
--exclude tests/PHPStan/Rules/Properties/data/private-final-property-hooks.php \
--exclude tests/PHPStan/Rules/Properties/data/abstract-final-property-hook.php \
--exclude tests/PHPStan/Rules/Properties/data/final-property-hooks-in-interface.php \
--exclude tests/PHPStan/Rules/Properties/data/final-property-hooks.php \
--exclude tests/PHPStan/Rules/Properties/data/final-properties.php \
--exclude tests/PHPStan/Rules/Properties/data/property-in-interface-explicit-abstract.php \
--exclude tests/PHPStan/Rules/Constants/data/final-private-const.php \
--exclude tests/PHPStan/Rules/Properties/data/abstract-final-property-hook-parse-error.php \
--exclude tests/PHPStan/Rules/Playground/data/promote-missing-override.php \
--exclude tests/PHPStan/Rules/Traits/data/trait-attributes.php \
--exclude tests/PHPStan/Rules/Classes/data/non-class-attribute-class.php \
--exclude tests/PHPStan/Rules/Classes/data/enum-cannot-be-attribute.php \
--exclude tests/PHPStan/Rules/Classes/data/class-attributes.php \
--exclude tests/PHPStan/Rules/Classes/data/enum-attributes.php \
--exclude tests/PHPStan/Rules/Cast/data/void-cast.php \
--exclude tests/PHPStan/Rules/Properties/data/property-hook-attributes-nodiscard.php \
--exclude tests/PHPStan/Rules/Functions/data/arrow-function-typehints-nodiscard.php \
--exclude tests/PHPStan/Rules/Functions/data/closure-typehints-nodiscard.php \
--exclude tests/PHPStan/Reflection/data/ClassWithConstants.php \
--exclude tests/PHPStan/Rules/Functions/data/typehints-nodiscard.php \
--exclude tests/PHPStan/Rules/Methods/data/typehints-nodiscard.php \
--exclude tests/PHPStan/Rules/Cast/data/deprecated-cast.php \
--exclude tests/PHPStan/Rules/Classes/data/deprecated-attr-on-class.php \
--exclude tests/PHPStan/Rules/Properties/data/property-override-attr-missing.php \
--exclude tests/PHPStan/Rules/Properties/data/override-attr-on-property.php \
--exclude tests/PHPStan/Rules/Properties/data/property-override-attr.php \
--exclude tests/PHPStan/Rules/Classes/data/bug-14250.php \
--exclude tests/PHPStan/Rules/Classes/data/bug-14250-promoted-properties.php \
--exclude tests/PHPStan/Rules/Operators/data/bug-3585.php \
--exclude tests/PHPStan/Rules/EnumCases/data/bug-14252.php \
--exclude tests/PHPStan/Rules/Functions/data/bug-14241.php \
--exclude tests/PHPStan/Rules/Variables/data/bug-14349.php \
--exclude tests/PHPStan/Rules/Variables/data/bug-14352.php \
--exclude tests/PHPStan/Rules/Variables/data/bug-14351.php \
--exclude tests/PHPStan/Rules/Properties/data/bug-14457.php \
src tests
install-paratest:
composer install --working-dir tests
.PHONY: cs-install
cs-install:
git clone https://github.com/phpstan/build-cs.git || true
git -C build-cs fetch origin && git -C build-cs reset --hard origin/2.x
composer install --working-dir build-cs
.PHONY: cs
cs: cs-install
XDEBUG_MODE=off php build-cs/vendor/bin/phpcs
.PHONY: cs-fix
cs-fix: cs-install
XDEBUG_MODE=off php build-cs/vendor/bin/phpcbf
phpstan:
php bin/phpstan clear-result-cache -q && php -d memory_limit=450M bin/phpstan -v
phpstan-result-cache:
php -d memory_limit=450M bin/phpstan
phpstan-fix:
php -d memory_limit=450M bin/phpstan --fix
phpstan-generate-baseline:
php -d memory_limit=450M bin/phpstan --generate-baseline
phpstan-generate-baseline-php:
php -d memory_limit=450M bin/phpstan analyse --generate-baseline phpstan-baseline.php
phpstan-pro:
php -d memory_limit=450M bin/phpstan --pro
name-collision:
php vendor/bin/detect-collisions --configuration build/collision-detector.json
composer-dependency-analyser:
php vendor/bin/composer-dependency-analyser --config build/composer-dependency-analyser.php
.PHONY: infection
infection:
git -C build-infection pull || git clone https://github.com/phpstan/build-infection.git
git -C build-infection fetch origin && git -C build-infection reset --hard origin/1.x
composer install --working-dir build-infection --no-interaction --no-progress
php build-infection/bin/infection-config.php --source-directory='build/PHPStan/Build'> infection.json5
XDEBUG_MODE=coverage php tests/vendor/bin/paratest \
--coverage-xml=tmp/coverage/coverage-xml \
--log-junit=tmp/coverage/junit.xml
php build-infection/vendor/bin/infection \
--configuration=infection.json5 \
--git-diff-base=origin/HEAD \
--git-diff-lines \
--coverage=tmp/coverage \
--skip-initial-tests \
--ignore-msi-with-no-mutations \
--logger-text=php://stdout
.PHONY: phpbench
phpbench:
@find tests/bench/storage/local-baseline.xml -mtime -60m | grep . || (echo "PHPBench baseline file does not exist or is too old. Regenerate it using 'make phpbench-baseline'." && exit 1)
XDEBUG_MODE=off tests/vendor/bin/phpbench run --file=tests/bench/storage/local-baseline.xml --report=my-report
.PHONY: phpbench-baseline
phpbench-baseline:
XDEBUG_MODE=off tests/vendor/bin/phpbench run --dump-file=tests/bench/storage/local-baseline.xml
download-coverage:
rm -rf tmp/coverage-download
mkdir tmp/coverage-download
(cd tmp/coverage-download; gh run download `gh run ls --repo=phpstan/phpstan-src --branch=\`git for-each-ref --format='%(upstream:short)' $$(git symbolic-ref -q HEAD) | cut -d/ -f2- \` --workflow=tests.yml --limit=1 --json=databaseId --jq '.[].databaseId'` --repo=phpstan/phpstan-src --name=coverage-reports)
sed -i '' -e 's,/home/runner/work/phpstan-src/phpstan-src/,'"$$PWD"/',g' tmp/coverage-download/clover.xml
cp tmp/coverage-download/clover.xml tmp/coverage/clover.xml
# Builds turbo-ext/phpstan_turbo.so for the machine and the PHP this runs on,
# in parallel over the local cores — plain `make -C turbo-ext` builds one
# translation unit at a time, and there are ~170 of them. The interpreter it
# builds against is whatever `php-config` is on PATH; point it elsewhere with
# `make build-turbo PHP_CONFIG=/path/to/php-config` (command-line variables
# reach the sub-make through MAKEFLAGS). Nothing is installed: load the
# result with `php -d extension=...`, or from the ini scan dir when the run
# re-executes itself (TurboProcessRestarter drops a -d extension).
TURBO_JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)
.PHONY: build-turbo
build-turbo:
$(MAKE) -C turbo-ext -j$(TURBO_JOBS)
@# The binary bakes its version from `git log -- turbo-ext/src`, and
@# TurboExtensionEnabler activates only the version it expects — a build
@# from a shallow clone ("dev"), or one made between a turbo-ext/src
@# commit and its `make bump-turbo`, loads but stays inactive, which
@# otherwise only shows up as "nothing got faster".
@# -n: the machine's php.ini usually loads the extension already, and
@# the "Module is already loaded" warning that a second -d then prints
@# goes to stdout, i.e. into the version being read. An ini-less probe
@# also guarantees the version reported is the binary just built.
@BUILT="$$(php -n -d display_errors=stderr -d extension="$(CURDIR)/turbo-ext/phpstan_turbo.so" -r 'echo phpversion("phpstan_turbo");' 2>/dev/null)"; \
EXPECTED="$$(sed -n "s/.*EXPECTED_EXTENSION_VERSION = '\([^']*\)'.*/\1/p" src/Turbo/TurboExtensionEnabler.php)"; \
echo "built $(CURDIR)/turbo-ext/phpstan_turbo.so$${BUILT:+ (version $$BUILT)}"; \
if [ -n "$$BUILT" ] && [ "$$BUILT" != "$$EXPECTED" ]; then \
echo "warning: TurboExtensionEnabler expects $$EXPECTED, so this build would load but stay inactive (run 'make bump-turbo' once the turbo-ext/src commit is in)"; \
fi
# The expected turbo version is the short SHA of the last commit touching
# turbo-ext/src (enforced by the phar.yml turbo-version job), so the bump can
# never be part of the commit it points at. Refreshes an unpushed bump commit
# in place — after a rebase gives the watched commit a new SHA, rerunning
# this amends instead of stacking a second bump commit.
.PHONY: bump-turbo
bump-turbo:
@if [ -n "$$(git status --porcelain -- turbo-ext/src)" ]; then \
echo "turbo-ext/src has uncommitted changes — commit them first, the expected version is the short SHA of the last commit touching turbo-ext/src"; \
exit 1; \
fi; \
if ! git diff --quiet HEAD -- src/Turbo/TurboExtensionEnabler.php; then \
echo "src/Turbo/TurboExtensionEnabler.php has uncommitted changes — commit or stash them first"; \
exit 1; \
fi; \
EXPECTED="$$(git log -1 --format=%H -- turbo-ext/src | cut -c1-7)"; \
CURRENT="$$(sed -n "s/.*EXPECTED_EXTENSION_VERSION = '\([^']*\)'.*/\1/p" src/Turbo/TurboExtensionEnabler.php)"; \
if [ "$$EXPECTED" = "$$CURRENT" ]; then \
echo "TurboExtensionEnabler::EXPECTED_EXTENSION_VERSION is already $$EXPECTED"; \
exit 0; \
fi; \
sed -i '' -e "s/EXPECTED_EXTENSION_VERSION = '$$CURRENT'/EXPECTED_EXTENSION_VERSION = '$$EXPECTED'/" src/Turbo/TurboExtensionEnabler.php; \
if [ "$$(git log -1 --format=%s)" = "Bump expected turbo version" ] && [ -z "$$(git branch -r --contains HEAD)" ]; then \
git commit --amend --no-edit -- src/Turbo/TurboExtensionEnabler.php; \
echo "amended the unpushed bump commit: $$CURRENT -> $$EXPECTED"; \
else \
git commit -m "Bump expected turbo version" -- src/Turbo/TurboExtensionEnabler.php; \
echo "bumped: $$CURRENT -> $$EXPECTED"; \
fi
# Static analysis of the native extension's hand-written C++ sources. The
# enabled checks and the measured reason for every exclusion are in
# turbo-ext/.clang-tidy; a finding fails the target rather than being
# baselined.
.PHONY: lint-turbo
lint-turbo:
$(MAKE) -C turbo-ext lint
# Builds the extension with UndefinedBehaviorSanitizer and runs the
# differential tests under it: the native results must still equal the PHP
# twins' with no sanitizer diagnostic. This is the memory-safety half of the
# checks — the static ones cannot see zval lifetimes.
.PHONY: sanitize-turbo
sanitize-turbo:
$(MAKE) -C turbo-ext sanitize