[gnome-builder/wip/gtk4-port] plugins/meson: pump pipline when necessary to load introspection



commit 9ef3757fc1b65d63a96d9b5f63d003d95dc505f3
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 27 12:24:26 2022 -0700

    plugins/meson: pump pipline when necessary to load introspection

 src/plugins/meson/gbp-meson-introspection.c        | 85 ++++++++++++++++++++--
 src/plugins/meson/gbp-meson-introspection.h        | 10 ++-
 src/plugins/meson/gbp-meson-pipeline-addin.c       |  2 +-
 src/plugins/meson/gbp-meson-run-command-provider.c | 35 ++++++++-
 4 files changed, 120 insertions(+), 12 deletions(-)
---
diff --git a/src/plugins/meson/gbp-meson-introspection.c b/src/plugins/meson/gbp-meson-introspection.c
index 0f41894b3..1f3317538 100644
--- a/src/plugins/meson/gbp-meson-introspection.c
+++ b/src/plugins/meson/gbp-meson-introspection.c
@@ -36,6 +36,8 @@ struct _GbpMesonIntrospection
 {
   IdePipelineStage parent_instance;
 
+  IdePipeline *pipeline;
+
   char *etag;
 
   GListStore *run_commands;
@@ -45,6 +47,7 @@ struct _GbpMesonIntrospection
   char *version;
 
   guint loaded : 1;
+  guint has_built_once : 1;
 };
 
 G_DEFINE_FINAL_TYPE (GbpMesonIntrospection, gbp_meson_introspection, IDE_TYPE_PIPELINE_STAGE)
@@ -477,6 +480,8 @@ gbp_meson_introspection_build_async (IdePipelineStage    *stage,
   g_assert (IDE_IS_PIPELINE (pipeline));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
+  self->has_built_once = TRUE;
+
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, gbp_meson_introspection_build_async);
   ide_task_set_task_data (task, get_current_etag (pipeline), g_free);
@@ -550,6 +555,8 @@ gbp_meson_introspection_dispose (GObject *object)
   g_clear_pointer (&self->version, g_free);
   g_clear_pointer (&self->etag, g_free);
 
+  g_clear_weak_pointer (&self->pipeline);
+
   G_OBJECT_CLASS (gbp_meson_introspection_parent_class)->dispose (object);
 }
 
@@ -576,15 +583,83 @@ gbp_meson_introspection_init (GbpMesonIntrospection *self)
 }
 
 GbpMesonIntrospection *
-gbp_meson_introspection_new (void)
+gbp_meson_introspection_new (IdePipeline *pipeline)
+{
+  GbpMesonIntrospection *self;
+
+  g_return_val_if_fail (IDE_IS_PIPELINE (pipeline), NULL);
+
+  self = g_object_new (GBP_TYPE_MESON_INTROSPECTION, NULL);
+  g_set_weak_pointer (&self->pipeline, pipeline);
+
+  return self;
+}
+
+static void
+gbp_meson_introspection_list_run_commands_cb (GObject      *object,
+                                              GAsyncResult *result,
+                                              gpointer      user_data)
+{
+  IdePipeline *pipeline = (IdePipeline *)object;
+  g_autoptr(IdeTask) task = user_data;
+  GbpMesonIntrospection *self;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_PIPELINE (pipeline));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  self = ide_task_get_source_object (task);
+  g_assert (GBP_IS_MESON_INTROSPECTION (self));
+
+  ide_task_return_pointer (task, g_object_ref (self->run_commands), g_object_unref);
+
+  IDE_EXIT;
+}
+
+void
+gbp_meson_introspection_list_run_commands_async (GbpMesonIntrospection *self,
+                                                 GCancellable          *cancellable,
+                                                 GAsyncReadyCallback    callback,
+                                                 gpointer               user_data)
 {
-  return g_object_new (GBP_TYPE_MESON_INTROSPECTION, NULL);
+  g_autoptr(IdeTask) task = NULL;
+
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_MAIN_THREAD ());
+  g_return_if_fail (GBP_IS_MESON_INTROSPECTION (self));
+  g_return_if_fail (IDE_IS_PIPELINE (self->pipeline));
+
+  task = ide_task_new (self, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, gbp_meson_introspection_list_run_commands_async);
+
+  if (!self->has_built_once)
+    ide_pipeline_build_async (self->pipeline,
+                              IDE_PIPELINE_PHASE_CONFIGURE,
+                              cancellable,
+                              gbp_meson_introspection_list_run_commands_cb,
+                              g_steal_pointer (&task));
+  else
+    ide_task_return_pointer (task, g_object_ref (self->run_commands), g_object_unref);
+
+  IDE_EXIT;
 }
 
 GListModel *
-gbp_meson_introspection_list_run_commands (GbpMesonIntrospection *self)
+gbp_meson_introspection_list_run_commands_finish (GbpMesonIntrospection  *self,
+                                                  GAsyncResult           *result,
+                                                  GError                **error)
 {
-  g_return_val_if_fail (GBP_IS_MESON_INTROSPECTION (self), NULL);
+  GListModel *ret;
+
+  IDE_ENTRY;
 
-  return g_object_ref (G_LIST_MODEL (self->run_commands));
+  g_assert (GBP_IS_MESON_INTROSPECTION (self));
+  g_assert (IDE_IS_TASK (result));
+
+  ret = ide_task_propagate_pointer (IDE_TASK (result), error);
+
+  IDE_RETURN (ret);
 }
diff --git a/src/plugins/meson/gbp-meson-introspection.h b/src/plugins/meson/gbp-meson-introspection.h
index 1573c0f63..ed83a4c2e 100644
--- a/src/plugins/meson/gbp-meson-introspection.h
+++ b/src/plugins/meson/gbp-meson-introspection.h
@@ -28,7 +28,13 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpMesonIntrospection, gbp_meson_introspection, GBP, MESON_INTROSPECTION, 
IdePipelineStage)
 
-GbpMesonIntrospection *gbp_meson_introspection_new               (void);
-GListModel            *gbp_meson_introspection_list_run_commands (GbpMesonIntrospection *self);
+GbpMesonIntrospection *gbp_meson_introspection_new                      (IdePipeline            *pipeline);
+void                   gbp_meson_introspection_list_run_commands_async  (GbpMesonIntrospection  *self,
+                                                                         GCancellable           *cancelalble,
+                                                                         GAsyncReadyCallback     callback,
+                                                                         gpointer                user_data);
+GListModel            *gbp_meson_introspection_list_run_commands_finish (GbpMesonIntrospection  *self,
+                                                                         GAsyncResult           *result,
+                                                                         GError                **error);
 
 G_END_DECLS
diff --git a/src/plugins/meson/gbp-meson-pipeline-addin.c b/src/plugins/meson/gbp-meson-pipeline-addin.c
index 361ccb536..df1594f2e 100644
--- a/src/plugins/meson/gbp-meson-pipeline-addin.c
+++ b/src/plugins/meson/gbp-meson-pipeline-addin.c
@@ -275,7 +275,7 @@ gbp_meson_pipeline_addin_load (IdePipelineAddin *addin,
   g_signal_connect (stage, "query", G_CALLBACK (on_install_stage_query), NULL);
 
   /* Setup our introspection stage */
-  self->introspection = gbp_meson_introspection_new ();
+  self->introspection = gbp_meson_introspection_new (pipeline);
   id = ide_pipeline_attach (pipeline,
                             IDE_PIPELINE_PHASE_CONFIGURE | IDE_PIPELINE_PHASE_AFTER,
                             0,
diff --git a/src/plugins/meson/gbp-meson-run-command-provider.c 
b/src/plugins/meson/gbp-meson-run-command-provider.c
index c5925f13c..fdec98b58 100644
--- a/src/plugins/meson/gbp-meson-run-command-provider.c
+++ b/src/plugins/meson/gbp-meson-run-command-provider.c
@@ -31,6 +31,31 @@ struct _GbpMesonRunCommandProvider
   IdeObject parent_instance;
 };
 
+static void
+gbp_meson_run_command_provider_list_run_commands_cb (GObject      *object,
+                                                     GAsyncResult *result,
+                                                     gpointer      user_data)
+{
+  GbpMesonIntrospection *introspection = (GbpMesonIntrospection *)object;
+  g_autoptr(GListModel) run_commands = NULL;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_MESON_INTROSPECTION (introspection));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  if (!(run_commands = gbp_meson_introspection_list_run_commands_finish (introspection, result, &error)))
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_task_return_pointer (task, g_steal_pointer (&run_commands), g_object_unref);
+
+  IDE_EXIT;
+}
+
 static void
 gbp_meson_run_command_provider_list_commands_async (IdeRunCommandProvider *provider,
                                                     GCancellable          *cancellable,
@@ -70,11 +95,13 @@ gbp_meson_run_command_provider_list_commands_async (IdeRunCommandProvider *provi
     }
 
   introspection = gbp_meson_pipeline_addin_get_introspection (GBP_MESON_PIPELINE_ADDIN (addin));
-  run_commands = gbp_meson_introspection_list_run_commands (introspection);
 
-  ide_task_return_pointer (task,
-                           g_steal_pointer (&run_commands),
-                           g_object_unref);
+  g_assert (GBP_IS_MESON_INTROSPECTION (introspection));
+
+  gbp_meson_introspection_list_run_commands_async (introspection,
+                                                   cancellable,
+                                                   gbp_meson_run_command_provider_list_run_commands_cb,
+                                                   g_steal_pointer (&task));
 
   IDE_EXIT;
 }


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