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