[libhandy/msvc: 4/8] Rewrite gen-public-types.sh in Python




commit 156d1445d072ad87e714949bfcb2e396450dd84e
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Jan 19 12:19:31 2022 +0800

    Rewrite gen-public-types.sh in Python
    
    This is a direct backport from the one that is used in libadwaita with the
    appropriate adaptations, so that we can avoid the need of Unix-like tools on
    the build system, which may not be readily available, such as on Windows
    Visual Studio builds.

 src/gen-public-types.py | 32 ++++++++++++++++++++++++++++++++
 src/gen-public-types.sh | 22 ----------------------
 src/meson.build         |  3 +--
 3 files changed, 33 insertions(+), 24 deletions(-)
---
diff --git a/src/gen-public-types.py b/src/gen-public-types.py
new file mode 100644
index 00000000..1a01ba97
--- /dev/null
+++ b/src/gen-public-types.py
@@ -0,0 +1,32 @@
+#!/bin/env python3
+
+import os
+import re
+import sys
+
+def main(argv):
+    ensure_types = []
+    print('/* This file was generated by gen-public-types.py, do not edit it. */\n')
+
+    # Run through the headers fed in to #include them and extract the HDY_TYPE_* macros
+    for header in argv[1:]:
+        print('#include "%s"' % os.path.basename(header))
+        with open(header, 'r') as file:
+            for line in file:
+                match = re.search(r'#define {1,}(HDY_TYPE_[A-Z0-9_]{1,}) {1,}.*', line)
+                if match:
+                    ensure_types.append(match.group(1))
+
+    ensure_types.sort()
+
+    print('#include "hdy-main-private.h"\n')
+    print('void')
+    print('hdy_init_public_types (void)')
+    print('{')
+
+    for gtype in ensure_types:
+        print('  g_type_ensure (%s);' % gtype)
+
+    print('}')
+    
+main(sys.argv)
diff --git a/src/meson.build b/src/meson.build
index 6a4c6a30..9c104024 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -119,8 +119,7 @@ src_headers = [
   'hdy-window-handle.h',
 ]
 
-sed = find_program('sed', required: true)
-gen_public_types = find_program('gen-public-types.sh', required: true)
+gen_public_types = find_program('gen-public-types.py', required: true)
 
 libhandy_init_public_types = custom_target('hdy-public-types.c',
    output: 'hdy-public-types.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]