]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/source-maintenance.sh
Source Maintenance: fix various maintenance script issues
[thirdparty/squid.git] / scripts / source-maintenance.sh
1 #!/bin/sh
2 #
3 ## Copyright (C) 1996-2014 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}" != "1.23" ; then
36 echo "Astyle version problem. You have ${ASVER} instead of 1.23";
37 else
38 echo "Found astyle ${ASVER}. Formatting..."
39 fi
40
41 srcformat ()
42 {
43 PWD=`pwd`
44 #echo "FORMAT: ${PWD}..."
45
46 #
47 # Scan for incorrect use of #ifdef/#ifndef
48 #
49 grep -E "ifn?def .*_SQUID_" ./*.* | grep -v -E "_H$" | while read f; do echo "PROBLEM?: ${PWD} ${f}"; done
50
51 #
52 # Scan for file-specific actions
53 #
54 for FILENAME in `ls -1`; do
55
56 case ${FILENAME} in
57
58 *.h|*.c|*.cc|*.cci)
59
60 #
61 # Code Style formatting maintenance
62 #
63 if test "${ASVER}" = "1.23"; then
64 ${ROOT}/scripts/formater.pl ${FILENAME}
65 if test -e $FILENAME -a -e "$FILENAME.astylebak"; then
66 md51=`cat $FILENAME| tr -d "\n \t\r" | $MD5`;
67 md52=`cat $FILENAME.astylebak| tr -d "\n \t\r" | $MD5`;
68
69 if test "$md51" != "$md52" ; then
70 echo "ERROR: File $PWD/$FILENAME not formating well";
71 mv $FILENAME $FILENAME.astylebad
72 mv $FILENAME.astylebak $FILENAME
73 else
74 rm -f $FILENAME.astylebak
75 fi
76 fi
77 fi
78
79 ${ROOT}/scripts/sort-includes.pl ${FILENAME} >${FILENAME}.sorted
80 if test -e ${FILENAME} -a -e "${FILENAME}.sorted"; then
81 md51=`cat ${FILENAME}| tr -d "\n \t\r" | $MD5`;
82 md52=`cat ${FILENAME}.sorted| tr -d "\n \t\r" | $MD5`;
83
84 if test "$md51" != "$md52" ; then
85 echo "NOTICE: File $PWD/${FILENAME} changed #include order"
86 fi
87 mv ${FILENAME}.sorted ${FILENAME}
88 fi
89
90 #
91 # REQUIRE squid.h first #include
92 #
93 case ${FILENAME} in
94 *.c|*.cc)
95 FI=`grep "#include" ${FILENAME} | head -1`;
96 if test "${FI}" != "#include \"squid.h\"" -a "${FILENAME}" != "cf_gen.cc"; then
97 echo "ERROR: ${PWD}/${FILENAME} does not include squid.h first!"
98 fi
99 ;;
100 *.h|*.cci)
101 FI=`grep "#include \"squid.h\"" ${FILENAME}`;
102 if test "x${FI}" != "x" ; then
103 echo "ERROR: ${PWD}/${FILENAME} duplicate include of squid.h"
104 fi
105 ;;
106 esac
107
108 #
109 # forward.h means different things to Squid code depending on the path
110 # require the full path is explicit for every include
111 #
112 FI=`grep "#include \"forward.h\"" ${FILENAME}`;
113 if test "x${FI}" != "x" ; then
114 echo "ERROR: ${PWD}/${FILENAME} contains reference to forward.h without path"
115 fi
116
117 #
118 # detect functions unsafe for use within Squid.
119 # strdup() - only allowed in compat/xstring.h which defines a safe replacement.
120 # sprintf() - not allowed anywhere.
121 #
122 STRDUP=`grep -e "[^x]strdup(" ${FILENAME}`;
123 if test "x${STRDUP}" != "x" -a "${FILENAME}" != "xstring.h"; then
124 echo "ERROR: ${PWD}/${FILENAME} contains unprotected use of strdup()"
125 fi
126 SPRINTF=`grep -e "[^v]sprintf(" ${FILENAME}`;
127 if test "x${SPRINTF}" != "x" ; then
128 echo "ERROR: ${PWD}/${FILENAME} contains unsafe use of sprintf()"
129 fi
130
131 #
132 # DEBUG Section list maintenance
133 #
134 grep " DEBUG: section" <${FILENAME} | sed -e 's/ \* DEBUG: //' -e 's%/\* DEBUG: %%' -e 's% \*/%%' | sort -u >>${ROOT}/doc/debug-sections.tmp
135
136 #
137 # File permissions maintenance.
138 #
139 chmod 644 ${FILENAME}
140 ;;
141
142 *.pl|*.sh)
143 #
144 # File permissions maintenance.
145 #
146 chmod 755 ${FILENAME}
147 ;;
148
149 Makefile.am)
150
151 perl -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
152 mv ${FILENAME}.styled ${FILENAME}
153 ;;
154
155 esac
156
157 # check for Foundation copyright blurb
158 if test -f ${PWD}/${FILENAME}; then
159 BLURB=`grep "The Squid Software Foundation and contributors" ${FILENAME}`;
160 if test "x${BLURB}" = "x"; then
161 echo "CHECK COPYRIGHT for ${PWD}/${FILENAME}"
162 fi
163 fi
164
165 if test "$FILENAME" = "libltdl" ; then
166 :
167 elif test -d $FILENAME ; then
168 cd $FILENAME
169 srcformat ${ROOT} || exit 1
170 cd ..
171 fi
172
173 done
174 }
175
176 # Build XPROF types file from current sources
177 echo "#ifndef _PROFILER_XPROF_TYPE_H_" >${ROOT}/lib/profiler/list
178 echo "#define _PROFILER_XPROF_TYPE_H_" >>${ROOT}/lib/profiler/list
179 echo "/* AUTO-GENERATED FILE */" >>${ROOT}/lib/profiler/list
180 echo "#if USE_XPROF_STATS" >>${ROOT}/lib/profiler/list
181 echo "typedef enum {" >>${ROOT}/lib/profiler/list
182 echo "XPROF_PROF_UNACCOUNTED," >>${ROOT}/lib/profiler/list
183 grep -R -h "PROF_start.*" ./* | grep -v probename | sed -e 's/ //g; s/PROF_start(/XPROF_/; s/);/,/' | sort -u >>${ROOT}/lib/profiler/list
184 echo " XPROF_LAST } xprof_type;" >>${ROOT}/lib/profiler/list
185 echo "#endif" >>${ROOT}/lib/profiler/list
186 echo "#endif" >>${ROOT}/lib/profiler/list
187 mv ${ROOT}/lib/profiler/list ${ROOT}/lib/profiler/xprof_type.h
188
189 # Build icons install include from current icons available
190 (
191 echo -n "ICONS="
192 for f in `ls -1 ${ROOT}/icons/silk/* | sort -u`
193 do
194 echo " \\"
195 echo -n " ${f}"
196 done
197 echo " "
198 )| sed s%${ROOT}/icons/%%g >${ROOT}/icons/list
199
200 # Build templates install include from current templates available
201 (
202 echo -n "ERROR_TEMPLATES="
203 for f in `ls -1 ${ROOT}/errors/templates/ERR_* | sort -u`
204 do
205 echo " \\"
206 echo -n " ${f}"
207 done
208 echo " "
209 )| sed s%${ROOT}/errors/%%g >${ROOT}/errors/template.list
210
211 # Build errors translation install include from current .PO available
212 (
213 echo -n "TRANSLATE_LANGUAGES="
214 for f in `ls -1 ${ROOT}/errors/*.po | sort -u`
215 do
216 echo " \\"
217 echo -n " ${f}"
218 done
219 echo " "
220 )| sed s%${ROOT}/errors/%%g | sed s%\.po%\.lang%g >${ROOT}/errors/language.list
221
222 # Build manuals translation install include from current .PO available
223 (
224 echo -n "TRANSLATE_LANGUAGES="
225 for f in `ls -1 ${ROOT}/doc/manuals/*.po | sort -u`
226 do
227 echo " \\"
228 echo -n " ${f}"
229 done
230 echo " "
231 )| sed s%${ROOT}/doc/manuals/%%g | sed s%\.po%\.lang%g >${ROOT}/doc/manuals/language.list
232
233 # Build STUB framework include from current stub_* available
234 (
235 echo -n "STUB_SOURCE= tests/STUB.h"
236 for f in `ls -1 ${ROOT}/src/tests/stub_*.cc | sort -u`
237 do
238 echo " \\"
239 echo -n " ${f}"
240 done
241 echo " "
242 )| sed s%${ROOT}/src/%%g >${ROOT}/src/tests/Stub.list
243
244 # Run formating
245 echo "" >${ROOT}/doc/debug-sections.tmp
246 srcformat || exit 1
247 sort -u <${ROOT}/doc/debug-sections.tmp | sort -n >${ROOT}/doc/debug-sections.txt
248 rm ${ROOT}/doc/debug-sections.tmp