Debian Codegraph @

caca/t/check-copyright

raw
1 #!/bin/sh
2
3 export MAKEFLAGS=""
4 top_srcdir="$(make -s echo-topdir)"
5
6 #
7 # Check that the copyright information is valid
8 #
9 nfails=0
10 nfiles=0
11 for dir in $(make -s echo-dirs -C "${top_srcdir}"); do
12 if [ ! -d "${top_srcdir}/${dir}" ]; then continue; fi
13 for x in $(make -s echo-sources -C "${top_srcdir}/${dir}"); do
14 case "$x" in
15 *.c|*.cpp|*.h|*.m|*.php|*.cs|*.java|.py|.pl)
16 nfiles=$(($nfiles + 1)) ;;
17 *)
18 continue ;;
19 esac
20 if ! grep 'Copyright *\((c)\|(C)\|©\)' "${top_srcdir}/${dir}/$x" >/dev/null 2>&1; then
21 echo "error: ${dir}/$x lacks proper copyright information"
22 nfails=$(($nfails + 1))
23 elif [ -d "${top_srcdir}/.git" ]; then
24 Y="$(git log "${top_srcdir}/${dir}/$x" | head -n 3 | sed -ne 's/^Date.* \([0-9][0-9][0-9][0-9]\) .*/\1/p')"
25 if [ "$Y" != "" ]; then
26 if ! grep "$Y.*@" "${top_srcdir}/${dir}/$x" >/dev/null 2>&1; then
27 echo "error: ${top_srcdir}/${dir}/$x last modified in $Y, which is not in copyright"
28 git log "${top_srcdir}/${dir}/$x" | head -n 3 | sed 's/^/info: /'
29 nfails=$(($nfails + 1))
30 fi
31 fi
32 fi
33 done
34 done
35
36 echo "$nfiles files, $nfails errors in copyright information"
37
38 if test "$nfails" -gt "10"; then
39 echo "That’s too many errors, deliberately failing test"
40 exit 1
41 fi
42
43 exit 0
44