xref: /dpdk/devtools/check-maintainers.sh (revision 68a03efeed657e6e05f281479b33b51102797e15)
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
7cd $(dirname $0)/..
8
9# speed up by ignoring Unicode details
10export LC_ALL=C
11
12# Get files matching paths with wildcards and / meaning recursing
13files () # <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
37parse_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			include_files=$(files $flines)
46			exclude_files=$(files $xlines)
47			match=$(aminusb "$include_files" "$exclude_files")
48			if [ -n "$include_files" ] ; 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:
75check_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
89add_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
99aminusb () # <lines a> <lines b>
100{
101	printf "$1\n$2\n$2" | sort | uniq -u | sed '/^$/d'
102}
103
104printf 'sections: '
105parsed=$(parse_fx MAINTAINERS)
106echo "$parsed" | grep -c '^#'
107printf 'with maintainer: '
108echo "$parsed" | grep -c '^#.*@'
109printf 'maintainers: '
110grep '^M:.*<' MAINTAINERS | sort -u | wc -l
111
112echo
113echo '##########'
114echo '# orphan areas'
115echo '##########'
116echo "$parsed" | sed -rn 's,^#([^@]*)$,\1,p' | uniq
117
118echo
119echo '##########'
120echo '# files not listed'
121echo '##########'
122all=$(files ./)
123listed=$(echo "$parsed" | sed '/^#/d' | sort -u)
124aminusb "$all" "$listed"
125
126echo
127echo '##########'
128echo '# wrong patterns'
129echo '##########'
130check_fx MAINTAINERS
131
132# TODO: check overlaps
133