egl: rewrite entrypoints check
authorEric Engestrom <eric.engestrom@intel.com>
Thu, 22 Nov 2018 18:44:29 +0000 (18:44 +0000)
committerEric Engestrom <eric@engestrom.ch>
Wed, 10 Jul 2019 11:27:51 +0000 (11:27 +0000)
Part of the effort to replace shell scripts with portable python scripts.
I could've used a trivial `assert lines == sorted(lines)`, but this way
the caller is shown which entrypoint is out of order.

Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by Dylan Baker <dylan@pnwbakers.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/egl/egl-entrypoint-check [deleted file]
src/egl/egl-entrypoint-check.py [new file with mode: 0644]
src/egl/meson.build

diff --git a/src/egl/egl-entrypoint-check b/src/egl/egl-entrypoint-check
deleted file mode 100755 (executable)
index d6a4272..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-if [ -z "$srcdir" ]
-then
-  srcdir=$(dirname "$0")
-fi
-
-entrypoints=$(grep EGL_ENTRYPOINT "$srcdir"/main/eglentrypoint.h)
-sorted=$(LC_ALL=C sort <<< "$entrypoints")
-test "$entrypoints" = "$sorted"
diff --git a/src/egl/egl-entrypoint-check.py b/src/egl/egl-entrypoint-check.py
new file mode 100644 (file)
index 0000000..1e87661
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import argparse
+
+PREFIX = 'EGL_ENTRYPOINT('
+SUFFIX = ')'
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('header')
+    args = parser.parse_args()
+
+    with open(args.header) as header:
+        lines = header.readlines()
+
+    entrypoints = []
+    for line in lines:
+        line = line.strip()
+        if line.startswith(PREFIX):
+            assert line.endswith(SUFFIX)
+            entrypoints.append(line[len(PREFIX):-len(SUFFIX)])
+
+    print('Checking EGL API entrypoints are sorted')
+
+    for i, _ in enumerate(entrypoints):
+        # Can't compare the first one with the previous
+        if i == 0:
+            continue
+        if entrypoints[i - 1] > entrypoints[i]:
+            print('ERROR: ' + entrypoints[i] + ' should come before ' + entrypoints[i - 1])
+            exit(1)
+
+    print('All good :)')
+
+if __name__ == '__main__':
+    main()
index a6b66a06857d26742bfd9b9924202e03fe8ea18a..019f79ee212badd0c05f4630e978babb3d34c741 100644 (file)
@@ -208,8 +208,8 @@ if with_tests and prog_nm.found()
     suite : ['egl'],
   )
   test('egl-entrypoint-check',
-    find_program('egl-entrypoint-check'),
-    env : ['srcdir=' + meson.current_source_dir()],
+    prog_python,
+    args : files('egl-entrypoint-check.py', 'main/eglentrypoint.h'),
     suite : ['egl'],
   )
 endif