]> git.ipfire.org Git - thirdparty/gcc.git/blame - contrib/check-params-in-docs.py
Update copyright years.
[thirdparty/gcc.git] / contrib / check-params-in-docs.py
CommitLineData
4cac9d00 1#!/usr/bin/env python3
81f86cb9 2
a945c346 3# Copyright (C) 2018-2024 Free Software Foundation, Inc.
4cac9d00
ML
4#
5# Find missing and extra parameters in documentation compared to
6# output of: gcc --help=params.
7#
8# This file is part of GCC.
9#
10# GCC is free software; you can redistribute it and/or modify it under
11# the terms of the GNU General Public License as published by the Free
12# Software Foundation; either version 3, or (at your option) any later
13# version.
14#
15# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16# WARRANTY; without even the implied warranty of MERCHANTABILITY or
17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18# for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with GCC; see the file COPYING3. If not see
22# <http://www.gnu.org/licenses/>. */
23#
24#
25#
26
4cac9d00 27import argparse
9199da4b 28import sys
467adc05 29from itertools import dropwhile, takewhile
4cac9d00 30
4cac9d00
ML
31
32def get_param_tuple(line):
467adc05 33 line = line.strip().replace('--param=', '')
4cac9d00 34 i = line.find(' ')
467adc05
ML
35 name = line[:i]
36 if '=' in name:
37 name = name[:name.find('=')]
38 description = line[i:].strip()
39 return (name, description)
40
4cac9d00
ML
41
42parser = argparse.ArgumentParser()
43parser.add_argument('texi_file')
44parser.add_argument('params_output')
45
46args = parser.parse_args()
47
9199da4b 48ignored = {'logical-op-non-short-circuit'}
4cac9d00
ML
49params = {}
50
51for line in open(args.params_output).readlines():
cab8f698 52 if line.startswith(' ' * 2) and not line.startswith(' ' * 8):
4cac9d00
ML
53 r = get_param_tuple(line)
54 params[r[0]] = r[1]
55
56# Find section in .texi manual with parameters
57texi = ([x.strip() for x in open(args.texi_file).readlines()])
467adc05
ML
58texi = dropwhile(lambda x: 'item --param' not in x, texi)
59texi = takewhile(lambda x: '@node Instrumentation Options' not in x, texi)
4cac9d00
ML
60texi = list(texi)[1:]
61
cab8f698
ML
62texi_params = []
63for line in texi:
64 for token in ('@item ', '@itemx '):
65 if line.startswith(token):
66 texi_params.append(line[len(token):])
67 break
68
9199da4b 69# skip digits
cab8f698 70texi_params = [x for x in texi_params if not x[0].isdigit()]
9199da4b 71# skip aarch64 params
cab8f698
ML
72texi_params = [x for x in texi_params if not x.startswith('aarch64')]
73sorted_params = sorted(texi_params)
4cac9d00 74
cab8f698 75texi_set = set(texi_params) - ignored
08bc73f0 76params_set = set(params.keys()) - ignored
4cac9d00 77
9199da4b 78success = True
4cac9d00
ML
79extra = texi_set - params_set
80if len(extra):
81 print('Extra:')
82 print(extra)
9199da4b 83 success = False
4cac9d00
ML
84
85missing = params_set - texi_set
86if len(missing):
87 print('Missing:')
88 for m in missing:
89 print('@item ' + m)
90 print(params[m])
91 print()
9199da4b 92 success = False
4cac9d00 93
9199da4b 94sys.exit(0 if success else 1)