]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/source-maintenance.sh
3 # This script contains the code run to perform automatic source maintenance
6 ## Source Code Format Enforcement
8 # A checker to recursively reformat all source files: .h .c .cc .cci
9 # using a custom astyle formatter and to use MD5 to validate that
10 # the formatter has not altered the code syntax.
12 # If code alteration takes place the process is halted for manual intervention.
15 # On squid-cache.org we have to use the python scripted md5sum
17 if test "$HOST" = "squid-cache.org" ; then
25 ASVER
=`astyle --version 2>&1 | grep -o -E "[0-9.]+"`
26 if test "${ASVER}" != "1.23" ; then
27 echo "Astyle version problem. You have ${ASVER} instead of 1.23";
29 echo "Found astyle ${ASVER}. Formatting..."
35 #echo "FORMAT: ${PWD}..."
38 # Scan for incorrect use of #ifdef/#ifndef
40 grep -E "ifn?def .*_SQUID_" .
/* |
grep -v -E "_H$" |
while read f
; do echo "PROBLEM?: ${PWD} ${f}"; done
43 # Scan for file-specific actions
45 for FILENAME
in `ls -1`; do
52 # Code Style formatting maintenance
54 if test "${ASVER}" = "1.23"; then
55 ${ROOT}/scripts
/formater.pl
${FILENAME}
56 if test -e $FILENAME -a -e "$FILENAME.astylebak"; then
57 md51
=`cat $FILENAME| tr -d "\n \t\r" | $MD5`;
58 md52
=`cat $FILENAME.astylebak| tr -d "\n \t\r" | $MD5`;
60 if test "$md51" != "$md52" ; then
61 echo "ERROR: File $PWD/$FILENAME not formating well";
62 mv $FILENAME $FILENAME.astylebad
63 mv $FILENAME.astylebak
$FILENAME
65 rm -f $FILENAME.astylebak
70 ${ROOT}/scripts/sort-includes.pl ${FILENAME} >${FILENAME}.sorted
71 if test -e ${FILENAME} -a -e "${FILENAME}.sorted"; then
72 md51
=`cat ${FILENAME}| tr -d "\n \t\r" | $MD5`;
73 md52
=`cat ${FILENAME}.sorted| tr -d "\n \t\r" | $MD5`;
75 if test "$md51" != "$md52" ; then
76 echo "NOTICE: File $PWD/${FILENAME} changed #include order"
78 mv ${FILENAME}.sorted
${FILENAME}
82 # REQUIRE squid.h first #include
86 FI
=`grep "#include" ${FILENAME} | head -1`;
87 if test "${FI}" != "#include \"squid.h\"" -a "${FILENAME}" != "cf_gen.cc"; then
88 echo "ERROR: ${PWD}/${FILENAME} does not include squid.h first!"
92 FI
=`grep "#include \"squid.h\"" ${FILENAME}`;
93 if test "x${FI}" != "x" ; then
94 echo "ERROR: ${PWD}/${FILENAME} duplicate include of squid.h"
100 # forward.h means different things to Squid code depending on the path
101 # require the full path is explicit for every include
103 FI
=`grep "#include \"forward.h\"" ${FILENAME}`;
104 if test "x${FI}" != "x" ; then
105 echo "ERROR: ${PWD}/${FILENAME} contains reference to forward.h without path"
109 # DEBUG Section list maintenance
111 grep " DEBUG: section" <${FILENAME} |
sed -e 's/ \* DEBUG: //' >>${ROOT}/doc
/debug-sections.tmp
114 # File permissions maintenance.
116 chmod 644 ${FILENAME}
121 # File permissions maintenance.
123 chmod 755 ${FILENAME}
128 perl
-i -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
129 mv ${FILENAME}.styled
${FILENAME}
134 if test "$FILENAME" = "libltdl" ; then
136 elif test -d $FILENAME ; then
138 srcformat
${ROOT} ||
exit 1
145 # Build XPROF types file from current sources
146 echo "#ifndef _PROFILER_XPROF_TYPE_H_" >${ROOT}/lib
/profiler
/list
147 echo "#define _PROFILER_XPROF_TYPE_H_" >>${ROOT}/lib
/profiler
/list
148 echo "/* AUTO-GENERATED FILE */" >>${ROOT}/lib
/profiler
/list
149 echo "#if USE_XPROF_STATS" >>${ROOT}/lib
/profiler
/list
150 echo "typedef enum {" >>${ROOT}/lib
/profiler
/list
151 echo "XPROF_PROF_UNACCOUNTED," >>${ROOT}/lib
/profiler
/list
152 grep -R -h "PROF_start.*" .
/* |
grep -v probename |
sed -e 's/ //g; s/PROF_start(/XPROF_/; s/);/,/' |
sort -u >>${ROOT}/lib
/profiler
/list
153 echo " XPROF_LAST } xprof_type;" >>${ROOT}/lib
/profiler
/list
154 echo "#endif" >>${ROOT}/lib
/profiler
/list
155 echo "#endif" >>${ROOT}/lib
/profiler
/list
156 mv ${ROOT}/lib
/profiler
/list
${ROOT}/lib
/profiler
/xprof_type.h
158 # Build icons install include from current icons available
161 for f
in `ls -1 ${ROOT}/icons/silk/*`
167 )|
sed s
%${ROOT}/icons
/%%g
>${ROOT}/icons
/list
169 # Build templates install include from current templates available
171 echo -n "ERROR_TEMPLATES="
172 for f
in `ls -1 ${ROOT}/errors/templates/ERR_*`
178 )|
sed s
%${ROOT}/errors
/%%g
>${ROOT}/errors
/template.list
180 # Build errors translation install include from current .PO available
182 echo -n "TRANSLATE_LANGUAGES="
183 for f
in `ls -1 ${ROOT}/errors/*.po`
189 )|
sed s
%${ROOT}/errors
/%%g |
sed s
%\.po
%\.lang
%g
>${ROOT}/errors
/language.list
191 # Build manuals translation install include from current .PO available
193 echo -n "TRANSLATE_LANGUAGES="
194 for f
in `ls -1 ${ROOT}/doc/manuals/*.po`
200 )|
sed s
%${ROOT}/doc
/manuals
/%%g |
sed s
%\.po
%\.lang
%g
>${ROOT}/doc
/manuals
/language.list
202 # Build STUB framework include from current stub_* available
204 echo -n "STUB_SOURCE= tests/STUB.h"
205 for f
in `ls -1 ${ROOT}/src/tests/stub_*.cc`
211 )|
sed s
%${ROOT}/src
/%%g
>${ROOT}/src
/tests
/Stub.list
214 echo "" >${ROOT}/doc
/debug-sections.tmp
216 sort -u <${ROOT}/doc
/debug-sections.tmp |
sort -n >${ROOT}/doc
/debug-sections.txt
217 rm ${ROOT}/doc
/debug-sections.tmp