]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/source-maintenance.sh
Merged from trunk 13172.
[thirdparty/squid.git] / scripts / source-maintenance.sh
1 #!/bin/sh
2 #
3 # This script contains the code run to perform automatic source maintenance
4 #
5
6 ## Source Code Format Enforcement
7 #
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.
11 #
12 # If code alteration takes place the process is halted for manual intervention.
13 #
14
15 # On squid-cache.org we have to use the python scripted md5sum
16 HOST=`hostname`
17 if test "$HOST" = "squid-cache.org" ; then
18 MD5="md5"
19 else
20 MD5="md5sum"
21 fi
22
23 ROOT=`bzr root`
24
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";
28 else
29 echo "Found astyle ${ASVER}. Formatting..."
30 fi
31
32 srcformat ()
33 {
34 PWD=`pwd`
35 #echo "FORMAT: ${PWD}..."
36
37 #
38 # Scan for incorrect use of #ifdef/#ifndef
39 #
40 grep -E "ifn?def .*_SQUID_" ./* | grep -v -E "_H$" | while read f; do echo "PROBLEM?: ${PWD} ${f}"; done
41
42 #
43 # Scan for file-specific actions
44 #
45 for FILENAME in `ls -1`; do
46
47 case ${FILENAME} in
48
49 *.h|*.c|*.cc|*.cci)
50
51 #
52 # Code Style formatting maintenance
53 #
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`;
59
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
64 else
65 rm -f $FILENAME.astylebak
66 fi
67 fi
68 fi
69
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`;
74
75 if test "$md51" != "$md52" ; then
76 echo "NOTICE: File $PWD/${FILENAME} changed #include order"
77 fi
78 mv ${FILENAME}.sorted ${FILENAME}
79 fi
80
81 #
82 # REQUIRE squid.h first #include
83 #
84 case ${FILENAME} in
85 *.c|*.cc)
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!"
89 fi
90 ;;
91 *.h|*.cci)
92 FI=`grep "#include \"squid.h\"" ${FILENAME}`;
93 if test "x${FI}" != "x" ; then
94 echo "ERROR: ${PWD}/${FILENAME} duplicate include of squid.h"
95 fi
96 ;;
97 esac
98
99 #
100 # forward.h means different things to Squid code depending on the path
101 # require the full path is explicit for every include
102 #
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"
106 fi
107
108 #
109 # DEBUG Section list maintenance
110 #
111 grep " DEBUG: section" <${FILENAME} | sed -e 's/ \* DEBUG: //' >>${ROOT}/doc/debug-sections.tmp
112
113 #
114 # File permissions maintenance.
115 #
116 chmod 644 ${FILENAME}
117 ;;
118
119 *.pl|*.sh)
120 #
121 # File permissions maintenance.
122 #
123 chmod 755 ${FILENAME}
124 ;;
125
126 Makefile.am)
127
128 perl -i -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
129 mv ${FILENAME}.styled ${FILENAME}
130 ;;
131
132 esac
133
134 if test "$FILENAME" = "libltdl" ; then
135 :
136 elif test -d $FILENAME ; then
137 cd $FILENAME
138 srcformat ${ROOT} || exit 1
139 cd ..
140 fi
141
142 done
143 }
144
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
157
158 # Build icons install include from current icons available
159 (
160 echo -n "ICONS="
161 for f in `ls -1 ${ROOT}/icons/silk/*`
162 do
163 echo " \\"
164 echo -n " ${f}"
165 done
166 echo " "
167 )| sed s%${ROOT}/icons/%%g >${ROOT}/icons/list
168
169 # Build templates install include from current templates available
170 (
171 echo -n "ERROR_TEMPLATES="
172 for f in `ls -1 ${ROOT}/errors/templates/ERR_*`
173 do
174 echo " \\"
175 echo -n " ${f}"
176 done
177 echo " "
178 )| sed s%${ROOT}/errors/%%g >${ROOT}/errors/template.list
179
180 # Build errors translation install include from current .PO available
181 (
182 echo -n "TRANSLATE_LANGUAGES="
183 for f in `ls -1 ${ROOT}/errors/*.po`
184 do
185 echo " \\"
186 echo -n " ${f}"
187 done
188 echo " "
189 )| sed s%${ROOT}/errors/%%g | sed s%\.po%\.lang%g >${ROOT}/errors/language.list
190
191 # Build manuals translation install include from current .PO available
192 (
193 echo -n "TRANSLATE_LANGUAGES="
194 for f in `ls -1 ${ROOT}/doc/manuals/*.po`
195 do
196 echo " \\"
197 echo -n " ${f}"
198 done
199 echo " "
200 )| sed s%${ROOT}/doc/manuals/%%g | sed s%\.po%\.lang%g >${ROOT}/doc/manuals/language.list
201
202 # Build STUB framework include from current stub_* available
203 (
204 echo -n "STUB_SOURCE= tests/STUB.h"
205 for f in `ls -1 ${ROOT}/src/tests/stub_*.cc`
206 do
207 echo " \\"
208 echo -n " ${f}"
209 done
210 echo " "
211 )| sed s%${ROOT}/src/%%g >${ROOT}/src/tests/Stub.list
212
213 # Run formating
214 echo "" >${ROOT}/doc/debug-sections.tmp
215 srcformat || exit 1
216 sort -u <${ROOT}/doc/debug-sections.tmp | sort -n >${ROOT}/doc/debug-sections.txt
217 rm ${ROOT}/doc/debug-sections.tmp