[gnome-builder] build: add plugin init helper



commit b638056be0f82784478f423dfa27664e0b0ff5d5
Author: Christian Hergert <christian hergert me>
Date:   Sat Aug 22 17:23:07 2015 -0700

    build: add plugin init helper
    
    This lets us initialize plugins from both the main application and tools.
    Longer term, I imagine we want to merge this into libgnome-builder.la and
    link against that in the tools.

 src/Makefile.am       |   18 +++++++++++-
 src/main.c            |   51 ++-------------------------------
 src/util/gb-plugins.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/gb-plugins.h |   30 ++++++++++++++++++++
 4 files changed, 124 insertions(+), 49 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 215d3b7..a3e2c60 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,7 @@ EXTRA_DIST =
 
 bin_PROGRAMS = gnome-builder
 
-noinst_LTLIBRARIES = libgnome-builder.la
+noinst_LTLIBRARIES = libgnome-builder.la libplugins-util.la
 
 libgnome_builder_la_SOURCES = \
        $(gnome_builder_built_sources) \
@@ -217,11 +217,27 @@ libgnome_builder_la_CFLAGS = \
        $(NULL)
 
 
+libplugins_util_la_SOURCES = \
+       util/gb-plugins.c \
+       util/gb-plugins.h \
+       $(NULL)
+libplugins_util_la_CFLAGS = \
+       $(BUILDER_CFLAGS) \
+       -DPACKAGE_DATADIR="\"${datadir}\"" \
+       -DPACKAGE_LOCALE_DIR=\""${datadir}/locale"\" \
+       -DPACKAGE_LIBDIR=\""${libdir}"\" \
+       $(NULL)
+libplugins_util_la_LDFLAGS = \
+       -avoid-version \
+       $(NULL)
+
+
 gnome_builder_SOURCES = main.c
 gnome_builder_CFLAGS = $(libgnome_builder_la_CFLAGS)
 gnome_builder_LDADD = \
        $(top_builddir)/libide/libide-1.0.la \
        libgnome-builder.la \
+       libplugins-util.la \
        $(NULL)
 gnome_builder_LDFLAGS = \
        -export-dynamic \
diff --git a/src/main.c b/src/main.c
index 2ff76ce..907910f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,57 +26,11 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <ide.h>
-#include <libpeas/peas.h>
 #include <locale.h>
 
 #include "gb-application.h"
 #include "gb-icons-resources.h"
-
-static void
-load_plugins (void)
-{
-  PeasEngine *engine;
-  const GList *list;
-
-  engine = peas_engine_get_default ();
-
-  peas_engine_enable_loader (engine, "python3");
-
-  if (g_getenv ("GB_IN_TREE_PLUGINS") != NULL)
-    {
-      GDir *dir;
-
-      if ((dir = g_dir_open ("plugins", 0, NULL)))
-        {
-          const gchar *name;
-
-          while ((name = g_dir_read_name (dir)))
-            {
-              gchar *path;
-
-              path = g_build_filename ("plugins", name, NULL);
-              peas_engine_prepend_search_path (engine, path, path);
-              g_free (path);
-            }
-
-          g_dir_close (dir);
-        }
-    }
-  else
-    {
-      peas_engine_prepend_search_path (engine,
-                                       PACKAGE_LIBDIR"/gnome-builder/plugins",
-                                       PACKAGE_DATADIR"/gnome-builder/plugins");
-    }
-
-  list = peas_engine_get_plugin_list (engine);
-
-  for (; list; list = list->next)
-    {
-      if (peas_plugin_info_is_builtin (list->data))
-        peas_engine_load_plugin (engine, list->data);
-    }
-}
+#include "gb-plugins.h"
 
 int
 main (int   argc,
@@ -104,7 +58,8 @@ main (int   argc,
              gtk_get_micro_version ());
 
   g_resources_register (gb_icons_get_resource ());
-  load_plugins ();
+
+  gb_plugins_init ();
 
   app = g_object_new (GB_TYPE_APPLICATION,
                       "application-id", "org.gnome.Builder",
diff --git a/src/util/gb-plugins.c b/src/util/gb-plugins.c
new file mode 100644
index 0000000..e5b29c6
--- /dev/null
+++ b/src/util/gb-plugins.c
@@ -0,0 +1,74 @@
+/* gb-plugins.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "plugins"
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <libpeas/peas.h>
+
+#include "gb-plugins.h"
+
+void
+gb_plugins_init (void)
+{
+  PeasEngine *engine;
+  const GList *list;
+
+  engine = peas_engine_get_default ();
+
+  peas_engine_enable_loader (engine, "python3");
+
+  if (g_getenv ("GB_IN_TREE_PLUGINS") != NULL)
+    {
+      GDir *dir;
+
+      if ((dir = g_dir_open ("plugins", 0, NULL)))
+        {
+          const gchar *name;
+
+          while ((name = g_dir_read_name (dir)))
+            {
+              gchar *path;
+
+              path = g_build_filename ("plugins", name, NULL);
+              peas_engine_prepend_search_path (engine, path, path);
+              g_free (path);
+            }
+
+          g_dir_close (dir);
+        }
+    }
+  else
+    {
+      peas_engine_prepend_search_path (engine,
+                                       PACKAGE_LIBDIR"/gnome-builder/plugins",
+                                       PACKAGE_DATADIR"/gnome-builder/plugins");
+    }
+
+  list = peas_engine_get_plugin_list (engine);
+
+  for (; list; list = list->next)
+    {
+      if (peas_plugin_info_is_builtin (list->data))
+        peas_engine_load_plugin (engine, list->data);
+    }
+}
+
diff --git a/src/util/gb-plugins.h b/src/util/gb-plugins.h
new file mode 100644
index 0000000..9e40530
--- /dev/null
+++ b/src/util/gb-plugins.h
@@ -0,0 +1,30 @@
+/* gb-plugins.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_PLUGINS_H
+#define GB_PLUGINS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void gb_plugins_init (void);
+
+G_END_DECLS
+
+#endif /* GB_PLUGINS_H */


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