[buoh/wip/jtojnar/gi-docgen: 1/2] Add support for introspection
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [buoh/wip/jtojnar/gi-docgen: 1/2] Add support for introspection
- Date: Wed, 4 May 2022 00:01:26 +0000 (UTC)
commit 825966bb35d19b9959461eaf8132c32714aee63e
Author: Jan Tojnar <jtojnar gmail com>
Date: Wed May 4 00:55:37 2022 +0200
Add support for introspection
It is required for Tartan to properly analyze our types.
Also will be required for API docs.
default.nix | 1 +
meson.build | 7 +++++++
meson_options.txt | 6 ++++++
src/buoh-application.c | 38 ++++++++++++++++++++++++++++++++++++++
src/meson.build | 44 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 96 insertions(+)
---
diff --git a/default.nix b/default.nix
index a6a31af..8cbfa40 100644
--- a/default.nix
+++ b/default.nix
@@ -79,6 +79,7 @@ in (if shell then pkgs.mkShell else pkgs.stdenv.mkDerivation) rec {
glib
gtk3
glib-networking # For TLS
+ gobject-introspection # for libgirepository
libsoup
libxml2
];
diff --git a/meson.build b/meson.build
index 90b4ee7..dc74faa 100644
--- a/meson.build
+++ b/meson.build
@@ -26,6 +26,7 @@ comicsdir = join_paths(pkgdatadir, 'comics')
# Dependencies
gtk = dependency('gtk+-3.0', version: '>= 3.22.0')
glib = dependency('glib-2.0', version: '>= 2.70.0')
+gobject_introspection = dependency('gobject-introspection-1.0', required: get_option('introspection'))
libsoup = dependency('libsoup-2.4', version: '>= 2.4.0')
libxml2 = dependency('libxml-2.0', version: '>= 2.4.0')
@@ -36,6 +37,8 @@ gtk_builder_tool = find_program('gtk-builder-tool', required: false)
xmllint = find_program('xmllint', required: false)
xsltproc = find_program('xsltproc', required: false)
+introspection_enabled = gobject_introspection.found()
+
buoh_deps = [
gtk,
glib,
@@ -43,6 +46,10 @@ buoh_deps = [
libxml2,
]
+if introspection_enabled
+ buoh_deps += gobject_introspection
+endif
+
if appstream_util.found()
meson.add_dist_script(
python3,
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..638b38f
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,6 @@
+option(
+ 'introspection',
+ type: 'feature',
+ value: 'auto',
+ description: 'Generate introspection data for the executable (e.g. for static analysis)',
+)
diff --git a/src/buoh-application.c b/src/buoh-application.c
index f8a3352..88fda6b 100644
--- a/src/buoh-application.c
+++ b/src/buoh-application.c
@@ -31,6 +31,10 @@
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
+#ifdef ENABLE_INTROSPECTION
+#include <girepository.h>
+#endif
+
#include "buoh-application.h"
#include "buoh-window.h"
#include "buoh-comic.h"
@@ -58,6 +62,16 @@ static void buoh_application_create_user_dir (BuohApplication
G_DEFINE_FINAL_TYPE (BuohApplication, buoh_application, GTK_TYPE_APPLICATION)
+static GOptionEntry buoh_options[] =
+{
+#ifdef ENABLE_INTROSPECTION
+ { "introspect-dump", '\0', 0, G_OPTION_ARG_STRING, NULL,
+ N_("Dump gobject introspection file"),
+ N_("input.txt,output.xml") },
+#endif
+ { NULL }
+};
+
void
buoh_debug (const gchar *format, ...)
{
@@ -78,6 +92,26 @@ buoh_debug (const gchar *format, ...)
return;
}
+static gint
+buoh_handle_local_options (GApplication *self, GVariantDict *options, gpointer user_data)
+{
+#ifdef ENABLE_INTROSPECTION
+ g_autoptr (GVariant) introspect_dump = g_variant_dict_lookup_value(options, "introspect-dump", NULL);
+
+ if (introspect_dump != NULL) {
+ g_autofree GError *error = NULL;
+ if (!g_irepository_dump (g_variant_get_string (introspect_dump, NULL), &error)) {
+ g_critical ("Failed to dump introspection data: %s", error->message);
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+ }
+#endif
+
+ return -1;
+}
+
static GList *
buoh_application_parse_selected (BuohApplication *buoh)
{
@@ -379,6 +413,10 @@ buoh_application_create_user_dir (BuohApplication *buoh)
static void
buoh_application_init (BuohApplication *buoh)
{
+ g_application_add_main_option_entries (G_APPLICATION (buoh), buoh_options);
+
+ g_signal_connect(G_APPLICATION (buoh), "handle-local-options", G_CALLBACK
(buoh_handle_local_options), NULL);
+
// If legacy path exists, use that
buoh->datadir = g_build_filename (g_get_home_dir (), ".buoh", NULL);
if (!g_file_test (buoh->datadir, G_FILE_TEST_IS_DIR)) {
diff --git a/src/meson.build b/src/meson.build
index bb6a4b8..0de48ac 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -37,6 +37,23 @@ sources += gnome.mkenums_simple(
sources: enum_headers,
)
+headers = files(
+ 'buoh-add-comic-dialog.h',
+ 'buoh-application.h',
+ 'buoh-comic-cache.h',
+ 'buoh-comic.h',
+ 'buoh-comic-list.h',
+ 'buoh-comic-loader.h',
+ 'buoh-comic-manager-date.h',
+ 'buoh-comic-manager.h',
+ 'buoh-properties-dialog.h',
+ 'buoh-settings.h',
+ 'buoh-view-comic.h',
+ 'buoh-view.h',
+ 'buoh-view-message.h',
+ 'buoh-window.h',
+)
+
cflags = [
'-DCOMICS_DIR="@0@"'.format(comicsdir),
'-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()),
@@ -44,10 +61,37 @@ cflags = [
'-DLOCALE_DIR="@0@"'.format(localedir),
]
+if introspection_enabled
+ cflags += '-DENABLE_INTROSPECTION'
+endif
+
+link_args = []
+
+if introspection_enabled
+ # Required for GIRepository to be able to dump symbols.
+ link_args += '-Wl,--export-dynamic'
+endif
+
buoh = executable(
meson.project_name(),
sources,
dependencies: buoh_deps,
c_args: cflags,
+ link_args: link_args,
install: true,
)
+
+if introspection_enabled
+ buoh_gir = gnome.generate_gir(
+ buoh,
+ sources: [
+ sources,
+ headers,
+ ],
+ namespace: 'Buoh',
+ nsversion: '0',
+ includes: [
+ 'Gtk-3.0',
+ ],
+ )
+endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]