From bee4b18225a2b7cde1855460bb7a4aaf5cf2b45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Wed, 21 Oct 2020 11:54:23 +0200 Subject: [PATCH] Use glib-mkenums to create the GType of all the available enums This allows the GObject Introspection to correctly understand the relations between all the from_string/to_string methods and the enum they belong to. This also allows to use the right GType when dealing with flags or enums. --- src/appstream.h | 1 + src/as-component.c | 37 ------------------------------------- src/as-component.h | 3 +-- src/meson.build | 23 +++++++++++++++++++++-- tests/meson.build | 42 +++++++----------------------------------- tools/meson.build | 6 +----- 6 files changed, 31 insertions(+), 81 deletions(-) diff --git a/src/appstream.h b/src/appstream.h index 7e520c44..12f3964d 100644 --- a/src/appstream.h +++ b/src/appstream.h @@ -48,6 +48,7 @@ extern "C" { #include #include #include +#include #include #include diff --git a/src/as-component.c b/src/as-component.c index b42d2067..74abf775 100644 --- a/src/as-component.c +++ b/src/as-component.c @@ -155,43 +155,6 @@ enum { AS_COMPONENT_SCREENSHOTS }; -/** - * as_component_kind_get_type: - * - * Defines registered component types. - */ -GType -as_component_kind_get_type (void) -{ - static volatile gsize as_component_kind_type_id__volatile = 0; - if (g_once_init_enter (&as_component_kind_type_id__volatile)) { - static const GEnumValue values[] = { - {AS_COMPONENT_KIND_UNKNOWN, "AS_COMPONENT_KIND_UNKNOWN", "unknown"}, - {AS_COMPONENT_KIND_GENERIC, "AS_COMPONENT_KIND_GENERIC", "generic"}, - {AS_COMPONENT_KIND_DESKTOP_APP, "AS_COMPONENT_KIND_DESKTOP_APP", "desktop-app"}, - {AS_COMPONENT_KIND_CONSOLE_APP, "AS_COMPONENT_KIND_CONSOLE_APP", "console-app"}, - {AS_COMPONENT_KIND_WEB_APP, "AS_COMPONENT_KIND_WEB_APP", "web-app"}, - {AS_COMPONENT_KIND_ADDON, "AS_COMPONENT_KIND_ADDON", "addon"}, - {AS_COMPONENT_KIND_FONT, "AS_COMPONENT_KIND_FONT", "font"}, - {AS_COMPONENT_KIND_CODEC, "AS_COMPONENT_KIND_CODEC", "codec"}, - {AS_COMPONENT_KIND_INPUTMETHOD, "AS_COMPONENT_KIND_INPUTMETHOD", "inputmethod"}, - {AS_COMPONENT_KIND_FIRMWARE, "AS_COMPONENT_KIND_FIRMWARE", "firmware"}, - {AS_COMPONENT_KIND_DRIVER, "AS_COMPONENT_KIND_DRIVER", "driver"}, - {AS_COMPONENT_KIND_LOCALIZATION, "AS_COMPONENT_KIND_LOCALIZATION", "localization"}, - {AS_COMPONENT_KIND_SERVICE, "AS_COMPONENT_KIND_SERVICE", "service"}, - {AS_COMPONENT_KIND_REPOSITORY, "AS_COMPONENT_KIND_REPOSITORY", "repository"}, - {AS_COMPONENT_KIND_OPERATING_SYSTEM, "AS_COMPONENT_KIND_OPERATING_SYSTEM", "operating-system"}, - {AS_COMPONENT_KIND_ICON_THEME, "AS_COMPONENT_KIND_ICON_THEME", "icon-theme"}, - {AS_COMPONENT_KIND_RUNTIME, "AS_COMPONENT_KIND_RUNTIME", "runtime"}, - {0, NULL, NULL} - }; - GType as_component_type_type_id; - as_component_type_type_id = g_enum_register_static ("AsComponentKind", values); - g_once_init_leave (&as_component_kind_type_id__volatile, as_component_type_type_id); - } - return as_component_kind_type_id__volatile; -} - /** * as_component_kind_to_string: * @kind: the #AsComponentKind. diff --git a/src/as-component.h b/src/as-component.h index 0d657fe1..9b6dca30 100644 --- a/src/as-component.h +++ b/src/as-component.h @@ -28,6 +28,7 @@ #include #include "as-context.h" #include "as-enums.h" +#include "as-enums-types.h" #include "as-provided.h" #include "as-icon.h" #include "as-screenshot.h" @@ -102,8 +103,6 @@ typedef enum { AS_COMPONENT_KIND_LAST } AsComponentKind; -#define AS_TYPE_COMPONENT_KIND (as_component_kind_get_type ()) -GType as_component_kind_get_type (void) G_GNUC_CONST; const gchar *as_component_kind_to_string (AsComponentKind kind); AsComponentKind as_component_kind_from_string (const gchar *kind_str); diff --git a/src/meson.build b/src/meson.build index 50b3e6ba..aef6df2d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -75,6 +75,12 @@ aslib_pub_headers = [ 'as-issue.h' ] +aslib_pub_enums = glib.mkenums_simple('as-enums-types', + sources : aslib_pub_headers, + install_header: true, + install_dir: 'appstream' +) + aslib_priv_headers = [ 'as-utils-private.h', 'as-tag.h', @@ -154,7 +160,8 @@ appstream_lib = library ('appstream', [aslib_src, aslib_pub_headers, aslib_priv_headers, - aslib_res], + aslib_res, + aslib_pub_enums], soversion: as_api_level, version: as_version, dependencies: [aslib_deps], @@ -163,6 +170,18 @@ appstream_lib = library ('appstream', install: true ) +appstream_dep = declare_dependency( + link_with: appstream_lib, + sources: [ + aslib_pub_headers, + aslib_pub_enums + ], + dependencies: [glib_dep, + gobject_dep], + include_directories: [appstream_lib_inc, + include_directories ('..')] +) + pkgc.generate ( version: as_version, libraries: appstream_lib, @@ -189,7 +208,7 @@ install_headers(aslib_pub_headers, subdir: 'appstream') if get_option ('gir') as_gir_typelib = glib.generate_gir ( appstream_lib, - sources: aslib_src + aslib_pub_headers, + sources: aslib_src + aslib_pub_headers + aslib_pub_enums, nsversion: '1.0', namespace: 'AppStream', symbol_prefix: 'as', diff --git a/tests/meson.build b/tests/meson.build index ec289946..261542d4 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -21,13 +21,9 @@ as_test_common_src = [ as_test_basic_exe = executable ('as-test_basic', ['test-basics.c', as_test_common_src], - include_directories: [appstream_lib_inc, - include_directories('..')], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep, xml2_dep], - link_with: [appstream_lib], ) test ('as-test_basic', as_test_basic_exe, @@ -39,13 +35,9 @@ test ('as-test_basic', as_test_xml_exe = executable ('as-test_xml', ['test-xmldata.c', as_test_common_src], - include_directories: [appstream_lib_inc, - include_directories('..')], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep, xml2_dep], - link_with: [appstream_lib], ) test ('as-test_xml', as_test_xml_exe, @@ -57,13 +49,9 @@ test ('as-test_xml', as_test_yaml_exe = executable ('as-test_yaml', ['test-yamldata.c', as_test_common_src], - include_directories: [appstream_lib_inc, - include_directories('..')], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep, xml2_dep], - link_with: [appstream_lib], ) test ('as-test_yaml', as_test_yaml_exe, @@ -75,13 +63,9 @@ test ('as-test_yaml', as_test_pool_exe = executable ('as-test_pool', ['test-pool.c', as_test_common_src], - include_directories: [appstream_lib_inc, - include_directories('..')], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep, xml2_dep], - link_with: [appstream_lib], ) test ('as-test_pool', as_test_pool_exe, @@ -93,13 +77,9 @@ test ('as-test_pool', as_test_validate_exe = executable ('as-test_validate', ['test-validate.c', as_test_common_src], - include_directories: [appstream_lib_inc, - include_directories('..')], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep, xml2_dep], - link_with: [appstream_lib], ) test ('as-test_validate', as_test_validate_exe, @@ -111,13 +91,9 @@ test ('as-test_validate', as_test_perf_exe = executable ('as-test_perf', ['test-performance.c', as_test_common_src], - include_directories: [appstream_lib_inc, - include_directories('..')], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep, xml2_dep], - link_with: [appstream_lib], ) test ('as-test_perf', as_test_perf_exe, @@ -129,13 +105,9 @@ test ('as-test_perf', as_test_misc_exe = executable ('as-test_misc', ['test-misc.c', as_test_common_src], - include_directories: [appstream_lib_inc, - include_directories('..')], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep, xml2_dep], - link_with: [appstream_lib], ) test ('as-test_misc', as_test_misc_exe, diff --git a/tools/meson.build b/tools/meson.build index b813916f..e16a1c24 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -11,11 +11,7 @@ ascli_src = [ ascli_exe = executable('appstreamcli', [ascli_src], - dependencies: [glib_dep, - gobject_dep, + dependencies: [appstream_dep, gio_dep], - link_with: [appstream_lib], - include_directories: [appstream_lib_inc, - include_directories ('..')], install: true )