summaryrefslogtreecommitdiff
path: root/libappstream-builder
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-07-29 12:55:22 +0100
committerRichard Hughes <richard@hughsie.com>2015-07-29 16:27:48 +0100
commit686e844e22a81bbdc39a27b7cd2cced582808b02 (patch)
treefee0acf455a035a9c2cf9c4294f74f53ef64cb35 /libappstream-builder
parent7fdc8c83f7ab463b1429b410efcb6627df2c91f4 (diff)
downloadappstream-glib-686e844e22a81bbdc39a27b7cd2cced582808b02.tar.gz
Add asb_plugin_loader_set_dir() to set the default plugin location
We need to set this from the build system when doing running the tests with build systems that do not build in the source tree.
Diffstat (limited to 'libappstream-builder')
-rw-r--r--libappstream-builder/Makefile.am1
-rw-r--r--libappstream-builder/asb-plugin-loader.c49
-rw-r--r--libappstream-builder/asb-plugin-loader.h3
-rw-r--r--libappstream-builder/asb-self-test.c7
4 files changed, 53 insertions, 7 deletions
diff --git a/libappstream-builder/Makefile.am b/libappstream-builder/Makefile.am
index 4264820..8139e14 100644
--- a/libappstream-builder/Makefile.am
+++ b/libappstream-builder/Makefile.am
@@ -25,6 +25,7 @@ AM_CPPFLAGS = \
-DTESTDIRSRC=\""$(top_srcdir)/data/tests"\" \
-DTESTDIRBUILD=\""$(top_builddir)/data/tests"\" \
-DASB_PLUGIN_DIR=\"$(libdir)/asb-plugins-$(AS_PLUGIN_VERSION)\" \
+ -DTESTPLUGINDIR=\"./plugins/.libs\" \
-DG_LOG_DOMAIN=\"Asb\"
AS_GLIB_LIBS = \
diff --git a/libappstream-builder/asb-plugin-loader.c b/libappstream-builder/asb-plugin-loader.c
index 6f16337..35fd5d8 100644
--- a/libappstream-builder/asb-plugin-loader.c
+++ b/libappstream-builder/asb-plugin-loader.c
@@ -39,6 +39,7 @@ struct _AsbPluginLoaderPrivate
{
GPtrArray *plugins;
AsbContext *ctx;
+ gchar *plugin_dir;
};
G_DEFINE_TYPE_WITH_PRIVATE (AsbPluginLoader, asb_plugin_loader, G_TYPE_OBJECT)
@@ -85,6 +86,7 @@ asb_plugin_loader_finalize (GObject *object)
(gpointer*) &priv->ctx);
}
g_ptr_array_unref (priv->plugins);
+ g_free (priv->plugin_dir);
G_OBJECT_CLASS (asb_plugin_loader_parent_class)->finalize (object);
}
@@ -387,6 +389,40 @@ asb_plugin_loader_sort_cb (gconstpointer a, gconstpointer b)
}
/**
+ * asb_plugin_loader_get_dir:
+ * @plugin_loader: A #AsbPluginLoader
+ *
+ * Gets the plugin location.
+ *
+ * Returns: the location of the plugins
+ *
+ * Since: 0.4.2
+ **/
+const gchar *
+asb_plugin_loader_get_dir (AsbPluginLoader *plugin_loader)
+{
+ AsbPluginLoaderPrivate *priv = GET_PRIVATE (plugin_loader);
+ return priv->plugin_dir;
+}
+
+/**
+ * asb_plugin_loader_set_dir:
+ * @plugin_loader: A #AsbPluginLoader
+ * @plugin_dir: the location of the plugins
+ *
+ * Set the plugin location.
+ *
+ * Since: 0.4.2
+ **/
+void
+asb_plugin_loader_set_dir (AsbPluginLoader *plugin_loader, const gchar *plugin_dir)
+{
+ AsbPluginLoaderPrivate *priv = GET_PRIVATE (plugin_loader);
+ g_free (priv->plugin_dir);
+ priv->plugin_dir = g_strdup (plugin_dir);
+}
+
+/**
* asb_plugin_loader_setup:
* @plugin_loader: A #AsbPluginLoader
* @error: A #GError or %NULL
@@ -402,20 +438,19 @@ asb_plugin_loader_setup (AsbPluginLoader *plugin_loader, GError **error)
{
AsbPluginLoaderPrivate *priv = GET_PRIVATE (plugin_loader);
const gchar *filename_tmp;
- const gchar *location = "./plugins/.libs/";
_cleanup_dir_close_ GDir *dir = NULL;
- /* search system-wide if not found locally */
- if (!g_file_test (location, G_FILE_TEST_EXISTS))
- location = ASB_PLUGIN_DIR;
+ /* never set */
+ if (priv->plugin_dir == NULL)
+ priv->plugin_dir = g_strdup (ASB_PLUGIN_DIR);
/* search in the plugin directory for plugins */
- dir = g_dir_open (location, 0, error);
+ dir = g_dir_open (priv->plugin_dir, 0, error);
if (dir == NULL)
return FALSE;
/* try to open each plugin */
- g_debug ("searching for plugins in %s", location);
+ g_debug ("searching for plugins in %s", priv->plugin_dir);
do {
_cleanup_free_ gchar *filename_plugin = NULL;
filename_tmp = g_dir_read_name (dir);
@@ -423,7 +458,7 @@ asb_plugin_loader_setup (AsbPluginLoader *plugin_loader, GError **error)
break;
if (!g_str_has_suffix (filename_tmp, ".so"))
continue;
- filename_plugin = g_build_filename (location,
+ filename_plugin = g_build_filename (priv->plugin_dir,
filename_tmp,
NULL);
asb_plugin_loader_open_plugin (plugin_loader, filename_plugin);
diff --git a/libappstream-builder/asb-plugin-loader.h b/libappstream-builder/asb-plugin-loader.h
index 750a7ec..1ef862b 100644
--- a/libappstream-builder/asb-plugin-loader.h
+++ b/libappstream-builder/asb-plugin-loader.h
@@ -60,6 +60,9 @@ struct _AsbPluginLoaderClass
GType asb_plugin_loader_get_type (void);
AsbPluginLoader *asb_plugin_loader_new (AsbContext *ctx);
+const gchar *asb_plugin_loader_get_dir (AsbPluginLoader *plugin_loader);
+void asb_plugin_loader_set_dir (AsbPluginLoader *plugin_loader,
+ const gchar *plugin_dir);
gboolean asb_plugin_loader_setup (AsbPluginLoader *plugin_loader,
GError **error);
GPtrArray *asb_plugin_loader_get_globs (AsbPluginLoader *plugin_loader);
diff --git a/libappstream-builder/asb-self-test.c b/libappstream-builder/asb-self-test.c
index 75c34d1..67d612b 100644
--- a/libappstream-builder/asb-self-test.c
+++ b/libappstream-builder/asb-self-test.c
@@ -260,6 +260,7 @@ asb_test_plugin_loader_func (void)
/* set up loader */
ctx = asb_context_new ();
loader = asb_context_get_plugin_loader (ctx);
+ asb_plugin_loader_set_dir (loader, TESTPLUGINDIR);
ret = asb_plugin_loader_setup (loader, &error);
g_assert_no_error (error);
g_assert (ret);
@@ -299,6 +300,7 @@ static void
asb_test_context_test_func (AsbTestContextMode mode)
{
AsApp *app;
+ AsbPluginLoader *loader;
GError *error = NULL;
const gchar *expected_xml;
gboolean ret;
@@ -356,6 +358,8 @@ asb_test_context_test_func (AsbTestContextMode mode)
}
g_assert (asb_context_get_flag (ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID));
g_assert_cmpstr (asb_context_get_temp_dir (ctx), ==, "/tmp/asbuilder/temp");
+ loader = asb_context_get_plugin_loader (ctx);
+ asb_plugin_loader_set_dir (loader, TESTPLUGINDIR);
ret = asb_context_setup (ctx, &error);
g_assert_no_error (error);
g_assert (ret);
@@ -846,6 +850,7 @@ static void
asb_test_firmware_func (void)
{
AsApp *app;
+ AsbPluginLoader *loader;
const gchar *expected_xml;
gboolean ret;
guint i;
@@ -871,6 +876,8 @@ asb_test_firmware_func (void)
asb_context_set_output_dir (ctx, "/tmp/asbuilder/output");
asb_context_set_temp_dir (ctx, "/tmp/asbuilder/temp");
asb_context_set_icons_dir (ctx, "/tmp/asbuilder/temp/icons");
+ loader = asb_context_get_plugin_loader (ctx);
+ asb_plugin_loader_set_dir (loader, TESTPLUGINDIR);
ret = asb_context_setup (ctx, &error);
g_assert_no_error (error);
g_assert (ret);