3 ## Copyright (C) 1996-2018 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
32 ASVER
=`astyle --version 2>&1 | grep -o -E "[0-9.]+"`
33 if test "${ASVER}" != "2.04" ; then
34 echo "Astyle version problem. You have ${ASVER} instead of 2.04"
37 echo "Found astyle ${ASVER}. Formatting..."
40 COPYRIGHT_YEARS
=`date +"1996-%Y"`
41 echo "s/1996-2[0-9]+ The Squid Software Foundation and contributors/${COPYRIGHT_YEARS} The Squid Software Foundation and contributors/g" >>boilerplate_fix.
sed
46 # Scan for incorrect use of #ifdef/#ifndef
48 git
grep "ifn?def .*_SQUID_" |
50 grep -v "scripts/source-maintenance.sh" |
51 while read f
; do echo "PROBLEM?: ${f}"; done
54 # Scan for file-specific actions
56 for FILENAME
in `git ls-files`; do
57 skip_copyright_check
=""
59 # skip subdirectories, git ls-files is recursive
60 test -d $FILENAME && continue
67 # Code Style formatting maintenance
69 if test "${ASVER}"; then
70 .
/scripts
/formater.pl
${FILENAME}
71 if test -e $FILENAME -a -e "$FILENAME.astylebak"; then
72 md51
=`cat $FILENAME| tr -d "\n \t\r" | $MD5`;
73 md52
=`cat $FILENAME.astylebak| tr -d "\n \t\r" | $MD5`;
75 if test "$md51" != "$md52"; then
76 echo "ERROR: File $FILENAME not formating well";
77 mv $FILENAME $FILENAME.astylebad
78 mv $FILENAME.astylebak
$FILENAME
79 git checkout
-- ${FILENAME}
81 rm -f $FILENAME.astylebak
86 .
/scripts
/sort-includes.pl
${FILENAME} >${FILENAME}.sorted
87 if test -e ${FILENAME} -a -e "${FILENAME}.sorted"; then
88 md51
=`cat ${FILENAME}| tr -d "\n \t\r" | $MD5`;
89 md52
=`cat ${FILENAME}.sorted| tr -d "\n \t\r" | $MD5`;
91 if test "$md51" != "$md52" ; then
92 echo "NOTICE: File ${FILENAME} changed #include order"
94 mv ${FILENAME}.sorted
${FILENAME}
98 # REQUIRE squid.h first #include
102 # ignore, this is a build tool.
105 FI
=`grep "#include" ${FILENAME} | head -1`;
106 if test "${FI}" != "#include \"squid.h\"" -a "${FILENAME}" != "cf_gen.cc"; then
107 echo "ERROR: ${FILENAME} does not include squid.h first!"
111 FI
=`grep "#include \"squid.h\"" ${FILENAME}`;
112 if test "x${FI}" != "x" ; then
113 echo "ERROR: ${FILENAME} duplicate include of squid.h"
119 # forward.h means different things to Squid code depending on the path
120 # require the full path is explicit for every include
122 FI
=`grep "#include \"forward.h\"" ${FILENAME}`;
123 if test "x${FI}" != "x" ; then
124 echo "ERROR: ${FILENAME} contains reference to forward.h without path"
128 # detect functions unsafe for use within Squid.
129 # strdup() - only allowed in compat/xstring.h which defines a safe replacement.
130 # sprintf() - not allowed anywhere.
132 STRDUP
=`grep -e "[^x]strdup(" ${FILENAME}`;
133 if test "x${STRDUP}" != "x" -a "${FILENAME}" != "xstring.h"; then
134 echo "ERROR: ${FILENAME} contains unprotected use of strdup()"
136 SPRINTF
=`grep -e "[^v]sprintf(" ${FILENAME}`;
137 if test "x${SPRINTF}" != "x" ; then
138 echo "ERROR: ${FILENAME} contains unsafe use of sprintf()"
142 # DEBUG Section list maintenance
144 grep " DEBUG: section" <${FILENAME} |
sed -e 's/ \* DEBUG: //' -e 's%/\* DEBUG: %%' -e 's% \*/%%' |
sort -u >>doc
/debug-sections.tmp
147 # File permissions maintenance.
149 chmod 644 ${FILENAME}
154 # File permissions maintenance.
156 chmod 755 ${FILENAME}
161 perl
-p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
162 mv ${FILENAME}.styled
${FILENAME}
165 ChangeLog|CREDITS|CONTRIBUTORS|COPYING|
*.list|
*.png|
*.po|
*.pot|rfcs
/|
*.txt|test-suite
/squidconf
/empty|.bzrignore
)
166 # we do not enforce copyright blurbs in:
168 # Squid Project contributor attribution file
169 # third-party copyright attribution file
172 # auto-generated .list files,
173 # license documentation files
174 # (imported) plain-text documentation files and ChangeLogs
177 skip_copyright_check
=1
181 # check for Foundation copyright blurb
182 if test -f ${FILENAME} -a "x$skip_copyright_check" = "x"; then
183 BLURB
=`grep -o "${COPYRIGHT_YEARS} The Squid Software Foundation and contributors" ${FILENAME}`;
184 if test "x${BLURB}" = "x"; then
185 BOILER
=`grep -o -E "1996-2[0-9]+ The Squid Software Foundation and contributors" ${FILENAME}`;
186 if test "x${BOILER}" != "x"; then
187 echo "UPDATE COPYRIGHT for ${FILENAME}"
188 sed --in-place -r -f boilerplate_fix.
sed ${FILENAME}
190 echo "CHECK COPYRIGHT for ${FILENAME}"
198 # Build XPROF types file from current sources
200 cat scripts
/boilerplate.h
201 echo "#ifndef _PROFILER_XPROF_TYPE_H_"
202 echo "#define _PROFILER_XPROF_TYPE_H_"
203 echo "/* AUTO-GENERATED FILE */"
204 echo "#if USE_XPROF_STATS"
205 echo "typedef enum {"
206 echo " XPROF_PROF_UNACCOUNTED,"
207 grep -R -h "PROF_start.*" .
/* |
grep -v probename |
sed -e 's/ //g; s/PROF_start(/XPROF_/; s/);/,/' |
sort -u
208 echo " XPROF_LAST } xprof_type;"
212 mv lib
/profiler
/list lib
/profiler
/xprof_type.h
214 # Build icons install include from current icons available
216 sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts
/boilerplate.h
218 for f
in `ls -1 icons/silk/* | sort -u`
224 )|
sed s
%icons
/%%g
>icons
/icon.list
226 # Build templates install include from current templates available
228 sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts
/boilerplate.h
229 echo -n "ERROR_TEMPLATES="
230 for f
in `ls -1 errors/templates/ERR_* | sort -u`
236 )|
sed s
%errors
/%%g
>errors
/template.list
238 # Build errors translation install include from current .PO available
240 sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts
/boilerplate.h
241 echo -n "TRANSLATE_LANGUAGES="
242 for f
in `ls -1 errors/*.po | sort -u`
248 )|
sed s
%errors
/%%g |
sed s
%\.po
%\.lang
%g
>errors
/language.list
250 # Build manuals translation install include from current .PO available
252 sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts
/boilerplate.h
253 echo -n "TRANSLATE_LANGUAGES="
254 for f
in `ls -1 doc/manuals/*.po | sort -u`
260 )|
sed s
%doc
/manuals
/%%g |
sed s
%\.po
%\.lang
%g
>doc
/manuals
/language.list
262 # Build STUB framework include from current stub_* available
264 sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts
/boilerplate.h
265 echo -n "STUB_SOURCE= tests/STUB.h"
266 for f
in `ls -1 src/tests/stub_*.cc | sort -u`
272 )|
sed s
%src
/%%g
>src
/tests
/Stub.list
274 # Build the GPERF generated content
275 make -C src
/http gperf-files
278 echo "" >doc
/debug-sections.tmp
280 sort -u <doc
/debug-sections.tmp |
sort -n >doc
/debug-sections.tmp2
281 cat scripts
/boilerplate.h
doc
/debug-sections.tmp2
>doc
/debug-sections.txt
282 rm doc
/debug-sections.tmp
doc
/debug-sections.tmp2
283 rm boilerplate_fix.
sed