]>
Commit | Line | Data |
---|---|---|
d743fb5d | 1 | #!/bin/sh |
a151895d | 2 | # |
5b74111a | 3 | ## Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
a151895d AJ |
4 | ## |
5 | ## Squid software is distributed under GPLv2+ license and includes | |
6 | ## contributions from numerous individuals and organizations. | |
7 | ## Please see the COPYING and CONTRIBUTORS files for details. | |
8 | ## | |
9 | ||
6f98e675 | 10 | # |
b510f3a1 | 11 | # This script contains the code run to perform automatic source maintenance |
a151895d | 12 | # on Squid |
b510f3a1 AJ |
13 | # |
14 | ||
15 | ## Source Code Format Enforcement | |
16 | # | |
6f98e675 AJ |
17 | # A checker to recursively reformat all source files: .h .c .cc .cci |
18 | # using a custom astyle formatter and to use MD5 to validate that | |
19 | # the formatter has not altered the code syntax. | |
20 | # | |
21 | # If code alteration takes place the process is halted for manual intervention. | |
22 | # | |
23 | ||
6adea170 AJ |
24 | # On squid-cache.org we have to use the python scripted md5sum |
25 | HOST=`hostname` | |
26 | if test "$HOST" = "squid-cache.org" ; then | |
f437b706 | 27 | MD5="md5" |
6adea170 AJ |
28 | else |
29 | MD5="md5sum" | |
30 | fi | |
31 | ||
f77fbf5b | 32 | ASVER=`astyle --version 2>&1 | grep -o -E "[0-9.]+"` |
2ab61c3a SM |
33 | if test "${ASVER}" != "2.04" ; then |
34 | echo "Astyle version problem. You have ${ASVER} instead of 2.04" | |
11097007 | 35 | ASVER="" |
f77fbf5b AJ |
36 | else |
37 | echo "Found astyle ${ASVER}. Formatting..." | |
38 | fi | |
39 | ||
e819858c | 40 | COPYRIGHT_YEARS=`date +"1996-%Y"` |
114c8217 | 41 | echo "s/1996-2[0-9]+ The Squid Software Foundation and contributors/${COPYRIGHT_YEARS} The Squid Software Foundation and contributors/g" >>boilerplate_fix.sed |
e819858c | 42 | |
e555fec8 AJ |
43 | srcformat () |
44 | { | |
605f2c3e AJ |
45 | # |
46 | # Scan for incorrect use of #ifdef/#ifndef | |
47 | # | |
114c8217 | 48 | git grep "ifn?def .*_SQUID_" | |
1a8e2e1c | 49 | grep -v -E "_H$" | |
114c8217 AJ |
50 | grep -v "scripts/source-maintenance.sh" | |
51 | while read f; do echo "PROBLEM?: ${f}"; done | |
605f2c3e AJ |
52 | |
53 | # | |
54 | # Scan for file-specific actions | |
55 | # | |
114c8217 | 56 | for FILENAME in `git ls-files`; do |
e9549c27 | 57 | skip_copyright_check="" |
6f98e675 | 58 | |
114c8217 AJ |
59 | # skip subdirectories, git ls-files is recursive |
60 | test -d $FILENAME && continue | |
61 | ||
d743fb5d AJ |
62 | case ${FILENAME} in |
63 | ||
64 | *.h|*.c|*.cc|*.cci) | |
65 | ||
d090e020 AJ |
66 | # |
67 | # Code Style formatting maintenance | |
68 | # | |
11097007 | 69 | if test "${ASVER}"; then |
114c8217 | 70 | ./scripts/formater.pl ${FILENAME} |
f77fbf5b AJ |
71 | if test -e $FILENAME -a -e "$FILENAME.astylebak"; then |
72 | md51=`cat $FILENAME| tr -d "\n \t\r" | $MD5`; | |
73 | md52=`cat $FILENAME.astylebak| tr -d "\n \t\r" | $MD5`; | |
74 | ||
0278ba4d | 75 | if test "$md51" != "$md52"; then |
114c8217 | 76 | echo "ERROR: File $FILENAME not formating well"; |
f77fbf5b AJ |
77 | mv $FILENAME $FILENAME.astylebad |
78 | mv $FILENAME.astylebak $FILENAME | |
114c8217 | 79 | git checkout -- ${FILENAME} |
f77fbf5b AJ |
80 | else |
81 | rm -f $FILENAME.astylebak | |
82 | fi | |
83 | fi | |
84 | fi | |
d090e020 | 85 | |
114c8217 | 86 | ./scripts/sort-includes.pl ${FILENAME} >${FILENAME}.sorted |
987ca90e AJ |
87 | if test -e ${FILENAME} -a -e "${FILENAME}.sorted"; then |
88 | md51=`cat ${FILENAME}| tr -d "\n \t\r" | $MD5`; | |
89 | md52=`cat ${FILENAME}.sorted| tr -d "\n \t\r" | $MD5`; | |
90 | ||
91 | if test "$md51" != "$md52" ; then | |
114c8217 | 92 | echo "NOTICE: File ${FILENAME} changed #include order" |
987ca90e AJ |
93 | fi |
94 | mv ${FILENAME}.sorted ${FILENAME} | |
95 | fi | |
96 | ||
536e999d | 97 | # |
582c2af2 | 98 | # REQUIRE squid.h first #include |
536e999d AJ |
99 | # |
100 | case ${FILENAME} in | |
114c8217 AJ |
101 | src/cf_gen.cc) |
102 | # ignore, this is a build tool. | |
103 | ;; | |
536e999d AJ |
104 | *.c|*.cc) |
105 | FI=`grep "#include" ${FILENAME} | head -1`; | |
582c2af2 | 106 | if test "${FI}" != "#include \"squid.h\"" -a "${FILENAME}" != "cf_gen.cc"; then |
114c8217 | 107 | echo "ERROR: ${FILENAME} does not include squid.h first!" |
536e999d AJ |
108 | fi |
109 | ;; | |
110 | *.h|*.cci) | |
f7f3304a | 111 | FI=`grep "#include \"squid.h\"" ${FILENAME}`; |
582c2af2 | 112 | if test "x${FI}" != "x" ; then |
114c8217 | 113 | echo "ERROR: ${FILENAME} duplicate include of squid.h" |
536e999d AJ |
114 | fi |
115 | ;; | |
116 | esac | |
117 | ||
eb13c21e AJ |
118 | # |
119 | # forward.h means different things to Squid code depending on the path | |
120 | # require the full path is explicit for every include | |
121 | # | |
122 | FI=`grep "#include \"forward.h\"" ${FILENAME}`; | |
123 | if test "x${FI}" != "x" ; then | |
114c8217 | 124 | echo "ERROR: ${FILENAME} contains reference to forward.h without path" |
eb13c21e AJ |
125 | fi |
126 | ||
b8889258 AJ |
127 | # |
128 | # detect functions unsafe for use within Squid. | |
86c63190 AJ |
129 | # strdup() - only allowed in compat/xstring.h which defines a safe replacement. |
130 | # sprintf() - not allowed anywhere. | |
b8889258 | 131 | # |
86c63190 AJ |
132 | STRDUP=`grep -e "[^x]strdup(" ${FILENAME}`; |
133 | if test "x${STRDUP}" != "x" -a "${FILENAME}" != "xstring.h"; then | |
114c8217 | 134 | echo "ERROR: ${FILENAME} contains unprotected use of strdup()" |
b8889258 | 135 | fi |
86c63190 | 136 | SPRINTF=`grep -e "[^v]sprintf(" ${FILENAME}`; |
b8889258 | 137 | if test "x${SPRINTF}" != "x" ; then |
114c8217 | 138 | echo "ERROR: ${FILENAME} contains unsafe use of sprintf()" |
b8889258 AJ |
139 | fi |
140 | ||
d090e020 AJ |
141 | # |
142 | # DEBUG Section list maintenance | |
143 | # | |
114c8217 | 144 | grep " DEBUG: section" <${FILENAME} | sed -e 's/ \* DEBUG: //' -e 's%/\* DEBUG: %%' -e 's% \*/%%' | sort -u >>doc/debug-sections.tmp |
d090e020 AJ |
145 | |
146 | # | |
147 | # File permissions maintenance. | |
148 | # | |
149 | chmod 644 ${FILENAME} | |
150 | ;; | |
151 | ||
152 | *.pl|*.sh) | |
153 | # | |
154 | # File permissions maintenance. | |
155 | # | |
156 | chmod 755 ${FILENAME} | |
8cd09bae HN |
157 | ;; |
158 | ||
159 | Makefile.am) | |
160 | ||
ddf5d6db | 161 | perl -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled |
8cd09bae HN |
162 | mv ${FILENAME}.styled ${FILENAME} |
163 | ;; | |
164 | ||
e758499d | 165 | ChangeLog|CREDITS|CONTRIBUTORS|COPYING|*.list|*.png|*.po|*.pot|rfcs/|*.txt|test-suite/squidconf/empty|.bzrignore) |
e9549c27 AJ |
166 | # we do not enforce copyright blurbs in: |
167 | # | |
e758499d AJ |
168 | # Squid Project contributor attribution file |
169 | # third-party copyright attribution file | |
e9549c27 AJ |
170 | # images, |
171 | # translation PO/POT | |
172 | # auto-generated .list files, | |
e758499d | 173 | # license documentation files |
e9549c27 | 174 | # (imported) plain-text documentation files and ChangeLogs |
e758499d | 175 | # VCS internal files |
e9549c27 AJ |
176 | # |
177 | skip_copyright_check=1 | |
178 | ;; | |
d743fb5d | 179 | esac |
6f98e675 | 180 | |
5fbc3e1d | 181 | # check for Foundation copyright blurb |
114c8217 | 182 | if test -f ${FILENAME} -a "x$skip_copyright_check" = "x"; then |
e819858c | 183 | BLURB=`grep -o "${COPYRIGHT_YEARS} The Squid Software Foundation and contributors" ${FILENAME}`; |
5fbc3e1d | 184 | if test "x${BLURB}" = "x"; then |
e819858c SM |
185 | BOILER=`grep -o -E "1996-2[0-9]+ The Squid Software Foundation and contributors" ${FILENAME}`; |
186 | if test "x${BOILER}" != "x"; then | |
114c8217 AJ |
187 | echo "UPDATE COPYRIGHT for ${FILENAME}" |
188 | sed --in-place -r -f boilerplate_fix.sed ${FILENAME} | |
e819858c | 189 | else |
114c8217 | 190 | echo "CHECK COPYRIGHT for ${FILENAME}" |
e819858c | 191 | fi |
5fbc3e1d AJ |
192 | fi |
193 | fi | |
194 | ||
6f98e675 | 195 | done |
e555fec8 AJ |
196 | } |
197 | ||
598c5a44 | 198 | # Build XPROF types file from current sources |
e9549c27 AJ |
199 | ( |
200 | cat scripts/boilerplate.h | |
201 | echo "#ifndef _PROFILER_XPROF_TYPE_H_" | |
202 | echo "#define _PROFILER_XPROF_TYPE_H_" | |
203 | echo "/* AUTO-GENERATED FILE */" | |
204 | echo "#if USE_XPROF_STATS" | |
205 | echo "typedef enum {" | |
206 | echo " XPROF_PROF_UNACCOUNTED," | |
207 | grep -R -h "PROF_start.*" ./* | grep -v probename | sed -e 's/ //g; s/PROF_start(/XPROF_/; s/);/,/' | sort -u | |
208 | echo " XPROF_LAST } xprof_type;" | |
209 | echo "#endif" | |
210 | echo "#endif" | |
114c8217 AJ |
211 | ) >lib/profiler/list |
212 | mv lib/profiler/list lib/profiler/xprof_type.h | |
598c5a44 | 213 | |
46002cc1 | 214 | # Build icons install include from current icons available |
54966be3 | 215 | ( |
e9549c27 | 216 | sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h |
54966be3 | 217 | echo -n "ICONS=" |
114c8217 | 218 | for f in `ls -1 icons/silk/* | sort -u` |
d78c092d | 219 | do |
54966be3 AJ |
220 | echo " \\" |
221 | echo -n " ${f}" | |
d78c092d | 222 | done |
54966be3 | 223 | echo " " |
114c8217 | 224 | )| sed s%icons/%%g >icons/icon.list |
d78c092d | 225 | |
46002cc1 AJ |
226 | # Build templates install include from current templates available |
227 | ( | |
e9549c27 | 228 | sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h |
46002cc1 | 229 | echo -n "ERROR_TEMPLATES=" |
114c8217 | 230 | for f in `ls -1 errors/templates/ERR_* | sort -u` |
46002cc1 AJ |
231 | do |
232 | echo " \\" | |
233 | echo -n " ${f}" | |
234 | done | |
235 | echo " " | |
114c8217 | 236 | )| sed s%errors/%%g >errors/template.list |
46002cc1 AJ |
237 | |
238 | # Build errors translation install include from current .PO available | |
239 | ( | |
e9549c27 | 240 | sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h |
46002cc1 | 241 | echo -n "TRANSLATE_LANGUAGES=" |
114c8217 | 242 | for f in `ls -1 errors/*.po | sort -u` |
46002cc1 AJ |
243 | do |
244 | echo " \\" | |
245 | echo -n " ${f}" | |
246 | done | |
247 | echo " " | |
114c8217 | 248 | )| sed s%errors/%%g | sed s%\.po%\.lang%g >errors/language.list |
46002cc1 AJ |
249 | |
250 | # Build manuals translation install include from current .PO available | |
251 | ( | |
e9549c27 | 252 | sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h |
46002cc1 | 253 | echo -n "TRANSLATE_LANGUAGES=" |
114c8217 | 254 | for f in `ls -1 doc/manuals/*.po | sort -u` |
46002cc1 AJ |
255 | do |
256 | echo " \\" | |
257 | echo -n " ${f}" | |
258 | done | |
259 | echo " " | |
114c8217 | 260 | )| sed s%doc/manuals/%%g | sed s%\.po%\.lang%g >doc/manuals/language.list |
46002cc1 | 261 | |
ee4478ed AJ |
262 | # Build STUB framework include from current stub_* available |
263 | ( | |
e9549c27 | 264 | sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h |
1c7a7cd5 | 265 | echo -n "STUB_SOURCE= tests/STUB.h" |
114c8217 | 266 | for f in `ls -1 src/tests/stub_*.cc | sort -u` |
ee4478ed AJ |
267 | do |
268 | echo " \\" | |
269 | echo -n " ${f}" | |
270 | done | |
271 | echo " " | |
114c8217 | 272 | )| sed s%src/%%g >src/tests/Stub.list |
ee4478ed | 273 | |
3d50beac FC |
274 | # Build the GPERF generated content |
275 | make -C src/http gperf-files | |
276 | ||
598c5a44 | 277 | # Run formating |
114c8217 | 278 | echo "" >doc/debug-sections.tmp |
e555fec8 | 279 | srcformat || exit 1 |
114c8217 AJ |
280 | sort -u <doc/debug-sections.tmp | sort -n >doc/debug-sections.tmp2 |
281 | cat scripts/boilerplate.h doc/debug-sections.tmp2 >doc/debug-sections.txt | |
282 | rm doc/debug-sections.tmp doc/debug-sections.tmp2 | |
283 | rm boilerplate_fix.sed |