]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/source-maintenance.sh
Merged changes since Apr 2013 review
[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 #
71 # REQUIRE squid.h first #include
72 #
73 case ${FILENAME} in
74 *.c|*.cc)
75 FI=`grep "#include" ${FILENAME} | head -1`;
76 if test "${FI}" != "#include \"squid.h\"" -a "${FILENAME}" != "cf_gen.cc"; then
77 echo "ERROR: ${PWD}/${FILENAME} does not include squid.h first!"
78 fi
79 ;;
80 *.h|*.cci)
81 FI=`grep "#include \"squid.h\"" ${FILENAME}`;
82 if test "x${FI}" != "x" ; then
83 echo "ERROR: ${PWD}/${FILENAME} duplicate include of squid.h"
84 fi
85 ;;
86 esac
87
88 #
89 # forward.h means different things to Squid code depending on the path
90 # require the full path is explicit for every include
91 #
92 FI=`grep "#include \"forward.h\"" ${FILENAME}`;
93 if test "x${FI}" != "x" ; then
94 echo "ERROR: ${PWD}/${FILENAME} contains reference to forward.h without path"
95 fi
96
97 #
98 # DEBUG Section list maintenance
99 #
100 grep " DEBUG: section" <${FILENAME} | sed -e 's/ \* DEBUG: //' >>${ROOT}/doc/debug-sections.tmp
101
102 #
103 # File permissions maintenance.
104 #
105 chmod 644 ${FILENAME}
106 ;;
107
108 *.pl|*.sh)
109 #
110 # File permissions maintenance.
111 #
112 chmod 755 ${FILENAME}
113 ;;
114
115 Makefile.am)
116
117 perl -i -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
118 mv ${FILENAME}.styled ${FILENAME}
119 ;;
120
121 esac
122
123 if test "$FILENAME" = "libltdl" -o "$FILENAME" = "libTrie" ; then
124 :
125 elif test -d $FILENAME ; then
126 cd $FILENAME
127 srcformat ${ROOT} || exit 1
128 cd ..
129 fi
130
131 done
132 }
133
134 # Build XPROF types file from current sources
135 echo "#ifndef _PROFILER_XPROF_TYPE_H_" >${ROOT}/lib/profiler/list
136 echo "#define _PROFILER_XPROF_TYPE_H_" >>${ROOT}/lib/profiler/list
137 echo "/* AUTO-GENERATED FILE */" >>${ROOT}/lib/profiler/list
138 echo "#if USE_XPROF_STATS" >>${ROOT}/lib/profiler/list
139 echo "typedef enum {" >>${ROOT}/lib/profiler/list
140 echo "XPROF_PROF_UNACCOUNTED," >>${ROOT}/lib/profiler/list
141 grep -R -h "PROF_start.*" ./* | grep -v probename | sed -e 's/ //g; s/PROF_start(/XPROF_/; s/);/,/' | sort -u >>${ROOT}/lib/profiler/list
142 echo " XPROF_LAST } xprof_type;" >>${ROOT}/lib/profiler/list
143 echo "#endif" >>${ROOT}/lib/profiler/list
144 echo "#endif" >>${ROOT}/lib/profiler/list
145 mv ${ROOT}/lib/profiler/list ${ROOT}/lib/profiler/xprof_type.h
146
147 # Build icons install include from current icons available
148 (
149 echo -n "ICONS="
150 for f in `ls -1 ${ROOT}/icons/silk/*`
151 do
152 echo " \\"
153 echo -n " ${f}"
154 done
155 echo " "
156 )| sed s%${ROOT}/icons/%%g >${ROOT}/icons/list
157
158 # Build templates install include from current templates available
159 (
160 echo -n "ERROR_TEMPLATES="
161 for f in `ls -1 ${ROOT}/errors/templates/ERR_*`
162 do
163 echo " \\"
164 echo -n " ${f}"
165 done
166 echo " "
167 )| sed s%${ROOT}/errors/%%g >${ROOT}/errors/template.list
168
169 # Build errors translation install include from current .PO available
170 (
171 echo -n "TRANSLATE_LANGUAGES="
172 for f in `ls -1 ${ROOT}/errors/*.po`
173 do
174 echo " \\"
175 echo -n " ${f}"
176 done
177 echo " "
178 )| sed s%${ROOT}/errors/%%g | sed s%\.po%\.lang%g >${ROOT}/errors/language.list
179
180 # Build manuals translation install include from current .PO available
181 (
182 echo -n "TRANSLATE_LANGUAGES="
183 for f in `ls -1 ${ROOT}/doc/manuals/*.po`
184 do
185 echo " \\"
186 echo -n " ${f}"
187 done
188 echo " "
189 )| sed s%${ROOT}/doc/manuals/%%g | sed s%\.po%\.lang%g >${ROOT}/doc/manuals/language.list
190
191 # Build STUB framework include from current stub_* available
192 (
193 echo -n "STUB_SOURCE= tests/STUB.h"
194 for f in `ls -1 ${ROOT}/src/tests/stub_*.cc`
195 do
196 echo " \\"
197 echo -n " ${f}"
198 done
199 echo " "
200 )| sed s%${ROOT}/src/%%g >${ROOT}/src/tests/Stub.list
201
202 # Run formating
203 echo "" >${ROOT}/doc/debug-sections.tmp
204 srcformat || exit 1
205 sort -u <${ROOT}/doc/debug-sections.tmp | sort -n >${ROOT}/doc/debug-sections.txt
206 rm ${ROOT}/doc/debug-sections.tmp