3 ## Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
11 # This script contains the code run to perform automatic source maintenance
15 ## Source Code Format Enforcement
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.
21 # If code alteration takes place the process is halted for manual intervention.
24 # On squid-cache.org we have to use the python scripted md5sum
26 if test "$HOST" = "squid-cache.org" ; then
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"
39 echo "Found astyle ${ASVER}. Formatting..."
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
48 #echo "FORMAT: ${PWD}..."
51 # Scan for incorrect use of #ifdef/#ifndef
53 bzr
grep --no-recursive "ifn?def .*_SQUID_" |
55 while read f
; do echo "PROBLEM?: ${PWD} ${f}"; done
58 # Scan for file-specific actions
60 for FILENAME
in `bzr ls --versioned`; do
61 skip_copyright_check
=""
68 # Code Style formatting maintenance
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`;
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}
82 rm -f $FILENAME.astylebak
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`;
92 if test "$md51" != "$md52" ; then
93 echo "NOTICE: File $PWD/${FILENAME} changed #include order"
95 mv ${FILENAME}.sorted
${FILENAME}
99 # REQUIRE squid.h first #include
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!"
109 FI
=`grep "#include \"squid.h\"" ${FILENAME}`;
110 if test "x${FI}" != "x" ; then
111 echo "ERROR: ${PWD}/${FILENAME} duplicate include of squid.h"
117 # forward.h means different things to Squid code depending on the path
118 # require the full path is explicit for every include
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"
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.
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()"
134 SPRINTF
=`grep -e "[^v]sprintf(" ${FILENAME}`;
135 if test "x${SPRINTF}" != "x" ; then
136 echo "ERROR: ${PWD}/${FILENAME} contains unsafe use of sprintf()"
140 # DEBUG Section list maintenance
142 grep " DEBUG: section" <${FILENAME} |
sed -e 's/ \* DEBUG: //' -e 's%/\* DEBUG: %%' -e 's% \*/%%' |
sort -u >>${ROOT}/doc
/debug-sections.tmp
145 # File permissions maintenance.
147 chmod 644 ${FILENAME}
152 # File permissions maintenance.
154 chmod 755 ${FILENAME}
159 perl
-p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
160 mv ${FILENAME}.styled
${FILENAME}
163 ChangeLog|CREDITS|CONTRIBUTORS|COPYING|
*.list|
*.png|
*.po|
*.pot|rfcs
/|
*.txt|test-suite
/squidconf
/empty|.bzrignore
)
164 # we do not enforce copyright blurbs in:
166 # Squid Project contributor attribution file
167 # third-party copyright attribution file
170 # auto-generated .list files,
171 # license documentation files
172 # (imported) plain-text documentation files and ChangeLogs
175 skip_copyright_check
=1
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}
188 echo "CHECK COPYRIGHT for ${PWD}/${FILENAME}"
193 if test "$FILENAME" = "libltdl/" ; then
195 elif test -d $FILENAME ; then
197 srcformat
${ROOT} ||
exit 1
204 # Build XPROF types file from current sources
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;"
217 ) >${ROOT}/lib
/profiler
/list
218 mv ${ROOT}/lib
/profiler
/list
${ROOT}/lib
/profiler
/xprof_type.h
220 # Build icons install include from current icons available
222 sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts
/boilerplate.h
224 for f
in `ls -1 ${ROOT}/icons/silk/* | sort -u`
230 )|
sed s
%${ROOT}/icons
/%%g
>${ROOT}/icons
/icon.list
232 # Build templates install include from current templates available
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`
242 )|
sed s
%${ROOT}/errors
/%%g
>${ROOT}/errors
/template.list
244 # Build errors translation install include from current .PO available
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`
254 )|
sed s
%${ROOT}/errors
/%%g |
sed s
%\.po
%\.lang
%g
>${ROOT}/errors
/language.list
256 # Build manuals translation install include from current .PO available
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`
266 )|
sed s
%${ROOT}/doc
/manuals
/%%g |
sed s
%\.po
%\.lang
%g
>${ROOT}/doc
/manuals
/language.list
268 # Build STUB framework include from current stub_* available
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`
278 )|
sed s
%${ROOT}/src
/%%g
>${ROOT}/src
/tests
/Stub.list
280 # Build the GPERF generated content
281 make -C src
/http gperf-files
284 echo "" >${ROOT}/doc
/debug-sections.tmp
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