3 # Copyright (C) 2022-2024 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GCC is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING. If not, write to
19 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 # Boston, MA 02110-1301, USA.
22 # Check that names in the file are sorted
23 # alphabetically by surname.
27 from difflib
import ndiff
28 from itertools
import groupby
32 locale
.setlocale(locale
.LC_ALL
, 'en_US.utf8')
36 if len(sys
.argv
) != 2:
37 print('Usage: ./check-MAINTAINERS.py path-to/MAINTAINERS')
41 def get_surname(name
):
45 # Special-case some names
46 if name
== 'Stefan Schulze Frielinghaus':
48 elif name
== 'Kris Van Hees':
50 elif surname
== "d'Humieres":
54 return unidecode
.unidecode(surname
)
57 def check_group(name
, lines
, columns
):
62 if line
.startswith(' '):
63 print(f
'Line should not start with space: "{line}"')
67 if line
.endswith(' '):
68 print(f
'Line should not end with space: "{line}"')
72 # Special-case some names
73 if line
== 'James Norris':
74 named_lines
.append((get_surname(line
), line
+ "\n"))
78 for i
, column
in enumerate(columns
):
80 if len(line
) <= column
:
81 print(f
'Line too short: "{line}"')
83 elif column
> 0 and line
[column
- 1] != ' ':
84 print(f
'Column {column - 1} should be empty: "{line}"')
86 elif line
[column
] == ' ':
87 print(f
'Column {column} should be nonempty: "{line}"')
89 elif i
== len(columns
) - 1:
90 piece
= line
[column
:].rstrip()
92 piece
= line
[column
:columns
[i
+ 1]].rstrip()
95 print(f
'Malformed field at column {column}: "{line}"')
100 named_lines
.append((get_surname(pieces
[0]), line
+ "\n"))
103 if email
and (not email
.startswith('<') or not email
.endswith('>')):
104 print(f
'Malformed email address: "{line}"')
107 lines
= [line
+ "\n" for line
in lines
]
108 sorted_lines
= [line
for _
, line
in sorted(named_lines
)]
109 if lines
!= sorted_lines
:
111 diff
= ndiff(lines
, sorted_lines
)
112 print(f
'Wrong order for {name}:\n')
115 print(f
'{name} are fine!')
118 text
= open(sys
.argv
[1]).read()
120 print('The file should not contain tabs')
124 # heading, paragraph index, column numbers
125 ('Global Reviewers', 1, [0, 48]),
126 ('Write After Approval', 2, [0, 32, 48]),
127 ('Bug database only accounts', 1, [0, 48]),
128 ('Contributing under the DCO', 2, [0, 48])
133 for is_empty
, lines
in groupby(text
.splitlines(), lambda x
: not x
):
140 check_group(sections
[i
][0], lines
, sections
[i
][2])
142 elif len(lines
) == 1 and i
< len(sections
) and sections
[i
][0] in lines
[0]:
143 count
= sections
[i
][1]
145 if i
< len(sections
):
146 print(f
'Missing "{sections[i][0]}" section')