]>
Commit | Line | Data |
---|---|---|
2d97aa77 | 1 | # The personal, minimalist, super-fast, database free, bookmarking service. |
559315ba | 2 | # Makefile for PHP code analysis & testing, documentation and release generation |
f3e89f50 | 3 | |
00f98bda V |
4 | # Prerequisites: |
5 | # - install Composer, either: | |
6 | # - from your distro's package manager; | |
7 | # - from the official website (https://getcomposer.org/download/); | |
8 | # - install/update test dependencies: | |
9 | # $ composer install # 1st setup | |
10 | # $ composer update | |
ca74886f V |
11 | # - install Xdebug for PHPUnit code coverage reports: |
12 | # - see http://xdebug.org/docs/install | |
13 | # - enable in php.ini | |
f3e89f50 | 14 | |
00f98bda | 15 | BIN = vendor/bin |
a52e8435 A |
16 | PHP_SOURCE = index.php application tests plugins |
17 | PHP_COMMA_SOURCE = index.php,application,tests,plugins | |
00f98bda | 18 | |
fc17813b | 19 | all: static_analysis_summary check_permissions test |
00f98bda | 20 | |
d6916040 V |
21 | ## |
22 | # Docker test adapter | |
23 | # | |
24 | # Shaarli sources and vendored libraries are copied from a shared volume | |
25 | # to a user-owned directory to enable running tests as a non-root user. | |
26 | ## | |
27 | docker_%: | |
28 | rsync -az /shaarli/ ~/shaarli/ | |
29 | cd ~/shaarli && make $* | |
30 | ||
00f98bda V |
31 | ## |
32 | # Concise status of the project | |
00f98bda V |
33 | # These targets are non-blocking: || exit 0 |
34 | ## | |
f3e89f50 | 35 | |
00f98bda | 36 | static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary |
ca74886f | 37 | @echo |
00f98bda V |
38 | |
39 | ## | |
40 | # PHP_CodeSniffer | |
00f98bda | 41 | # Detects PHP syntax errors |
00f98bda V |
42 | # Documentation (usage, output formatting): |
43 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.usage.php | |
44 | # - http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php | |
45 | ## | |
f3e89f50 | 46 | |
00f98bda V |
47 | code_sniffer: code_sniffer_full |
48 | ||
3e25f245 V |
49 | ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend... |
50 | PHPCS_%: | |
51 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$* | |
52 | ||
f3e89f50 | 53 | ### - errors by Git author |
00f98bda V |
54 | code_sniffer_blame: |
55 | @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame | |
56 | ||
f3e89f50 | 57 | ### - all errors/warnings |
00f98bda V |
58 | code_sniffer_full: |
59 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 | |
60 | ||
f3e89f50 | 61 | ### - errors grouped by kind |
00f98bda V |
62 | code_sniffer_source: |
63 | @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0 | |
64 | ||
65 | ## | |
66 | # PHP Copy/Paste Detector | |
00f98bda | 67 | # Detects code redundancy |
00f98bda V |
68 | # Documentation: https://github.com/sebastianbergmann/phpcpd |
69 | ## | |
f3e89f50 | 70 | |
00f98bda V |
71 | copy_paste: |
72 | @echo "-----------------------" | |
73 | @echo "PHP COPY/PASTE DETECTOR" | |
74 | @echo "-----------------------" | |
75 | @$(BIN)/phpcpd $(PHP_SOURCE) || exit 0 | |
76 | @echo | |
77 | ||
78 | ## | |
79 | # PHP Mess Detector | |
00f98bda | 80 | # Detects PHP syntax errors, sorted by category |
00f98bda | 81 | # Rules documentation: http://phpmd.org/rules/index.html |
f3e89f50 | 82 | ## |
ca74886f | 83 | MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode |
f3e89f50 | 84 | |
00f98bda V |
85 | mess_title: |
86 | @echo "-----------------" | |
87 | @echo "PHP MESS DETECTOR" | |
88 | @echo "-----------------" | |
89 | ||
f3e89f50 | 90 | ### - all warnings |
00f98bda | 91 | mess_detector: mess_title |
ca74886f | 92 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__' |
00f98bda | 93 | |
f3e89f50 | 94 | ### - all warnings + HTML output contains links to PHPMD's documentation |
00f98bda | 95 | mess_detector_html: |
ca74886f | 96 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \ |
00f98bda V |
97 | --reportfile phpmd.html || exit 0 |
98 | ||
f3e89f50 | 99 | ### - warnings grouped by message, sorted by descending frequency order |
00f98bda V |
100 | mess_detector_grouped: mess_title |
101 | @$(BIN)/phpmd $(PHP_SOURCE) text $(MESS_DETECTOR_RULES) \ | |
102 | | cut -f 2 | sort | uniq -c | sort -nr | |
103 | ||
f3e89f50 | 104 | ### - summary: number of warnings by rule set |
00f98bda V |
105 | mess_detector_summary: mess_title |
106 | @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \ | |
ca74886f | 107 | warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \ |
00f98bda V |
108 | printf "$$warnings\t$$rule\n"; \ |
109 | done; | |
1acc87ee | 110 | |
fc17813b V |
111 | ## |
112 | # Checks source file & script permissions | |
113 | ## | |
114 | check_permissions: | |
115 | @echo "----------------------" | |
116 | @echo "Check file permissions" | |
117 | @echo "----------------------" | |
118 | @for file in `git ls-files`; do \ | |
119 | if [ -x $$file ]; then \ | |
120 | errors=true; \ | |
121 | echo "$${file} is executable"; \ | |
122 | fi \ | |
123 | done; [ -z $$errors ] || false | |
124 | ||
ca74886f V |
125 | ## |
126 | # PHPUnit | |
127 | # Runs unitary and functional tests | |
128 | # Generates an HTML coverage report if Xdebug is enabled | |
129 | # | |
130 | # See phpunit.xml for configuration | |
131 | # https://phpunit.de/manual/current/en/appendixes.configuration.html | |
132 | ## | |
d0ce99e5 | 133 | test: |
ca74886f V |
134 | @echo "-------" |
135 | @echo "PHPUNIT" | |
136 | @echo "-------" | |
6c7d6864 A |
137 | @mkdir -p sandbox coverage |
138 | @$(BIN)/phpunit --coverage-php coverage/main.cov --testsuite unit-tests | |
139 | ||
140 | locale_test_%: | |
141 | @UT_LOCALE=$*.utf8 \ | |
142 | $(BIN)/phpunit \ | |
143 | --coverage-php coverage/$(firstword $(subst _, ,$*)).cov \ | |
144 | --bootstrap tests/languages/bootstrap.php \ | |
145 | --testsuite language-$(firstword $(subst _, ,$*)) | |
146 | ||
147 | all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR | |
148 | @$(BIN)/phpcov merge --html coverage coverage | |
149 | @# --text doesn't work with phpunit 4.* (v5 requires PHP 5.6) | |
150 | @#$(BIN)/phpcov merge --text coverage/txt coverage | |
ca74886f | 151 | |
559315ba V |
152 | ## |
153 | # Custom release archive generation | |
154 | # | |
155 | # For each tagged revision, GitHub provides tar and zip archives that correspond | |
156 | # to the output of git-archive | |
157 | # | |
158 | # These targets produce similar archives, featuring 3rd-party dependencies | |
159 | # to ease deployment on shared hosting. | |
160 | ## | |
161 | ARCHIVE_VERSION := shaarli-$$(git describe)-full | |
ca0ed5ca | 162 | ARCHIVE_PREFIX=Shaarli/ |
559315ba V |
163 | |
164 | release_archive: release_tar release_zip | |
165 | ||
166 | ### download 3rd-party PHP libraries | |
167 | composer_dependencies: clean | |
eaed9ce8 | 168 | composer install --no-dev --prefer-dist |
559315ba V |
169 | find vendor/ -name ".git" -type d -exec rm -rf {} + |
170 | ||
171 | ### generate a release tarball and include 3rd-party dependencies | |
dc37a482 | 172 | release_tar: composer_dependencies htmldoc |
ca0ed5ca V |
173 | git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD |
174 | tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/ | |
29712e90 | 175 | tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/ |
ca0ed5ca | 176 | gzip $(ARCHIVE_VERSION).tar |
559315ba V |
177 | |
178 | ### generate a release zip and include 3rd-party dependencies | |
dc37a482 | 179 | release_zip: composer_dependencies htmldoc |
ca0ed5ca | 180 | git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD |
29712e90 V |
181 | mkdir -p $(ARCHIVE_PREFIX)/{doc,vendor} |
182 | rsync -a doc/html/ $(ARCHIVE_PREFIX)doc/html/ | |
183 | zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)doc/ | |
ca0ed5ca V |
184 | rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/ |
185 | zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/ | |
186 | rm -rf $(ARCHIVE_PREFIX) | |
559315ba | 187 | |
1acc87ee | 188 | ## |
189 | # Targets for repository and documentation maintenance | |
f3e89f50 | 190 | ## |
191 | ||
192 | ### remove all unversioned files | |
1acc87ee | 193 | clean: |
d0ce99e5 | 194 | @git clean -df |
4bf35ba5 | 195 | @rm -rf sandbox |
1acc87ee | 196 | |
3ee5c697 V |
197 | ### generate the AUTHORS file from Git commit information |
198 | authors: | |
199 | @cp .github/mailmap .mailmap | |
200 | @git shortlog -sne > AUTHORS | |
201 | @rm .mailmap | |
202 | ||
05af6f53 V |
203 | ### generate Doxygen documentation |
204 | doxygen: clean | |
205 | @rm -rf doxygen | |
206 | @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen - | |
207 | ||
dc37a482 V |
208 | ### generate HTML documentation from Markdown pages with MkDocs |
209 | htmldoc: | |
53ed6d7d | 210 | python3 -m venv venv/ |
211 | bash -c 'source venv/bin/activate; \ | |
212 | pip install mkdocs; \ | |
213 | mkdocs build' | |
214 | find doc/html/ -type f -exec chmod a-x '{}' \; | |
215 | rm -r venv |