(root)/
gcc-13.2.0/
contrib/
check-MAINTAINERS.py
       1  #!/usr/bin/env python3
       2  
       3  # Copyright (C) 2022-2023 Free Software Foundation, Inc.
       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  
      25  import locale
      26  import sys
      27  from difflib import ndiff
      28  from itertools import dropwhile, takewhile
      29  
      30  import unidecode
      31  
      32  locale.setlocale(locale.LC_ALL, 'en_US.utf8')
      33  
      34  exit_code = 0
      35  
      36  if len(sys.argv) != 2:
      37      print('Usage: ./check-MAINTAINERS.py path-to/MAINTAINERS')
      38      sys.exit(1)
      39  
      40  
      41  def 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  
      58  def has_tab(line):
      59      return '\t' in line
      60  
      61  
      62  def is_empty(line):
      63      return line
      64  
      65  
      66  def 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  
      85  lines = open(sys.argv[1]).read().splitlines()
      86  
      87  needle = 'Global Reviewers'
      88  lines = list(dropwhile(lambda x: x.strip() != needle, lines))
      89  lines = lines[2:]
      90  
      91  chunk = list(takewhile(is_empty, lines))
      92  check_group(needle, chunk)
      93  
      94  needle = 'Write After Approval'
      95  lines = list(dropwhile(lambda x: needle not in x, lines))
      96  lines = lines[2:]
      97  
      98  chunk = list(takewhile(is_empty, lines))
      99  check_group(needle, chunk)
     100  
     101  needle = 'Bug database only accounts'
     102  lines = list(dropwhile(lambda x: needle not in x, lines))
     103  lines = lines[2:]
     104  
     105  chunk = list(takewhile(is_empty, lines))
     106  check_group(needle, chunk)
     107  
     108  needle = 'Contributing under the DCO'
     109  lines = list(dropwhile(lambda x: needle not in x, lines))[1:]
     110  lines = list(dropwhile(lambda x: not has_tab(x), lines))
     111  check_group(needle, lines)
     112  
     113  sys.exit(exit_code)