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