[gnome-builder/wip/tintou/toolchain] Do not attempt to load the toolchain when the manager is not loaded



commit 532b6a2a4ec364082db4fefbf4b1bbf83635cb32
Author: Corentin Noël <corentin noel collabora co uk>
Date:   Tue Apr 17 11:07:53 2018 +0100

    Do not attempt to load the toolchain when the manager is not loaded

 src/libide/buildsystem/ide-build-pipeline.c  | 17 ++++++++++++-----
 src/libide/toolchain/ide-toolchain-manager.c | 12 ++++++++++++
 src/libide/toolchain/ide-toolchain-manager.h |  2 ++
 3 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/src/libide/buildsystem/ide-build-pipeline.c b/src/libide/buildsystem/ide-build-pipeline.c
index e28593b39..0e9bc92a0 100644
--- a/src/libide/buildsystem/ide-build-pipeline.c
+++ b/src/libide/buildsystem/ide-build-pipeline.c
@@ -3768,12 +3768,24 @@ _ide_build_pipeline_check_toolchain (IdeBuildPipeline *self, IdeDeviceInfo *info
 {
   g_autoptr(IdeToolchain) toolchain = NULL;
   g_autoptr(IdeTriplet) toolchain_triplet = NULL;
+  IdeContext *context;
   IdeRuntime *runtime;
   IdeTriplet *device_triplet;
+  IdeToolchainManager *toolchain_manager;
 
   g_return_if_fail (IDE_IS_BUILD_PIPELINE (self));
   g_return_if_fail (IDE_IS_DEVICE_INFO (info));
 
+  context = ide_object_get_context (IDE_OBJECT (self));
+  g_return_if_fail (IDE_IS_CONTEXT (context));
+
+  toolchain_manager = ide_context_get_toolchain_manager (context);
+  g_return_if_fail (IDE_IS_TOOLCHAIN_MANAGER (toolchain_manager));
+
+  /* Don't try to initialize too early */
+  if (ide_toolchain_manager_is_loaded (toolchain_manager))
+    return;
+
   toolchain = ide_configuration_get_toolchain (self->configuration);
   runtime = ide_configuration_get_runtime (self->configuration);
   device_triplet = ide_device_info_get_host_triplet (info);
@@ -3784,13 +3796,8 @@ _ide_build_pipeline_check_toolchain (IdeBuildPipeline *self, IdeDeviceInfo *info
       g_strcmp0 (ide_triplet_get_arch (device_triplet), ide_triplet_get_arch (toolchain_triplet)) != 0 ||
       !ide_runtime_supports_toolchain (runtime, toolchain))
     {
-      IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
-      IdeToolchainManager *toolchain_manager = ide_context_get_toolchain_manager (context);
       g_autoptr(IdeToolchain) default_toolchain = ide_toolchain_manager_get_toolchain (toolchain_manager, 
"default");
 
-      g_return_if_fail (IDE_IS_CONTEXT (context));
-      g_return_if_fail (IDE_IS_TOOLCHAIN_MANAGER (toolchain_manager));
-
       _ide_build_pipeline_set_toolchain (self, default_toolchain);
     }
 }
diff --git a/src/libide/toolchain/ide-toolchain-manager.c b/src/libide/toolchain/ide-toolchain-manager.c
index d85969a1e..933453148 100644
--- a/src/libide/toolchain/ide-toolchain-manager.c
+++ b/src/libide/toolchain/ide-toolchain-manager.c
@@ -44,6 +44,7 @@ struct _IdeToolchainManager
   GCancellable     *cancellable;
   PeasExtensionSet *extensions;
   GPtrArray        *toolchains;
+  guint             loaded : 1;
 };
 
 typedef struct
@@ -358,6 +359,8 @@ ide_toolchain_manager_init_finish (GAsyncInitable  *initable,
   g_assert (IDE_IS_TOOLCHAIN_MANAGER (initable));
   g_assert (IDE_IS_TASK (result));
 
+  IDE_TOOLCHAIN_MANAGER (initable)->loaded = TRUE;
+
   return ide_task_propagate_boolean (IDE_TASK (result), error);
 }
 
@@ -391,6 +394,7 @@ ide_toolchain_manager_class_init (IdeToolchainManagerClass *klass)
 static void
 ide_toolchain_manager_init (IdeToolchainManager *self)
 {
+  self->loaded = FALSE;
   self->cancellable = g_cancellable_new ();
   self->toolchains = g_ptr_array_new_with_free_func (g_object_unref);
 }
@@ -461,6 +465,14 @@ ide_toolchain_manager_get_toolchain (IdeToolchainManager *self,
   return NULL;
 }
 
+gboolean
+ide_toolchain_manager_is_loaded (IdeToolchainManager  *self)
+{
+  g_return_val_if_fail (IDE_IS_TOOLCHAIN_MANAGER (self), FALSE);
+
+  return self->loaded;
+}
+
 void
 _ide_toolchain_manager_prepare_async (IdeToolchainManager  *self,
                                       IdeBuildPipeline     *pipeline,
diff --git a/src/libide/toolchain/ide-toolchain-manager.h b/src/libide/toolchain/ide-toolchain-manager.h
index f4ef26d34..374a5fbb4 100644
--- a/src/libide/toolchain/ide-toolchain-manager.h
+++ b/src/libide/toolchain/ide-toolchain-manager.h
@@ -34,4 +34,6 @@ G_DECLARE_FINAL_TYPE (IdeToolchainManager, ide_toolchain_manager, IDE, TOOLCHAIN
 IDE_AVAILABLE_IN_3_30
 IdeToolchain *ide_toolchain_manager_get_toolchain (IdeToolchainManager  *self,
                                                    const gchar          *id);
+IDE_AVAILABLE_IN_3_30
+gboolean      ide_toolchain_manager_is_loaded     (IdeToolchainManager  *self);
 G_END_DECLS


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