]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/source-maintenance.sh
SourceFormat Enforcement
[thirdparty/squid.git] / scripts / source-maintenance.sh
CommitLineData
d743fb5d 1#!/bin/sh
a151895d 2#
4ac4a490 3## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
a151895d
AJ
4##
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.
8##
9
6f98e675 10#
b510f3a1 11# This script contains the code run to perform automatic source maintenance
a151895d 12# on Squid
b510f3a1
AJ
13#
14
15## Source Code Format Enforcement
16#
6f98e675
AJ
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.
20#
21# If code alteration takes place the process is halted for manual intervention.
22#
23
6adea170
AJ
24# On squid-cache.org we have to use the python scripted md5sum
25HOST=`hostname`
26if test "$HOST" = "squid-cache.org" ; then
f437b706 27 MD5="md5"
6adea170
AJ
28else
29 MD5="md5sum"
30fi
31
d743fb5d 32ROOT=`bzr root`
e555fec8 33
f77fbf5b 34ASVER=`astyle --version 2>&1 | grep -o -E "[0-9.]+"`
2ab61c3a
SM
35if test "${ASVER}" != "2.04" ; then
36 echo "Astyle version problem. You have ${ASVER} instead of 2.04"
11097007 37 ASVER=""
f77fbf5b
AJ
38else
39 echo "Found astyle ${ASVER}. Formatting..."
40fi
41
e819858c
SM
42COPYRIGHT_YEARS=`date +"1996-%Y"`
43echo "s/1996-2[0-9]+ The Squid Software Foundation and contributors/${COPYRIGHT_YEARS} The Squid Software Foundation and contributors/g" >>${ROOT}/boilerplate_fix.sed
44
e555fec8
AJ
45srcformat ()
46{
6f98e675 47PWD=`pwd`
536e999d 48#echo "FORMAT: ${PWD}..."
e555fec8 49
605f2c3e
AJ
50#
51# Scan for incorrect use of #ifdef/#ifndef
52#
1a8e2e1c
AR
53bzr grep --no-recursive "ifn?def .*_SQUID_" |
54 grep -v -E "_H$" |
55 while read f; do echo "PROBLEM?: ${PWD} ${f}"; done
605f2c3e
AJ
56
57#
58# Scan for file-specific actions
59#
1a8e2e1c 60for FILENAME in `bzr ls --versioned`; do
e9549c27 61 skip_copyright_check=""
6f98e675 62
d743fb5d
AJ
63 case ${FILENAME} in
64
65 *.h|*.c|*.cc|*.cci)
66
d090e020
AJ
67 #
68 # Code Style formatting maintenance
69 #
11097007 70 if test "${ASVER}"; then
f77fbf5b
AJ
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`;
75
0278ba4d 76 if test "$md51" != "$md52"; then
f77fbf5b
AJ
77 echo "ERROR: File $PWD/$FILENAME not formating well";
78 mv $FILENAME $FILENAME.astylebad
79 mv $FILENAME.astylebak $FILENAME
0278ba4d 80 bzr revert ${FILENAME}
f77fbf5b
AJ
81 else
82 rm -f $FILENAME.astylebak
83 fi
84 fi
85 fi
d090e020 86
987ca90e
AJ
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`;
91
92 if test "$md51" != "$md52" ; then
93 echo "NOTICE: File $PWD/${FILENAME} changed #include order"
94 fi
95 mv ${FILENAME}.sorted ${FILENAME}
96 fi
97
536e999d 98 #
582c2af2 99 # REQUIRE squid.h first #include
536e999d
AJ
100 #
101 case ${FILENAME} in
102 *.c|*.cc)
103 FI=`grep "#include" ${FILENAME} | head -1`;
582c2af2
FC
104 if test "${FI}" != "#include \"squid.h\"" -a "${FILENAME}" != "cf_gen.cc"; then
105 echo "ERROR: ${PWD}/${FILENAME} does not include squid.h first!"
536e999d
AJ
106 fi
107 ;;
108 *.h|*.cci)
f7f3304a 109 FI=`grep "#include \"squid.h\"" ${FILENAME}`;
582c2af2 110 if test "x${FI}" != "x" ; then
f7f3304a 111 echo "ERROR: ${PWD}/${FILENAME} duplicate include of squid.h"
536e999d
AJ
112 fi
113 ;;
114 esac
115
eb13c21e
AJ
116 #
117 # forward.h means different things to Squid code depending on the path
118 # require the full path is explicit for every include
119 #
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"
123 fi
124
b8889258
AJ
125 #
126 # detect functions unsafe for use within Squid.
86c63190
AJ
127 # strdup() - only allowed in compat/xstring.h which defines a safe replacement.
128 # sprintf() - not allowed anywhere.
b8889258 129 #
86c63190
AJ
130 STRDUP=`grep -e "[^x]strdup(" ${FILENAME}`;
131 if test "x${STRDUP}" != "x" -a "${FILENAME}" != "xstring.h"; then
b8889258
AJ
132 echo "ERROR: ${PWD}/${FILENAME} contains unprotected use of strdup()"
133 fi
86c63190 134 SPRINTF=`grep -e "[^v]sprintf(" ${FILENAME}`;
b8889258
AJ
135 if test "x${SPRINTF}" != "x" ; then
136 echo "ERROR: ${PWD}/${FILENAME} contains unsafe use of sprintf()"
137 fi
138
d090e020
AJ
139 #
140 # DEBUG Section list maintenance
141 #
5fbc3e1d 142 grep " DEBUG: section" <${FILENAME} | sed -e 's/ \* DEBUG: //' -e 's%/\* DEBUG: %%' -e 's% \*/%%' | sort -u >>${ROOT}/doc/debug-sections.tmp
d090e020
AJ
143
144 #
145 # File permissions maintenance.
146 #
147 chmod 644 ${FILENAME}
148 ;;
149
150 *.pl|*.sh)
151 #
152 # File permissions maintenance.
153 #
154 chmod 755 ${FILENAME}
8cd09bae
HN
155 ;;
156
157 Makefile.am)
158
ddf5d6db 159 perl -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
8cd09bae
HN
160 mv ${FILENAME}.styled ${FILENAME}
161 ;;
162
e758499d 163 ChangeLog|CREDITS|CONTRIBUTORS|COPYING|*.list|*.png|*.po|*.pot|rfcs/|*.txt|test-suite/squidconf/empty|.bzrignore)
e9549c27
AJ
164 # we do not enforce copyright blurbs in:
165 #
e758499d
AJ
166 # Squid Project contributor attribution file
167 # third-party copyright attribution file
e9549c27
AJ
168 # images,
169 # translation PO/POT
170 # auto-generated .list files,
e758499d 171 # license documentation files
e9549c27 172 # (imported) plain-text documentation files and ChangeLogs
e758499d 173 # VCS internal files
e9549c27
AJ
174 #
175 skip_copyright_check=1
176 ;;
d743fb5d 177 esac
6f98e675 178
5fbc3e1d 179 # check for Foundation copyright blurb
e9549c27 180 if test -f ${PWD}/${FILENAME} -a "x$skip_copyright_check" = "x"; then
e819858c 181 BLURB=`grep -o "${COPYRIGHT_YEARS} The Squid Software Foundation and contributors" ${FILENAME}`;
5fbc3e1d 182 if test "x${BLURB}" = "x"; then
e819858c
SM
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}
187 else
188 echo "CHECK COPYRIGHT for ${PWD}/${FILENAME}"
189 fi
5fbc3e1d
AJ
190 fi
191 fi
192
1a8e2e1c 193 if test "$FILENAME" = "libltdl/" ; then
2db7809d
AJ
194 :
195 elif test -d $FILENAME ; then
6f98e675 196 cd $FILENAME
d090e020 197 srcformat ${ROOT} || exit 1
6f98e675
AJ
198 cd ..
199 fi
200
201done
e555fec8
AJ
202}
203
598c5a44 204# Build XPROF types file from current sources
e9549c27
AJ
205(
206cat scripts/boilerplate.h
207echo "#ifndef _PROFILER_XPROF_TYPE_H_"
208echo "#define _PROFILER_XPROF_TYPE_H_"
209echo "/* AUTO-GENERATED FILE */"
210echo "#if USE_XPROF_STATS"
211echo "typedef enum {"
212echo " XPROF_PROF_UNACCOUNTED,"
213grep -R -h "PROF_start.*" ./* | grep -v probename | sed -e 's/ //g; s/PROF_start(/XPROF_/; s/);/,/' | sort -u
214echo " XPROF_LAST } xprof_type;"
215echo "#endif"
216echo "#endif"
217) >${ROOT}/lib/profiler/list
598c5a44
AJ
218mv ${ROOT}/lib/profiler/list ${ROOT}/lib/profiler/xprof_type.h
219
46002cc1 220# Build icons install include from current icons available
54966be3 221(
e9549c27 222sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h
54966be3 223echo -n "ICONS="
5fbc3e1d 224for f in `ls -1 ${ROOT}/icons/silk/* | sort -u`
d78c092d 225do
54966be3
AJ
226 echo " \\"
227 echo -n " ${f}"
d78c092d 228done
54966be3 229echo " "
e9549c27 230)| sed s%${ROOT}/icons/%%g >${ROOT}/icons/icon.list
d78c092d 231
46002cc1
AJ
232# Build templates install include from current templates available
233(
e9549c27 234sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h
46002cc1 235echo -n "ERROR_TEMPLATES="
5fbc3e1d 236for f in `ls -1 ${ROOT}/errors/templates/ERR_* | sort -u`
46002cc1
AJ
237do
238 echo " \\"
239 echo -n " ${f}"
240done
241echo " "
242)| sed s%${ROOT}/errors/%%g >${ROOT}/errors/template.list
243
244# Build errors translation install include from current .PO available
245(
e9549c27 246sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h
46002cc1 247echo -n "TRANSLATE_LANGUAGES="
5fbc3e1d 248for f in `ls -1 ${ROOT}/errors/*.po | sort -u`
46002cc1
AJ
249do
250 echo " \\"
251 echo -n " ${f}"
252done
253echo " "
254)| sed s%${ROOT}/errors/%%g | sed s%\.po%\.lang%g >${ROOT}/errors/language.list
255
256# Build manuals translation install include from current .PO available
257(
e9549c27 258sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h
46002cc1 259echo -n "TRANSLATE_LANGUAGES="
5fbc3e1d 260for f in `ls -1 ${ROOT}/doc/manuals/*.po | sort -u`
46002cc1
AJ
261do
262 echo " \\"
263 echo -n " ${f}"
264done
265echo " "
266)| sed s%${ROOT}/doc/manuals/%%g | sed s%\.po%\.lang%g >${ROOT}/doc/manuals/language.list
267
ee4478ed
AJ
268# Build STUB framework include from current stub_* available
269(
e9549c27 270sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h
1c7a7cd5 271echo -n "STUB_SOURCE= tests/STUB.h"
5fbc3e1d 272for f in `ls -1 ${ROOT}/src/tests/stub_*.cc | sort -u`
ee4478ed
AJ
273do
274 echo " \\"
275 echo -n " ${f}"
276done
277echo " "
278)| sed s%${ROOT}/src/%%g >${ROOT}/src/tests/Stub.list
279
3d50beac
FC
280# Build the GPERF generated content
281make -C src/http gperf-files
282
598c5a44 283# Run formating
d090e020 284echo "" >${ROOT}/doc/debug-sections.tmp
e555fec8 285srcformat || exit 1
e9549c27
AJ
286sort -u <${ROOT}/doc/debug-sections.tmp | sort -n >${ROOT}/doc/debug-sections.tmp2
287cat scripts/boilerplate.h ${ROOT}/doc/debug-sections.tmp2 >${ROOT}/doc/debug-sections.txt
288rm ${ROOT}/doc/debug-sections.tmp ${ROOT}/doc/debug-sections.tmp2
e819858c 289rm ${ROOT}/boilerplate_fix.sed