[buoh] introspection: Allow building without running the app



commit 078d61f89337e1c6f1a868ba89dde6d6de357718
Author: Jan Tojnar <jtojnar gmail com>
Date:   Thu Jun 23 02:35:05 2022 +0200

    introspection: Allow building without running the app
    
    In de26d1483fb1984b82ce41646f0d14fc68493400, we added support
    for the `--introspection-dump` CLI flag inside GApplication
    but that initialized a bunch of classes that e.g. try to migrate config files.
    Let’s move it to the beginning of the main program entry point before
    GApplication is even created to avoid having to set `HOME` in the Nix package
    (introduced in 15f61da9c6531b44e926c31e8a74175045ac0cdb)
    and prevent warnings about data files not being installed.

 default.nix            |  7 -------
 src/buoh-application.c | 38 --------------------------------------
 src/main.c             | 18 ++++++++++++++++++
 3 files changed, 18 insertions(+), 45 deletions(-)
---
diff --git a/default.nix b/default.nix
index 1d9ebc8..a538c26 100644
--- a/default.nix
+++ b/default.nix
@@ -101,13 +101,6 @@ in (if shell then pkgs.mkShell else pkgs.stdenv.mkDerivation) rec {
 
   inherit doCheck;
 
-  preBuild = ''
-    # Generating introspection needed for building docs runs BuohApplication,
-    # which tries to create config file in XDG_CONFIG_DIR,
-    # so we need to point HOME to an existing directory.
-    export HOME="$TMPDIR"
-  '';
-
   # Hardening does not work in debug mode
   hardeningDisable = lib.optionals shell [ "all" ];
 
diff --git a/src/buoh-application.c b/src/buoh-application.c
index 88fda6b..f8a3352 100644
--- a/src/buoh-application.c
+++ b/src/buoh-application.c
@@ -31,10 +31,6 @@
 #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"
@@ -62,16 +58,6 @@ 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, ...)
 {
@@ -92,26 +78,6 @@ 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)
 {
@@ -413,10 +379,6 @@ 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/main.c b/src/main.c
index c568175..beac402 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,6 +21,10 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#ifdef ENABLE_INTROSPECTION
+#  include <girepository.h>
+#endif
+
 #include <gtk/gtk.h>
 
 #include "buoh-application.h"
@@ -28,6 +32,20 @@
 int
 main (int argc, char *argv[])
 {
+#ifdef ENABLE_INTROSPECTION
+        const char *introspect_dump_prefix = "--introspect-dump=";
+
+        if (argc == 2 && g_str_has_prefix (argv[1], introspect_dump_prefix)) {
+                g_autoptr (GError) error = NULL;
+                if (!g_irepository_dump (argv[1] + strlen(introspect_dump_prefix), &error)) {
+                        g_critical ("Failed to dump introspection data: %s", error->message);
+                        return EXIT_FAILURE;
+                }
+
+                return EXIT_SUCCESS;
+        }
+#endif
+
         g_autoptr (BuohApplication) buoh;
 
         bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);


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