check-params-in-docs.py 2.5 KB

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