From 1d873a4b05928b9ab56518908622be12d01a896b Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Wed, 26 Oct 2022 15:09:11 +0200 Subject: [PATCH] plugins: Rescan for plugins after adding search paths Using rescan allows use to give a priority to search paths. So this way plugins in `CALLS_PLUGIN_DIR` take precedence over plugins we ship. This also makes sure that the plugin test searches in the same location as CallsManager. --- src/calls-manager.c | 7 +++---- tests/test-plugins.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/calls-manager.c b/src/calls-manager.c index 1e2012f..3a89897 100644 --- a/src/calls-manager.c +++ b/src/calls-manager.c @@ -803,18 +803,17 @@ calls_manager_init (CallsManager *self) dir = g_getenv ("CALLS_PLUGIN_DIR"); if (dir && dir[0] != '\0') { g_autofree char *plugin_dir_provider = NULL; - /** Add the directory to the search path. prepend_search_path() does not work - * as expected. see https://gitlab.gnome.org/GNOME/libpeas/-/issues/19 - */ plugin_dir_provider = g_build_filename (dir, "provider", NULL); g_debug ("Adding %s to plugin search path", plugin_dir_provider); - peas_engine_add_search_path (peas, plugin_dir_provider, NULL); + peas_engine_prepend_search_path (peas, plugin_dir_provider, NULL); } default_plugin_dir_provider = g_build_filename(PLUGIN_LIBDIR, "provider", NULL); peas_engine_add_search_path (peas, default_plugin_dir_provider, NULL); g_debug ("Scanning for plugins in `%s'", default_plugin_dir_provider); + + peas_engine_rescan_plugins (peas); } diff --git a/tests/test-plugins.c b/tests/test-plugins.c index 39da630..b0ae8b2 100644 --- a/tests/test-plugins.c +++ b/tests/test-plugins.c @@ -6,6 +6,8 @@ * Author: Evangelos Ribeiro Tzaras */ +#include "config.h" + #include "calls-provider.h" #include @@ -47,15 +49,33 @@ main (gint argc, gchar *argv[]) { g_autofree char *plugin_dir_provider = NULL; + PeasEngine *peas; + const gchar *dir; + g_autofree char *default_plugin_dir_provider = NULL; gtk_test_init (&argc, &argv, NULL); + peas = peas_engine_get_default (); + /* Add builddir as search path */ #ifdef PLUGIN_BUILDDIR plugin_dir_provider = g_build_filename (PLUGIN_BUILDDIR, "provider", NULL); peas_engine_add_search_path (peas_engine_get_default (), plugin_dir_provider, NULL); #endif + dir = g_getenv ("CALLS_PLUGIN_DIR"); + if (dir && dir[0] != '\0') { + g_autofree char *plugin_dir_provider = NULL; + plugin_dir_provider = g_build_filename (dir, "provider", NULL); + g_debug ("Adding %s to plugin search path", plugin_dir_provider); + peas_engine_prepend_search_path (peas, plugin_dir_provider, NULL); + } + + default_plugin_dir_provider = g_build_filename (PLUGIN_LIBDIR, "provider", NULL); + g_debug ("Adding %s to plugin search path", default_plugin_dir_provider); + peas_engine_add_search_path (peas, default_plugin_dir_provider, NULL); + peas_engine_rescan_plugins (peas); + g_test_add_func("/Calls/Plugins/load_plugins", test_calls_plugin_loading); return g_test_run();