[gexiv2/wip/phako/error-introspection] wip: Try to get GExiv2Error into GIR




commit ff5f4192c6ee6c6271291db78a699e250917636d
Author: Jens Georg <mail jensge org>
Date:   Sun May 16 15:27:12 2021 +0200

    wip: Try to get GExiv2Error into GIR

 build-aux/build-error-enum.py | 59 +++++++++++++++++++++++++++++++++++++++++++
 gexiv2/gexiv2-error.cpp       | 11 ++++++++
 gexiv2/meson.build            | 25 +++++++++++++++---
 meson.build                   |  2 +-
 4 files changed, 92 insertions(+), 5 deletions(-)
---
diff --git a/build-aux/build-error-enum.py b/build-aux/build-error-enum.py
new file mode 100755
index 0000000..e879353
--- /dev/null
+++ b/build-aux/build-error-enum.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+import sys
+import re
+
+# From https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
+def camel_to_snake(name):
+  name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
+  return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).upper()
+
+
+HEAD = """
+#ifndef GEXIV2ERROR_H
+#define GEXIV2ERROR_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+GQuark gexiv2_error_quark(void) G_GNUC_CONST;
+
+#define GEXIV2_ERROR (gexiv2_error_quark())
+
+typedef enum _GExiv2Error {
+"""
+
+TAIL = """
+} GExiv2Error;
+
+G_END_DECLS
+
+#endif // GEXIV2ERROR_H
+"""
+
+with open(sys.argv[1]) as f:
+    state = 0
+    print(HEAD)
+    for line in f:
+        if state == 0:
+            if "enum ErrorCode" in line:
+                state = 1
+            continue
+
+        if state == 1:
+            if "//" in line:
+                continue
+            if "}" in line:
+                break
+            else:
+                line = line.strip().replace(',', '')
+                parts = line.split("=", 2)
+                if len(parts) == 2:
+                    value = int(parts[1].strip())
+                else:
+                    value = value + 1
+                line = parts[0].strip().replace(",", "")
+                snake = camel_to_snake(line[3:])
+                print(f"    GEXIV2_ERROR_{snake} = {value},")
+    print(TAIL)
diff --git a/gexiv2/gexiv2-error.cpp b/gexiv2/gexiv2-error.cpp
new file mode 100644
index 0000000..189228c
--- /dev/null
+++ b/gexiv2/gexiv2-error.cpp
@@ -0,0 +1,11 @@
+#include "gexiv2-error.h"
+
+GQuark gexiv2_error_quark() {
+    static GQuark quark = 0;
+
+    if (quark == 0) {
+        quark = g_quark_from_static_string("exiv2-error");
+    }
+
+    return quark;
+}
diff --git a/gexiv2/meson.build b/gexiv2/meson.build
index fcea1ff..1e3b3d8 100644
--- a/gexiv2/meson.build
+++ b/gexiv2/meson.build
@@ -9,8 +9,23 @@ darwin_version_minor = libversion_arr[1].to_int()
 darwin_version_micro = libversion_arr[2].to_int()
 darwin_versions = [darwin_version_major + darwin_version_minor + 1, '@0@.@1@'.format(darwin_version_major + 
darwin_version_minor + 1, darwin_version_micro)]
 
+# We need python to generate the error header
+prog_python = import('python').find_installation('python3')
+
+exiv2_error_header = exiv2.get_variable(pkgconfig: 'includedir') / 'exiv2/error.hpp'
+
 gexiv2_include_dir = join_paths(get_option('includedir'), 'gexiv2')
 
+gexiv2_error_h = custom_target(
+    'gexiv2-error.h',
+    output: 'gexiv2-error.h',
+    input: meson.source_root() / 'build-aux/build-error-enum.py',
+    capture: true,
+    command: [prog_python, '@INPUT@', exiv2_error_header],
+    install: true,
+    install_dir : gexiv2_include_dir
+)
+
 config = configuration_data()
 config.set('GEXIV2_MAJOR_VERSION', as_version[0])
 config.set('GEXIV2_MINOR_VERSION', as_version[1])
@@ -30,11 +45,11 @@ gexiv2_headers = gexiv2_enum_headers + ['gexiv2.h',
                   'gexiv2-startup.h']
 
 enum_sources = gnome.mkenums('gexiv2-enums',
-                             sources : gexiv2_enum_headers,
+                             sources : gexiv2_enum_headers + [gexiv2_error_h],
                              h_template : 'gexiv2-enums.h.template',
                              c_template : 'gexiv2-enums.cpp.template',
-                             identifier_prefix : 'gexiv2',
-                             symbol_prefix : 'GExiv2',
+                             identifier_prefix : 'GExiv2',
+                             symbol_prefix : 'gexiv2',
                              install_header : true,
                              install_dir : gexiv2_include_dir)
 
@@ -51,11 +66,13 @@ gexiv2 = library('gexiv2',
                   'gexiv2-preview-image.cpp',
                   'gexiv2-log.cpp',
                   'gexiv2-startup.cpp',
+                  'gexiv2-error.cpp',
                   'gexiv2-log-private.h',
                   'gexiv2-metadata-private.h',
                   'gexiv2-stream-io.h',
                   'gexiv2-preview-properties-private.h',
-                  'gexiv2-preview-image-private.h'] +
+                  'gexiv2-preview-image-private.h',
+                  gexiv2_error_h] +
                  gexiv2_headers +
                  [version_header] +
                  enum_sources,
diff --git a/meson.build b/meson.build
index 28f8ad5..9d3da3e 100644
--- a/meson.build
+++ b/meson.build
@@ -2,7 +2,7 @@ project(
     'gexiv2',
     ['c', 'cpp'],
     version : '0.12.2',
-    meson_version : '>=0.48',
+    meson_version : '>=0.51',
     default_options : [
         'cpp_std=c++11'
     ]


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