xref: /aosp_15_r20/external/mesa3d/src/egl/egl-entrypoint-check.py (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1#!/usr/bin/env python3
2
3import argparse
4from generate.eglFunctionList import EGL_FUNCTIONS as GLVND_ENTRYPOINTS
5
6
7PREFIX1 = 'EGL_ENTRYPOINT('
8PREFIX2 = 'EGL_ENTRYPOINT2('
9SUFFIX = ')'
10
11
12# These entrypoints should *not* be in the GLVND entrypoints
13GLVND_EXCLUDED_ENTRYPOINTS = [
14        # EGL_KHR_debug
15        'eglDebugMessageControlKHR',
16        'eglQueryDebugKHR',
17        'eglLabelObjectKHR',
18    ]
19
20
21def check_entrypoint_sorted(entrypoints):
22    print('Checking that EGL API entrypoints are sorted...')
23
24    for i, _ in enumerate(entrypoints):
25        # Can't compare the first one with the previous
26        if i == 0:
27            continue
28        if entrypoints[i - 1] > entrypoints[i]:
29            print('ERROR: ' + entrypoints[i] + ' should come before ' + entrypoints[i - 1])
30            exit(1)
31
32    print('All good :)')
33
34
35def check_glvnd_entrypoints(egl_entrypoints, glvnd_entrypoints):
36    print('Checking the GLVND entrypoints against the plain EGL ones...')
37    success = True
38
39    for egl_entrypoint in egl_entrypoints:
40        if egl_entrypoint in GLVND_EXCLUDED_ENTRYPOINTS:
41            continue
42        if egl_entrypoint not in glvnd_entrypoints:
43            print('ERROR: ' + egl_entrypoint + ' is missing from the GLVND entrypoints (src/egl/generate/eglFunctionList.py)')
44            success = False
45
46    for glvnd_entrypoint in glvnd_entrypoints:
47        if glvnd_entrypoint not in egl_entrypoints:
48            print('ERROR: ' + glvnd_entrypoint + ' is missing from the plain EGL entrypoints (src/egl/main/eglentrypoint.h)')
49            success = False
50
51    for glvnd_entrypoint in GLVND_EXCLUDED_ENTRYPOINTS:
52        if glvnd_entrypoint in glvnd_entrypoints:
53            print('ERROR: ' + glvnd_entrypoint + ' is should *not* be in the GLVND entrypoints (src/egl/generate/eglFunctionList.py)')
54            success = False
55
56    if success:
57        print('All good :)')
58    else:
59        exit(1)
60
61
62def main():
63    parser = argparse.ArgumentParser()
64    parser.add_argument('header')
65    args = parser.parse_args()
66
67    with open(args.header) as header:
68        lines = header.readlines()
69
70    entrypoints = []
71    for line in lines:
72        line = line.strip()
73        if line.startswith(PREFIX1):
74            assert line.endswith(SUFFIX)
75            entrypoints.append(line[len(PREFIX1):-len(SUFFIX)])
76        if line.startswith(PREFIX2):
77            assert line.endswith(SUFFIX)
78            entrypoint = line[len(PREFIX2):-len(SUFFIX)]
79            entrypoint = entrypoint.split(',')[0].strip()
80            entrypoints.append(entrypoint)
81
82    check_entrypoint_sorted(entrypoints)
83
84    glvnd_entrypoints = [x[0] for x in GLVND_ENTRYPOINTS]
85
86    check_glvnd_entrypoints(entrypoints, glvnd_entrypoints)
87
88if __name__ == '__main__':
89    main()
90