[libadwaita/msvc: 5/13] build: Redo gen-public-types.sh in Python




commit 3f86ffb51396e06c08348a8b6c8435b959184dfb
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Jan 11 17:13:45 2022 +0800

    build: Redo gen-public-types.sh in Python
    
    This way, we make builds easier in environments that do not have a unix-like
    shell and/or sed available, such as on Visual Studio and clang-cl.
    
    For Visual Studio builds, this means that we no longer need to have a separate
    Cygwin or MSYS2 installation to carry out the build.

 src/gen-public-types.py | 34 ++++++++++++++++++++++++++++++++++
 src/gen-public-types.sh | 22 ----------------------
 src/meson.build         |  3 +--
 3 files changed, 35 insertions(+), 24 deletions(-)
---
diff --git a/src/gen-public-types.py b/src/gen-public-types.py
new file mode 100644
index 00000000..755df48f
--- /dev/null
+++ b/src/gen-public-types.py
@@ -0,0 +1,34 @@
+#!/bin/env python3
+
+import os
+import re
+import sys
+
+def main(argv):
+    ensure_types = []
+    result = ['/* This file was generated by gen-plublic-types.py, do not edit it. */', '']
+
+    # Run through the headers fed in to #include them and extract the ADW_TYPE_* macros
+    for header in argv[1:]:
+        result.append('#include "%s"' % os.path.basename(header))
+        with open(header, 'r') as file:
+            for line in file:
+                match = re.search(r'#define {1,}(ADW_TYPE_[A-Z0-9_]{1,}) {1,}.*', line)
+                if match:
+                    ensure_types.append(match.group(1))
+
+    ensure_types.sort()
+
+    result.append('#include "adw-main-private.h"\n')
+    result.append('void')
+    result.append('adw_init_public_types (void)')
+    result.append('{')
+
+    for gtype in ensure_types:
+        result.append('  g_type_ensure (%s);' % gtype)
+
+    result.append('}')
+    for l in result:
+        print(l)
+    
+main(sys.argv)
diff --git a/src/meson.build b/src/meson.build
index 1ed528a0..cfd52054 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -131,8 +131,7 @@ src_headers = [
   'adw-window-title.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)
 
 libadwaita_init_public_types = custom_target('adw-public-types.c',
    output: 'adw-public-types.c',


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