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