forked from box-project/box
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
278 lines (208 loc) · 9.95 KB
/
Makefile
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
.DEFAULT_GOAL := help
PHPNOGC=php -d zend.enable_gc=0
.PHONY: help
help:
@echo "\033[33mUsage:\033[0m\n make TARGET\n\n\033[32m#\n# Commands\n#---------------------------------------------------------------------------\033[0m\n"
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | awk 'BEGIN {FS = ":"}; {printf "\033[33m%s:\033[0m%s\n", $$1, $$2}'
#
# Commands
#---------------------------------------------------------------------------
.PHONY: clean
clean: ## Cleans all created artifacts
clean:
git clean --exclude=.idea/ -ffdx
.PHONY: cs
PHP_CS_FIXER=vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer
CODE_SNIFFER=vendor-bin/doctrine-cs/vendor/bin/phpcs
CODE_SNIFFER_FIX=vendor-bin/doctrine-cs/vendor/bin/phpcbf
cs: ## Fixes CS
cs: $(PHP_CS_FIXER) $(CODE_SNIFFER) $(CODE_SNIFFER_FIX)
$(PHPNOGC) $(CODE_SNIFFER_FIX) || true
$(PHPNOGC) $(CODE_SNIFFER)
$(PHPNOGC) $(PHP_CS_FIXER) fix
.PHONY: compile
compile: ## Compiles the application into the PHAR
compile: box
cp -f box bin/box.phar
.PHONY: dump-requirement-checker
dump-requirement-checker:## Dumps the requirement checker
dump-requirement-checker: requirement-checker requirement-checker/vendor
rm rf .requirement-checker || true
bin/box compile --working-dir requirement-checker
php bin/dump-requirements-checker.php
#
# Tests
#---------------------------------------------------------------------------
.PHONY: test
test: ## Runs all the tests
test: tu e2e
.PHONY: tu
tu: ## Runs the unit tests
tu: tu_requirement_checker tu_box
.PHONY: tu_box
tu_box: ## Runs the unit tests
TU_BOX_DEPS = bin/phpunit fixtures/default_stub.php .requirement-checker fixtures/composer-dump/dir001/vendor
tu_box: $(TU_BOX_DEPS)
$(PHPNOGC) bin/phpunit
.PHONY: tu_box_phar_readonly
tu_box_phar_readonly: ## Runs the unit tests with the setting `phar.readonly` to `On`
tu_box_phar_readonly: $(TU_BOX_DEPS)
php -d zend.enable_gc=0 -d phar.readonly=1 bin/phpunit
.PHONY: tu_requirement_checker
tu_requirement_checker: ## Runs the unit tests
tu_requirement_checker: requirement-checker/bin/phpunit requirement-checker/tests/DisplayNormalizer.php requirement-checker/actual_terminal_diff
cd requirement-checker && $(PHPNOGC) bin/phpunit
diff requirement-checker/expected_terminal_diff requirement-checker/actual_terminal_diff
.PHONY: tc
tc: ## Runs the unit tests with code coverage
tc: bin/phpunit
phpdbg -qrr -d zend.enable_gc=0 bin/phpunit --coverage-html=dist/coverage --coverage-text
.PHONY: tm
tm: ## Runs Infection
tm: $(TU_BOX_DEPS)
$(PHPNOGC) bin/infection --only-covered
.PHONY: e2e
e2e: ## Runs all the end-to-end tests
e2e: e2e_scoper_alias e2e_scoper_whitelist e2e_check_requirements
.PHONY: e2e_scoper_alias
e2e_scoper_alias: ## Runs the end-to-end tests to check that the PHP-Scoper config API regarding the prefix alias is working
e2e_scoper_alias: box
./box compile --working-dir fixtures/build/dir010
.PHONY: e2e_scoper_whitelist
e2e_scoper_whitelist: ## Runs the end-to-end tests to check that the PHP-Scoper config API regarding the whitelisting is working
e2e_scoper_whitelist: box fixtures/build/dir011/vendor
php fixtures/build/dir011/index.php > fixtures/build/dir011/expected-output
./box compile --working-dir fixtures/build/dir011
php fixtures/build/dir011/index.phar > fixtures/build/dir011/output
diff fixtures/build/dir011/expected-output fixtures/build/dir011/output
.PHONY: e2e_check_requirements
DOCKER=docker run -i --rm -w /opt/box
PHP7PHAR=box_php72 php index.phar -vvv --no-ansi
PHP5PHAR=box_php53 php index.phar -vvv --no-ansi
e2e_check_requirements: ## Runs the end-to-end tests for the check requirements feature
#e2e_check_requirements: box
e2e_check_requirements:
./.docker/build
#
# Pass no config
#
bin/box compile --working-dir fixtures/check-requirements/pass-no-config/
# 5.3
sed "s/PHP_VERSION/$$($(DOCKER) box_php53 php -r 'echo PHP_VERSION;')/" \
fixtures/check-requirements/pass-no-config/expected-output-53-dist \
> fixtures/check-requirements/pass-no-config/expected-output-53
rm fixtures/check-requirements/pass-no-config/actual-output || true
$(DOCKER) -v "$$PWD/fixtures/check-requirements/pass-no-config":/opt/box $(PHP5PHAR) > fixtures/check-requirements/pass-no-config/actual-output
diff fixtures/check-requirements/pass-no-config/expected-output-53 fixtures/check-requirements/pass-no-config/actual-output
# 7.2
sed "s/PHP_VERSION/$$($(DOCKER) box_php72 php -r 'echo PHP_VERSION;')/" \
fixtures/check-requirements/pass-no-config/expected-output-72-dist \
> fixtures/check-requirements/pass-no-config/expected-output-72
rm fixtures/check-requirements/pass-no-config/actual-output || true
$(DOCKER) -v "$$PWD/fixtures/check-requirements/pass-no-config":/opt/box $(PHP7PHAR) > fixtures/check-requirements/pass-no-config/actual-output
diff fixtures/check-requirements/pass-no-config/expected-output-72 fixtures/check-requirements/pass-no-config/actual-output
#
# Pass complete
#
bin/box compile --working-dir fixtures/check-requirements/pass-complete/
# 5.3
sed "s/PHP_VERSION/$$($(DOCKER) box_php53 php -r 'echo PHP_VERSION;')/" \
fixtures/check-requirements/pass-complete/expected-output-53-dist \
> fixtures/check-requirements/pass-complete/expected-output-53
rm fixtures/check-requirements/pass-complete/actual-output || true
$(DOCKER) -v "$$PWD/fixtures/check-requirements/pass-complete":/opt/box $(PHP5PHAR) > fixtures/check-requirements/pass-complete/actual-output
diff fixtures/check-requirements/pass-complete/expected-output-53 fixtures/check-requirements/pass-complete/actual-output
# 7.2
sed "s/PHP_VERSION/$$($(DOCKER) box_php72 php -r 'echo PHP_VERSION;')/" \
fixtures/check-requirements/pass-complete/expected-output-72-dist \
> fixtures/check-requirements/pass-complete/expected-output-72
rm fixtures/check-requirements/pass-complete/actual-output || true
$(DOCKER) -v "$$PWD/fixtures/check-requirements/pass-complete":/opt/box $(PHP7PHAR) > fixtures/check-requirements/pass-complete/actual-output
diff fixtures/check-requirements/pass-complete/expected-output-72 fixtures/check-requirements/pass-complete/actual-output
#
# Fail complete
#
bin/box compile --working-dir fixtures/check-requirements/fail-complete/
# 5.3
sed "s/PHP_VERSION/$$($(DOCKER) box_php53 php -r 'echo PHP_VERSION;')/" \
fixtures/check-requirements/fail-complete/expected-output-53-dist \
> fixtures/check-requirements/fail-complete/expected-output-53
rm fixtures/check-requirements/fail-complete/actual-output || true
$(DOCKER) -v "$$PWD/fixtures/check-requirements/fail-complete":/opt/box $(PHP5PHAR) > fixtures/check-requirements/fail-complete/actual-output || true
diff fixtures/check-requirements/fail-complete/expected-output-53 fixtures/check-requirements/fail-complete/actual-output
# 7.2
sed "s/PHP_VERSION/$$($(DOCKER) box_php72 php -r 'echo PHP_VERSION;')/" \
fixtures/check-requirements/fail-complete/expected-output-72-dist \
> fixtures/check-requirements/fail-complete/expected-output-72
rm fixtures/check-requirements/fail-complete/actual-output || true
$(DOCKER) -v "$$PWD/fixtures/check-requirements/fail-complete":/opt/box $(PHP7PHAR) > fixtures/check-requirements/fail-complete/actual-output || true
diff fixtures/check-requirements/fail-complete/expected-output-72 fixtures/check-requirements/fail-complete/actual-output
.PHONY: blackfire
blackfire: ## Profiles the compile step
blackfire: box
# Profile compiling the PHAR from the source code
blackfire --reference=1 --samples=5 run $(PHPNOGC) -d bin/box compile --quiet
# Profile compiling the PHAR from the PHAR
blackfire --reference=2 --samples=5 run $(PHPNOGC) -d box compile --quiet
#
# Rules from files
#---------------------------------------------------------------------------
composer.lock: composer.json
composer install
touch $@
requirement-checker/composer.lock: requirement-checker/composer.json
composer install --working-dir requirement-checker
touch $@
vendor: composer.lock
composer install
vendor/bamarni: composer.lock
composer install
touch $@
bin/phpunit: composer.lock
composer install
touch $@
requirement-checker/bin/phpunit: requirement-checker/composer.lock
composer install --working-dir requirement-checker
touch $@
requirement-checker/vendor: requirement-checker/composer.json
composer install --working-dir requirement-checker
touch $@
$(PHP_CS_FIXER): vendor/bamarni
composer bin php-cs-fixer install
touch $@
$(CODE_SNIFFER): vendor/bamarni
composer bin doctrine-cs install
touch $@
$(CODE_SNIFFER_FIX): vendor/bamarni
composer bin doctrine-cs install
touch $@
fixtures/composer-dump/dir001/composer.lock: fixtures/composer-dump/dir001/composer.json
composer install --working-dir fixtures/composer-dump/dir001
touch $@
fixtures/composer-dump/dir001/vendor: fixtures/composer-dump/dir001/composer.lock
composer install --working-dir fixtures/composer-dump/dir001
touch $@
fixtures/build/dir011/vendor:
composer install --working-dir fixtures/build/dir011
touch $@
.PHONY: fixtures/default_stub.php
fixtures/default_stub.php:
bin/generate_default_stub
requirement-checker/tests/DisplayNormalizer.php: tests/Console/DisplayNormalizer.php
cat tests/Console/DisplayNormalizer.php | sed -E 's/namespace KevinGH\\Box\\Console;/namespace KevinGH\\RequirementChecker;/g' > requirement-checker/tests/DisplayNormalizer.php
.requirement-checker: requirement-checker
$(MAKE) dump-requirement-checker
requirement-checker/actual_terminal_diff: requirement-checker/src/Terminal.php vendor/symfony/console/Terminal.php
diff vendor/symfony/console/Terminal.php requirement-checker/src/Terminal.php > requirement-checker/actual_terminal_diff || true
vendor/symfony/console/Terminal.php: vendor
box: bin src res vendor box.json.dist scoper.inc.php .requirement-checker
# Compile Box
bin/box compile
rm bin/_box.phar || true
mv -v bin/box.phar bin/_box.phar
# Compile Box with the isolated Box PHAR
php bin/_box.phar compile
mv -fv bin/box.phar box
# Test the PHAR which has been created by the isolated PHAR
./box compile
rm bin/_box.phar