5 # Copyright 2015 6WIND S.A.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
17 # * Neither the name of 6WIND S.A. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 # Do some basic checks in MAINTAINERS file
37 # Get files matching paths with wildcards and / meaning recursing
38 files () # <path> [<path> ...]
50 if ! echo "$1" | grep -q '/[[:space:]]*$' ; then
51 # filter out deeper directories
52 sed "/\(\/[^/]*\)\{$(($(echo "$1" | grep -o / | wc -l) + 1))\}/d"
61 # Get all files matching F: and X: fields
62 parse_fx () # <index file>
66 # parse each line excepted underlining
67 for line in $( (sed '/^-\+$/d' $1 ; echo) | sed 's,^$,§,') ; do
68 if echo "$line" | grep -q '^§$' ; then
69 # empty line delimit end of section
70 whitelist=$(files $flines)
71 blacklist=$(files $xlines)
72 match=$(aminusb "$whitelist" "$blacklist")
73 if [ -n "$match" ] ; then
80 elif echo "$line" | grep -q '^[A-Z]: ' ; then
81 # file matching pattern
82 flines=$(add_line_to_if "$line" "$flines" 'F: ')
83 # file exclusion pattern
84 xlines=$(add_line_to_if "$line" "$xlines" 'X: ')
85 else # assume it is a title
91 # Add a line to a set of lines if it begins with right pattern
92 add_line_to_if () # <new line> <lines> <head pattern>
96 echo "$1" | sed -rn "s,^$3(.*),\1,p"
101 # Subtract two sets of lines
102 aminusb () # <lines a> <lines b>
104 printf "$1\n$2\n$2" | sort | uniq -u | sed '/^$/d'
108 listed=$(parse_fx MAINTAINERS | sed '/^#/d' | sort -u)
111 echo '# files not listed'
113 aminusb "$all" "$listed"
115 # TODO: check patterns that match nothing
116 # TODO: check overlaps
117 # TODO: check orphan areas