]> git.ipfire.org Git - thirdparty/gcc.git/blame - contrib/check-MAINTAINERS.py
Fix boostrap failure in tree-ssa-loop-ch.cc
[thirdparty/gcc.git] / contrib / check-MAINTAINERS.py
CommitLineData
11b26b8d
ML
1#!/usr/bin/env python3
2
83ffe9cd 3# Copyright (C) 2022-2023 Free Software Foundation, Inc.
11b26b8d
ML
4#
5# This file is part of GCC.
6#
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)
10# any later version.
11#
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.
16#
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.
21
22# Check that names in the file are sorted
23# alphabetically by surname.
24
25import locale
26import sys
27from difflib import ndiff
28from itertools import dropwhile, takewhile
29
30import unidecode
31
32locale.setlocale(locale.LC_ALL, 'en_US.utf8')
33
34exit_code = 0
35
36if len(sys.argv) != 2:
37 print('Usage: ./check-MAINTAINERS.py path-to/MAINTAINERS')
38 sys.exit(1)
39
40
41def sort_by_surname(line):
42 name = line.split('\t')[0]
43 parts = name.split()
44 surname = parts[-1]
45
46 # Special-case some names
47 if name == 'Stefan Schulze Frielinghaus':
48 surname = parts[1]
49 elif name == 'Kris Van Hees':
50 surname = parts[1]
51 elif surname == "d'Humieres":
52 surname = 'Humieres'
53
54 # Remove accents
55 return (unidecode.unidecode(surname), line)
56
57
58def has_tab(line):
59 return '\t' in line
60
61
62def is_empty(line):
63 return line
64
65
66def check_group(name, lines):
67 global exit_code
68
69 for line in lines:
70 if line.startswith(' '):
71 print(f'Line should not start with space: "{line}"')
72 exit_code = 2
73
74 lines = [line + '\n' for line in lines]
75 sorted_lines = sorted(lines, key=sort_by_surname)
76 if lines != sorted_lines:
77 exit_code = 1
78 diff = ndiff(lines, sorted_lines)
79 print(f'Wrong order for {name}:\n')
80 print(''.join(diff))
81 else:
82 print(f'{name} are fine!')
83
84
438f2a24 85lines = open(sys.argv[1]).read().splitlines()
11b26b8d
ML
86
87needle = 'Global Reviewers'
88lines = list(dropwhile(lambda x: x.strip() != needle, lines))
89lines = lines[2:]
90
91chunk = list(takewhile(is_empty, lines))
92check_group(needle, chunk)
93
94needle = 'Write After Approval'
95lines = list(dropwhile(lambda x: needle not in x, lines))
96lines = lines[2:]
97
98chunk = list(takewhile(is_empty, lines))
99check_group(needle, chunk)
100
101needle = 'Bug database only accounts'
102lines = list(dropwhile(lambda x: needle not in x, lines))
103lines = lines[2:]
104
105chunk = list(takewhile(is_empty, lines))
106check_group(needle, chunk)
107
108needle = 'Contributing under the DCO'
109lines = list(dropwhile(lambda x: needle not in x, lines))[1:]
110lines = list(dropwhile(lambda x: not has_tab(x), lines))
111check_group(needle, lines)
112
113sys.exit(exit_code)