test mbuf attach
[dpdk.git] / devtools / check-maintainers.sh
1 #! /bin/sh
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2015 6WIND S.A.
4
5 # Do some basic checks in MAINTAINERS file
6
7 cd $(dirname $0)/..
8
9 # speed up by ignoring Unicode details
10 export LC_ALL=C
11
12 # Get files matching paths with wildcards and / meaning recursing
13 files () # <path> [<path> ...]
14 {
15         if [ -z "$1" ] ; then
16                 return
17         fi
18         if [ -d .git ] ; then
19                 git ls-files "$1"
20         else
21                 find "$1" -type f |
22                 sed 's,^\./,,'
23         fi |
24         # if not ended by /
25         if ! echo "$1" | grep -q '/[[:space:]]*$' ; then
26                 # filter out deeper directories
27                 sed "/\(\/[^/]*\)\{$(($(echo "$1" | grep -o / | wc -l) + 1))\}/d"
28         else
29                 cat
30         fi
31         # next path
32         shift
33         files "$@"
34 }
35
36 # Get all files matching F: and X: fields
37 parse_fx () # <index file>
38 {
39         IFS='
40 '
41         # parse each line excepted underlining
42         for line in $( (sed '/^-\+$/d' $1 ; echo) | sed 's,^$,§,') ; do
43                 if echo "$line" | grep -q '^§$' ; then
44                         # empty line delimit end of section
45                         whitelist=$(files $flines)
46                         blacklist=$(files $xlines)
47                         match=$(aminusb "$whitelist" "$blacklist")
48                         if [ -n "$whitelist" ] ; then
49                                 printf "# $title "
50                                 maintainers=$(echo "$maintainers" | sed -r 's,.*<(.*)>.*,\1,')
51                                 maintainers=$(printf "$maintainers" | sed -e 's,^,<,' -e 's,$,>,')
52                                 echo $maintainers
53                         fi
54                         if [ -n "$match" ] ; then
55                                 echo "$match"
56                         fi
57                         # flush section
58                         unset maintainers
59                         unset flines
60                         unset xlines
61                 elif echo "$line" | grep -q '^[A-Z]: ' ; then
62                         # maintainer
63                         maintainers=$(add_line_to_if "$line" "$maintainers" 'M: ')
64                         # file matching pattern
65                         flines=$(add_line_to_if "$line" "$flines" 'F: ')
66                         # file exclusion pattern
67                         xlines=$(add_line_to_if "$line" "$xlines" 'X: ')
68                 else # assume it is a title
69                         title="$line"
70                 fi
71         done
72 }
73
74 # Check patterns in F: and X:
75 check_fx () # <index file>
76 {
77         IFS='
78 '
79         for line in $(sed -n 's,^[FX]: ,,p' $1 | tr '*' '#') ; do
80                 line=$(printf "$line" | tr '#' '*')
81                 match=$(files "$line")
82                 if [ -z "$match" ] ; then
83                         echo "$line"
84                 fi
85         done
86 }
87
88 # Add a line to a set of lines if it begins with right pattern
89 add_line_to_if () # <new line> <lines> <head pattern>
90 {
91         (
92                 echo "$2"
93                 echo "$1" | sed -rn "s,^$3(.*),\1,p"
94         ) |
95         sed '/^$/d'
96 }
97
98 # Subtract two sets of lines
99 aminusb () # <lines a> <lines b>
100 {
101         printf "$1\n$2\n$2" | sort | uniq -u | sed '/^$/d'
102 }
103
104 printf 'sections: '
105 parsed=$(parse_fx MAINTAINERS)
106 echo "$parsed" | grep -c '^#'
107 printf 'with maintainer: '
108 echo "$parsed" | grep -c '^#.*@'
109 printf 'maintainers: '
110 grep '^M:.*<' MAINTAINERS | sort -u | wc -l
111
112 echo
113 echo '##########'
114 echo '# orphan areas'
115 echo '##########'
116 echo "$parsed" | sed -rn 's,^#([^@]*)$,\1,p' | uniq
117
118 echo
119 echo '##########'
120 echo '# files not listed'
121 echo '##########'
122 all=$(files ./)
123 listed=$(echo "$parsed" | sed '/^#/d' | sort -u)
124 aminusb "$all" "$listed"
125
126 echo
127 echo '##########'
128 echo '# wrong patterns'
129 echo '##########'
130 check_fx MAINTAINERS
131
132 # TODO: check overlaps