]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/source-maintenance.sh
3 ## Copyright (C) 1996-2014 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}" != "1.23" ; then
36 echo "Astyle version problem. You have ${ASVER} instead of 1.23";
38 echo "Found astyle ${ASVER}. Formatting..."
44 #echo "FORMAT: ${PWD}..."
47 # Scan for incorrect use of #ifdef/#ifndef
49 grep -E "ifn?def .*_SQUID_" .
/*.
* |
grep -v -E "_H$" |
while read f
; do echo "PROBLEM?: ${PWD} ${f}"; done
52 # Scan for file-specific actions
54 for FILENAME
in `ls -1`; do
61 # Code Style formatting maintenance
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`;
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
74 rm -f $FILENAME.astylebak
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`;
84 if test "$md51" != "$md52" ; then
85 echo "NOTICE: File $PWD/${FILENAME} changed #include order"
87 mv ${FILENAME}.sorted
${FILENAME}
91 # REQUIRE squid.h first #include
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!"
101 FI
=`grep "#include \"squid.h\"" ${FILENAME}`;
102 if test "x${FI}" != "x" ; then
103 echo "ERROR: ${PWD}/${FILENAME} duplicate include of squid.h"
109 # forward.h means different things to Squid code depending on the path
110 # require the full path is explicit for every include
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"
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.
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()"
126 SPRINTF
=`grep -e "[^v]sprintf(" ${FILENAME}`;
127 if test "x${SPRINTF}" != "x" ; then
128 echo "ERROR: ${PWD}/${FILENAME} contains unsafe use of sprintf()"
132 # DEBUG Section list maintenance
134 grep " DEBUG: section" <${FILENAME} |
sed -e 's/ \* DEBUG: //' -e 's%/\* DEBUG: %%' -e 's% \*/%%' |
sort -u >>${ROOT}/doc
/debug-sections.tmp
137 # File permissions maintenance.
139 chmod 644 ${FILENAME}
144 # File permissions maintenance.
146 chmod 755 ${FILENAME}
151 perl
-p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
152 mv ${FILENAME}.styled
${FILENAME}
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}"
165 if test "$FILENAME" = "libltdl" ; then
167 elif test -d $FILENAME ; then
169 srcformat
${ROOT} ||
exit 1
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
189 # Build icons install include from current icons available
192 for f
in `ls -1 ${ROOT}/icons/silk/* | sort -u`
198 )|
sed s
%${ROOT}/icons
/%%g
>${ROOT}/icons
/list
200 # Build templates install include from current templates available
202 echo -n "ERROR_TEMPLATES="
203 for f
in `ls -1 ${ROOT}/errors/templates/ERR_* | sort -u`
209 )|
sed s
%${ROOT}/errors
/%%g
>${ROOT}/errors
/template.list
211 # Build errors translation install include from current .PO available
213 echo -n "TRANSLATE_LANGUAGES="
214 for f
in `ls -1 ${ROOT}/errors/*.po | sort -u`
220 )|
sed s
%${ROOT}/errors
/%%g |
sed s
%\.po
%\.lang
%g
>${ROOT}/errors
/language.list
222 # Build manuals translation install include from current .PO available
224 echo -n "TRANSLATE_LANGUAGES="
225 for f
in `ls -1 ${ROOT}/doc/manuals/*.po | sort -u`
231 )|
sed s
%${ROOT}/doc
/manuals
/%%g |
sed s
%\.po
%\.lang
%g
>${ROOT}/doc
/manuals
/language.list
233 # Build STUB framework include from current stub_* available
235 echo -n "STUB_SOURCE= tests/STUB.h"
236 for f
in `ls -1 ${ROOT}/src/tests/stub_*.cc | sort -u`
242 )|
sed s
%${ROOT}/src
/%%g
>${ROOT}/src
/tests
/Stub.list
245 echo "" >${ROOT}/doc
/debug-sections.tmp
247 sort -u <${ROOT}/doc
/debug-sections.tmp |
sort -n >${ROOT}/doc
/debug-sections.txt
248 rm ${ROOT}/doc
/debug-sections.tmp