]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/source-maintenance.sh
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / scripts / source-maintenance.sh
1 #!/bin/sh
2 #
3 ## Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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
10 #
11 # This script contains the code run to perform automatic source maintenance
12 # on Squid
13 #
14
15 ## Source Code Format Enforcement
16 #
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
24 # On squid-cache.org we have to use the python scripted md5sum
25 HOST=`hostname`
26 if test "$HOST" = "squid-cache.org" ; then
27 MD5="md5"
28 else
29 MD5="md5sum"
30 fi
31
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"
35 ASVER=""
36 else
37 echo "Found astyle ${ASVER}. Formatting..."
38 fi
39
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
42
43 srcformat ()
44 {
45 #
46 # Scan for incorrect use of #ifdef/#ifndef
47 #
48 git grep "ifn?def .*_SQUID_" |
49 grep -v -E "_H$" |
50 grep -v "scripts/source-maintenance.sh" |
51 while read f; do echo "PROBLEM?: ${f}"; done
52
53 #
54 # Scan for file-specific actions
55 #
56 for FILENAME in `git ls-files`; do
57 skip_copyright_check=""
58
59 # skip subdirectories, git ls-files is recursive
60 test -d $FILENAME && continue
61
62 case ${FILENAME} in
63
64 *.h|*.c|*.cc|*.cci)
65
66 #
67 # Code Style formatting maintenance
68 #
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`;
74
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}
80 else
81 rm -f $FILENAME.astylebak
82 fi
83 fi
84 fi
85
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`;
90
91 if test "$md51" != "$md52" ; then
92 echo "NOTICE: File ${FILENAME} changed #include order"
93 fi
94 mv ${FILENAME}.sorted ${FILENAME}
95 fi
96
97 #
98 # REQUIRE squid.h first #include
99 #
100 case ${FILENAME} in
101 src/cf_gen.cc)
102 # ignore, this is a build tool.
103 ;;
104 *.c|*.cc)
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!"
108 fi
109 ;;
110 *.h|*.cci)
111 FI=`grep "#include \"squid.h\"" ${FILENAME}`;
112 if test "x${FI}" != "x" ; then
113 echo "ERROR: ${FILENAME} duplicate include of squid.h"
114 fi
115 ;;
116 esac
117
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
124 echo "ERROR: ${FILENAME} contains reference to forward.h without path"
125 fi
126
127 #
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.
131 #
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()"
135 fi
136 SPRINTF=`grep -e "[^v]sprintf(" ${FILENAME}`;
137 if test "x${SPRINTF}" != "x" ; then
138 echo "ERROR: ${FILENAME} contains unsafe use of sprintf()"
139 fi
140
141 #
142 # DEBUG Section list maintenance
143 #
144 grep " DEBUG: section" <${FILENAME} | sed -e 's/ \* DEBUG: //' -e 's%/\* DEBUG: %%' -e 's% \*/%%' | sort -u >>doc/debug-sections.tmp
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}
157 ;;
158
159 Makefile.am)
160
161 perl -p -e 's/@([A-Z0-9_]+)@/\$($1)/g' <${FILENAME} >${FILENAME}.styled
162 mv ${FILENAME}.styled ${FILENAME}
163 ;;
164
165 ChangeLog|CREDITS|CONTRIBUTORS|COPYING|*.list|*.png|*.po|*.pot|rfcs/|*.txt|test-suite/squidconf/empty|.bzrignore)
166 # we do not enforce copyright blurbs in:
167 #
168 # Squid Project contributor attribution file
169 # third-party copyright attribution file
170 # images,
171 # translation PO/POT
172 # auto-generated .list files,
173 # license documentation files
174 # (imported) plain-text documentation files and ChangeLogs
175 # VCS internal files
176 #
177 skip_copyright_check=1
178 ;;
179 esac
180
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}
189 else
190 echo "CHECK COPYRIGHT for ${FILENAME}"
191 fi
192 fi
193 fi
194
195 done
196 }
197
198 # Build XPROF types file from current sources
199 (
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;"
209 echo "#endif"
210 echo "#endif"
211 ) >lib/profiler/list
212 mv lib/profiler/list lib/profiler/xprof_type.h
213
214 # Build icons install include from current icons available
215 (
216 sed -e 's%\ \*%##%' -e 's%/\*%##%' -e 's%##/%##%' <scripts/boilerplate.h
217 echo -n "ICONS="
218 for f in `ls -1 icons/silk/* | sort -u`
219 do
220 echo " \\"
221 echo -n " ${f}"
222 done
223 echo " "
224 )| sed s%icons/%%g >icons/icon.list
225
226 # Build templates install include from current templates available
227 (
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`
231 do
232 echo " \\"
233 echo -n " ${f}"
234 done
235 echo " "
236 )| sed s%errors/%%g >errors/template.list
237
238 # Build errors translation install include from current .PO available
239 (
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`
243 do
244 echo " \\"
245 echo -n " ${f}"
246 done
247 echo " "
248 )| sed s%errors/%%g | sed s%\.po%\.lang%g >errors/language.list
249
250 # Build manuals translation install include from current .PO available
251 (
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`
255 do
256 echo " \\"
257 echo -n " ${f}"
258 done
259 echo " "
260 )| sed s%doc/manuals/%%g | sed s%\.po%\.lang%g >doc/manuals/language.list
261
262 # Build STUB framework include from current stub_* available
263 (
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`
267 do
268 echo " \\"
269 echo -n " ${f}"
270 done
271 echo " "
272 )| sed s%src/%%g >src/tests/Stub.list
273
274 # Build the GPERF generated content
275 make -C src/http gperf-files
276
277 # Run formating
278 echo "" >doc/debug-sections.tmp
279 srcformat || exit 1
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