]>
Commit | Line | Data |
---|---|---|
1 | # The personal, minimalist, super-fast, database free, bookmarking service. | |
2 | # Makefile for PHP code analysis & testing, documentation and release generation | |
3 | ||
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 | |
11 | # - install Xdebug for PHPUnit code coverage reports: | |
12 | # - see http://xdebug.org/docs/install | |
13 | # - enable in php.ini | |
14 | ||
15 | BIN = vendor/bin | |
16 | PHP_SOURCE = index.php application tests plugins | |
17 | PHP_COMMA_SOURCE = index.php,application,tests,plugins | |
18 | ||
19 | all: static_analysis_summary check_permissions test | |
20 | ||
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 | ||
31 | ## | |
32 | # Concise status of the project | |
33 | # These targets are non-blocking: || exit 0 | |
34 | ## | |
35 | ||
36 | static_analysis_summary: code_sniffer_source copy_paste mess_detector_summary | |
37 | @echo | |
38 | ||
39 | ## | |
40 | # PHP_CodeSniffer | |
41 | # Detects PHP syntax errors | |
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 | ## | |
46 | ||
47 | code_sniffer: code_sniffer_full | |
48 | ||
49 | ### - errors filtered by coding standard: PEAR, PSR1, PSR2, Zend... | |
50 | PHPCS_%: | |
51 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 --standard=$* | |
52 | ||
53 | ### - errors by Git author | |
54 | code_sniffer_blame: | |
55 | @$(BIN)/phpcs $(PHP_SOURCE) --report-gitblame | |
56 | ||
57 | ### - all errors/warnings | |
58 | code_sniffer_full: | |
59 | @$(BIN)/phpcs $(PHP_SOURCE) --report-full --report-width=200 | |
60 | ||
61 | ### - errors grouped by kind | |
62 | code_sniffer_source: | |
63 | @$(BIN)/phpcs $(PHP_SOURCE) --report-source || exit 0 | |
64 | ||
65 | ## | |
66 | # PHP Copy/Paste Detector | |
67 | # Detects code redundancy | |
68 | # Documentation: https://github.com/sebastianbergmann/phpcpd | |
69 | ## | |
70 | ||
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 | |
80 | # Detects PHP syntax errors, sorted by category | |
81 | # Rules documentation: http://phpmd.org/rules/index.html | |
82 | ## | |
83 | MESS_DETECTOR_RULES = cleancode,codesize,controversial,design,naming,unusedcode | |
84 | ||
85 | mess_title: | |
86 | @echo "-----------------" | |
87 | @echo "PHP MESS DETECTOR" | |
88 | @echo "-----------------" | |
89 | ||
90 | ### - all warnings | |
91 | mess_detector: mess_title | |
92 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) text $(MESS_DETECTOR_RULES) | sed 's_.*\/__' | |
93 | ||
94 | ### - all warnings + HTML output contains links to PHPMD's documentation | |
95 | mess_detector_html: | |
96 | @$(BIN)/phpmd $(PHP_COMMA_SOURCE) html $(MESS_DETECTOR_RULES) \ | |
97 | --reportfile phpmd.html || exit 0 | |
98 | ||
99 | ### - warnings grouped by message, sorted by descending frequency order | |
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 | ||
104 | ### - summary: number of warnings by rule set | |
105 | mess_detector_summary: mess_title | |
106 | @for rule in $$(echo $(MESS_DETECTOR_RULES) | tr ',' ' '); do \ | |
107 | warnings=$$($(BIN)/phpmd $(PHP_COMMA_SOURCE) text $$rule | wc -l); \ | |
108 | printf "$$warnings\t$$rule\n"; \ | |
109 | done; | |
110 | ||
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 | grep -v docker`; do \ | |
119 | if [ -x $$file ]; then \ | |
120 | errors=true; \ | |
121 | echo "$${file} is executable"; \ | |
122 | fi \ | |
123 | done; [ -z $$errors ] || false | |
124 | ||
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 | ## | |
133 | test: translate | |
134 | @echo "-------" | |
135 | @echo "PHPUNIT" | |
136 | @echo "-------" | |
137 | @mkdir -p sandbox coverage | |
138 | @$(BIN)/phpunit --coverage-php coverage/main.cov --bootstrap tests/bootstrap.php --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 | |
151 | ||
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 | |
162 | ARCHIVE_PREFIX=Shaarli/ | |
163 | ||
164 | release_archive: release_tar release_zip | |
165 | ||
166 | ### download 3rd-party PHP libraries | |
167 | composer_dependencies: clean | |
168 | composer install --no-dev --prefer-dist | |
169 | find vendor/ -name ".git" -type d -exec rm -rf {} + | |
170 | ||
171 | ### generate a release tarball and include 3rd-party dependencies and translations | |
172 | release_tar: composer_dependencies htmldoc translate | |
173 | git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).tar HEAD | |
174 | tar rvf $(ARCHIVE_VERSION).tar --transform "s|^vendor|$(ARCHIVE_PREFIX)vendor|" vendor/ | |
175 | tar rvf $(ARCHIVE_VERSION).tar --transform "s|^doc/html|$(ARCHIVE_PREFIX)doc/html|" doc/html/ | |
176 | gzip $(ARCHIVE_VERSION).tar | |
177 | ||
178 | ### generate a release zip and include 3rd-party dependencies and translations | |
179 | release_zip: composer_dependencies htmldoc translate | |
180 | git archive --prefix=$(ARCHIVE_PREFIX) -o $(ARCHIVE_VERSION).zip -9 HEAD | |
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/ | |
184 | rsync -a vendor/ $(ARCHIVE_PREFIX)vendor/ | |
185 | zip -r $(ARCHIVE_VERSION).zip $(ARCHIVE_PREFIX)vendor/ | |
186 | rm -rf $(ARCHIVE_PREFIX) | |
187 | ||
188 | ## | |
189 | # Targets for repository and documentation maintenance | |
190 | ## | |
191 | ||
192 | ### remove all unversioned files | |
193 | clean: | |
194 | @git clean -df | |
195 | @rm -rf sandbox | |
196 | ||
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 | ||
203 | ### generate Doxygen documentation | |
204 | doxygen: clean | |
205 | @rm -rf doxygen | |
206 | @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen - | |
207 | ||
208 | ### generate HTML documentation from Markdown pages with MkDocs | |
209 | htmldoc: | |
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 | |
216 | ||
217 | ||
218 | ### Generate Shaarli's translation compiled file (.mo) | |
219 | translate: | |
220 | @find inc/languages/ -name shaarli.po -execdir msgfmt shaarli.po -o shaarli.mo \; |