egl/entrypoint-check: split sort-check into a function
[mesa.git] / src / egl / egl-entrypoint-check.py
1 #!/usr/bin/env python
2
3 import argparse
4
5 PREFIX = 'EGL_ENTRYPOINT('
6 SUFFIX = ')'
7
8
9 def check_entrypoint_sorted(entrypoints):
10 print('Checking that EGL API entrypoints are sorted...')
11
12 for i, _ in enumerate(entrypoints):
13 # Can't compare the first one with the previous
14 if i == 0:
15 continue
16 if entrypoints[i - 1] > entrypoints[i]:
17 print('ERROR: ' + entrypoints[i] + ' should come before ' + entrypoints[i - 1])
18 exit(1)
19
20 print('All good :)')
21
22
23 def main():
24 parser = argparse.ArgumentParser()
25 parser.add_argument('header')
26 args = parser.parse_args()
27
28 with open(args.header) as header:
29 lines = header.readlines()
30
31 entrypoints = []
32 for line in lines:
33 line = line.strip()
34 if line.startswith(PREFIX):
35 assert line.endswith(SUFFIX)
36 entrypoints.append(line[len(PREFIX):-len(SUFFIX)])
37
38 check_entrypoint_sorted(entrypoints)
39
40 if __name__ == '__main__':
41 main()