[gnome-builder/wip/chergert/multi-process] plugins: only load target plugin in worker process



commit 433410c3f00324d94327329f30654ea25856ad1b
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 30 13:58:58 2015 -0700

    plugins: only load target plugin in worker process
    
    If we are spawning a worker process, we only want to load the plugin for
    which the process was spawned.

 src/app/gb-application.c       |    9 +++++++++
 src/main.c                     |    3 ---
 src/util/gb-plugins.c          |   25 +++++++++++++++++++++++--
 src/util/gb-plugins.h          |    2 +-
 tests/test-helper.c            |    2 +-
 tests/test-ide-source-view.c   |    2 +-
 tools/ide-build.c              |    2 +-
 tools/ide-list-build-flags.c   |    2 +-
 tools/ide-list-devices.c       |    2 +-
 tools/ide-list-diagnostics.c   |    2 +-
 tools/ide-list-file-settings.c |    2 +-
 tools/ide-list-files.c         |    2 +-
 tools/ide-mine-projects.c      |    2 +-
 tools/ide-search.c             |    2 +-
 14 files changed, 43 insertions(+), 16 deletions(-)
---
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index c921a27..a50e72a 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -552,9 +552,18 @@ static void
 gb_application_activate (GApplication *application)
 {
   GbApplication *self = (GbApplication *)application;
+  gchar *plugins[] = { NULL, NULL };
+  const gchar * const *pluginsptr = (const gchar * const *)plugins;
 
   g_assert (GB_IS_APPLICATION (self));
 
+  if (self->type == NULL)
+    pluginsptr = NULL;
+  else
+    plugins [0] = (gchar *)self->type;
+
+  gb_plugins_init (pluginsptr);
+
   if (gb_application_is_worker (self))
     gb_application_load_worker (self);
   else
diff --git a/src/main.c b/src/main.c
index 9412351..2dabdf4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -59,9 +59,6 @@ main (int   argc,
 
   g_resources_register (gb_icons_get_resource ());
 
-  /* TODO: delay plugin loading based on --type */
-  gb_plugins_init ();
-
   app = g_object_new (GB_TYPE_APPLICATION,
                       "application-id", "org.gnome.Builder",
                       "flags", G_APPLICATION_HANDLES_OPEN,
diff --git a/src/util/gb-plugins.c b/src/util/gb-plugins.c
index 8313490..5ba62d4 100644
--- a/src/util/gb-plugins.c
+++ b/src/util/gb-plugins.c
@@ -36,8 +36,29 @@
 #include "gb-workbench.h"
 #include "gb-workspace.h"
 
+static gboolean
+can_load_plugin (PeasPluginInfo      *plugin_info,
+                 const gchar * const *plugin_names)
+{
+  const gchar *plugin_name;
+
+  /* Currently we only allow in-tree plugins */
+  if (!peas_plugin_info_is_builtin (plugin_info))
+    return FALSE;
+
+  /*
+   * If plugin_names is specified, we are only loading a subset of the
+   * plugins into this process.
+   */
+  plugin_name = peas_plugin_info_get_module_name (plugin_info);
+  if ((plugin_names != NULL) && !g_strv_contains (plugin_names, plugin_name))
+    return FALSE;
+
+  return TRUE;
+}
+
 void
-gb_plugins_init (void)
+gb_plugins_init (const gchar * const *plugin_names)
 {
   PeasEngine *engine;
   const GList *list;
@@ -96,7 +117,7 @@ gb_plugins_init (void)
 
   for (; list; list = list->next)
     {
-      if (peas_plugin_info_is_builtin (list->data))
+      if (can_load_plugin (list->data, plugin_names))
         peas_engine_load_plugin (engine, list->data);
     }
 }
diff --git a/src/util/gb-plugins.h b/src/util/gb-plugins.h
index 9e40530..a2f0464 100644
--- a/src/util/gb-plugins.h
+++ b/src/util/gb-plugins.h
@@ -23,7 +23,7 @@
 
 G_BEGIN_DECLS
 
-void gb_plugins_init (void);
+void gb_plugins_init (const gchar * const *plugin_names);
 
 G_END_DECLS
 
diff --git a/tests/test-helper.c b/tests/test-helper.c
index 69c5e0e..1b63837 100644
--- a/tests/test-helper.c
+++ b/tests/test-helper.c
@@ -38,7 +38,7 @@ test_helper_init (gint    *argc,
 {
   gtk_init (argc, argv);
   g_test_init (argc, argv, NULL);
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 }
 
 void
diff --git a/tests/test-ide-source-view.c b/tests/test-ide-source-view.c
index 8c3c5d4..6ccdc0b 100644
--- a/tests/test-ide-source-view.c
+++ b/tests/test-ide-source-view.c
@@ -755,7 +755,7 @@ main (int argc,
 
   project_dir = g_file_new_for_path (".");
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_dir,
                          NULL,
diff --git a/tools/ide-build.c b/tools/ide-build.c
index 4d23909..de2b559 100644
--- a/tools/ide-build.c
+++ b/tools/ide-build.c
@@ -389,7 +389,7 @@ main (gint   argc,
   if (!deviceId)
     deviceId = g_strdup ("local");
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_file, NULL, context_cb, NULL);
 
diff --git a/tools/ide-list-build-flags.c b/tools/ide-list-build-flags.c
index 4a1b679..8c3cf7f 100644
--- a/tools/ide-list-build-flags.c
+++ b/tools/ide-list-build-flags.c
@@ -141,7 +141,7 @@ main (gint   argc,
 
   project_file = g_file_new_for_path (project_path);
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_file, NULL, context_cb, NULL);
 
diff --git a/tools/ide-list-devices.c b/tools/ide-list-devices.c
index f94f02e..bfd1d91 100644
--- a/tools/ide-list-devices.c
+++ b/tools/ide-list-devices.c
@@ -120,7 +120,7 @@ main (gint   argc,
     project_path = argv [1];
   project_file = g_file_new_for_path (project_path);
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_file, NULL, context_cb, NULL);
 
diff --git a/tools/ide-list-diagnostics.c b/tools/ide-list-diagnostics.c
index abbec25..55e1df4 100644
--- a/tools/ide-list-diagnostics.c
+++ b/tools/ide-list-diagnostics.c
@@ -310,7 +310,7 @@ main (gint   argc,
 
   project_file = g_file_new_for_path (project_path);
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_file, NULL, context_cb, NULL);
 
diff --git a/tools/ide-list-file-settings.c b/tools/ide-list-file-settings.c
index e530a3f..6091024 100644
--- a/tools/ide-list-file-settings.c
+++ b/tools/ide-list-file-settings.c
@@ -225,7 +225,7 @@ main (gint   argc,
 
   paths = (gchar **)g_ptr_array_free (strv, FALSE);
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_file, NULL, context_cb, NULL);
 
diff --git a/tools/ide-list-files.c b/tools/ide-list-files.c
index ae54199..8f064f6 100644
--- a/tools/ide-list-files.c
+++ b/tools/ide-list-files.c
@@ -138,7 +138,7 @@ main (gint   argc,
     project_path = argv [1];
   project_file = g_file_new_for_path (project_path);
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_file, NULL, context_cb, NULL);
 
diff --git a/tools/ide-mine-projects.c b/tools/ide-mine-projects.c
index 70b2802..b575f26 100644
--- a/tools/ide-mine-projects.c
+++ b/tools/ide-mine-projects.c
@@ -95,7 +95,7 @@ main (int    argc,
 
   main_loop = g_main_loop_new (NULL, FALSE);
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   projects = ide_recent_projects_new ();
   ide_recent_projects_discover_async (projects, NULL, discover_cb, NULL);
diff --git a/tools/ide-search.c b/tools/ide-search.c
index 42a8ecc..9c4b7a8 100644
--- a/tools/ide-search.c
+++ b/tools/ide-search.c
@@ -137,7 +137,7 @@ main (gint   argc,
     g_string_append_printf (search_terms_string, " %s", argv [i]);
   search_terms = g_string_free (search_terms_string, FALSE);
 
-  gb_plugins_init ();
+  gb_plugins_init (NULL);
 
   ide_context_new_async (project_file, NULL, context_cb, NULL);
 


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