# HG changeset patch
# Node ID 652a7fc10bb4
# Parent  3880a5d25cf2
diff --git a/gplugin-gtk3-viewer/gplugin-gtk-viewer.c b/gplugin-gtk3-viewer/gplugin-gtk-viewer.c
--- a/gplugin-gtk3-viewer/gplugin-gtk-viewer.c
+++ b/gplugin-gtk3-viewer/gplugin-gtk-viewer.c
@@ -27,8 +27,7 @@
  * Globals
  *****************************************************************************/
 static gboolean show_internal = FALSE;
-static gboolean add_default_paths = TRUE, version_only = FALSE;
-static gchar **paths = NULL;
+static gboolean version_only = FALSE;
 
 /******************************************************************************
  * Callbacks
@@ -80,18 +79,6 @@
 }
 
 static gboolean
-no_default_cb(
-	G_GNUC_UNUSED const gchar *n,
-	G_GNUC_UNUSED const gchar *v,
-	G_GNUC_UNUSED gpointer d,
-	G_GNUC_UNUSED GError **e)
-{
-	add_default_paths = FALSE;
-
-	return TRUE;
-}
-
-static gboolean
 version_cb(
 	G_GNUC_UNUSED const gchar *n,
 	G_GNUC_UNUSED const gchar *v,
@@ -161,14 +148,6 @@
 		internal_cb, "Show internal plugins",
 		NULL,
 	}, {
-		"no-default-paths", 'D', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
-		no_default_cb, "Do not search the default plugin paths",
-		NULL,
-	}, {
-		"path", 'p', 0, G_OPTION_ARG_STRING_ARRAY,
-		&paths, "Additional paths to look for plugins",
-		"PATH",
-	}, {
 		"version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
 		version_cb, "Display the version and exit",
 		NULL,
@@ -185,10 +164,12 @@
 	GError *error = NULL;
 	GOptionContext *ctx = NULL;
 	GtkWidget *window = NULL;
+	const gchar *env_paths = NULL;
 
 	ctx = g_option_context_new("");
 	g_option_context_add_main_entries(ctx, entries, NULL);
 	g_option_context_add_group(ctx, gtk_get_option_group(TRUE));
+	g_option_context_add_group(ctx, gplugin_get_option_group());
 	g_option_context_parse(ctx, &argc, &argv, &error);
 	g_option_context_free(ctx);
 
@@ -212,15 +193,16 @@
 
 	manager = gplugin_manager_get_default();
 
-	if(add_default_paths)
-		gplugin_manager_add_default_paths(manager);
-
-	if(paths) {
+	env_paths = g_getenv("GPLUGIN_PLUGIN_PATH");
+	if(env_paths != NULL) {
+		gchar **paths = g_strsplit(env_paths, G_SEARCHPATH_SEPARATOR_S, 0);
 		gint i;
 
-		for(i = 0; paths[i]; i++) {
+		for(i = 0; paths[i] != NULL; i++) {
 			gplugin_manager_prepend_path(manager, paths[i]);
 		}
+
+		g_strfreev(paths);
 	}
 
 	gplugin_manager_refresh(manager);
diff --git a/gplugin-query/gplugin-query.c b/gplugin-query/gplugin-query.c
--- a/gplugin-query/gplugin-query.c
+++ b/gplugin-query/gplugin-query.c
@@ -298,6 +298,7 @@
 	GError *error = NULL;
 	GOptionContext *ctx = NULL;
 	GOptionGroup *group = NULL;
+	const gchar *env_paths = NULL;
 	gint i = 0, ret = 0;
 
 	ctx = g_option_context_new("PLUGIN-ID...");
@@ -328,6 +329,18 @@
 
 	manager = gplugin_manager_get_default();
 
+	env_paths = g_getenv("GPLUGIN_PLUGIN_PATH");
+	if(env_paths != NULL) {
+		gchar **paths = g_strsplit(env_paths, G_SEARCHPATH_SEPARATOR_S, 0);
+		gint i;
+
+		for(i = 0; paths[i] != NULL; i++) {
+			gplugin_manager_prepend_path(manager, paths[i]);
+		}
+
+		g_strfreev(paths);
+	}
+
 	if(output_paths) {
 		GList *path = NULL;
 
diff --git a/gplugin/tests/meson.build b/gplugin/tests/meson.build
--- a/gplugin/tests/meson.build
+++ b/gplugin/tests/meson.build
@@ -16,6 +16,9 @@
 # Tests
 ###############################################################################
 
+# Add the normal plugins to the plugin path envvar
+devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir() / 'plugins')
+
 #######################################
 # Simple Tests (single file)
 #######################################
diff --git a/lua/meson.build b/lua/meson.build
--- a/lua/meson.build
+++ b/lua/meson.build
@@ -57,6 +57,9 @@
 		install : true,
 		install_dir : get_option('libdir') / 'gplugin'
 	)
+
+	# Add the loader's path to our environment variable
+	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # lua
 
 subdir('tests')
diff --git a/lua/tests/meson.build b/lua/tests/meson.build
--- a/lua/tests/meson.build
+++ b/lua/tests/meson.build
@@ -10,4 +10,7 @@
 	dependencies : [GLIB, GOBJECT, LUA, gplugin_dep])
 test('Lua Loader', e)
 
+# Add the test plugins path to our environment variable
+devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_source_dir() / 'plugins')
+
 endif  # lua
diff --git a/meson.build b/meson.build
--- a/meson.build
+++ b/meson.build
@@ -47,6 +47,26 @@
 )
 
 ###############################################################################
+# devenv
+#
+# This sets up the meson devenv stuff. See
+# https://mesonbuild.com/Commands.html#devenv for more information.
+###############################################################################
+devenv = environment()
+
+if meson.version().version_compare('>=0.58.0')
+	config_home = get_option('devenv-config-dir')
+
+	if config_home == ''
+		config_home = meson.build_root() / 'config'
+	endif
+
+	devenv.set('XDG_CONFIG_HOME', config_home)
+
+	meson.add_devenv(devenv)
+endif
+
+###############################################################################
 # NLS
 ###############################################################################
 GETTEXT_PACKAGE = 'gplugin'
diff --git a/meson_options.txt b/meson_options.txt
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -11,6 +11,12 @@
 )
 
 option(
+	'devenv-config-dir',
+	type : 'string',
+	description : 'config directory for running a devenv (defaults to a subdirectory of buildroot)'
+)
+
+option(
 	'gtk3',
 	type : 'boolean', value : true,
 	description : 'Whether or not to build the gtk3 library'
diff --git a/perl5/meson.build b/perl5/meson.build
--- a/perl5/meson.build
+++ b/perl5/meson.build
@@ -71,6 +71,9 @@
 		install : true,
 		install_dir : get_option('libdir') / 'gplugin'
 	)
+
+	# Add the loader's path to our environment variable
+	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # perl5
 
 subdir('tests')
diff --git a/perl5/tests/meson.build b/perl5/tests/meson.build
--- a/perl5/tests/meson.build
+++ b/perl5/tests/meson.build
@@ -9,4 +9,7 @@
 	dependencies : [GLIB, GOBJECT, gplugin_dep, perl_dep])
 test('Perl5 Loader', e)
 
+# Add the test plugins path to our environment variable
+devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_source_dir() / 'plugins')
+
 endif  # perl5
diff --git a/python3/meson.build b/python3/meson.build
--- a/python3/meson.build
+++ b/python3/meson.build
@@ -83,6 +83,9 @@
 		include_directories : gplugin_python3_inc,
 		link_with : gplugin_python3_static,
 	)
+
+	# Add the loader's path to our environment variable
+	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # python3
 
 subdir('tests')
diff --git a/python3/tests/meson.build b/python3/tests/meson.build
--- a/python3/tests/meson.build
+++ b/python3/tests/meson.build
@@ -19,4 +19,7 @@
 	                gplugin_python3_static_dep])
 test('Python3 utils', e)
 
+# Add the test plugins path to our environment variable
+devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_source_dir() / 'plugins')
+
 endif  # python3
diff --git a/tcc/meson.build b/tcc/meson.build
--- a/tcc/meson.build
+++ b/tcc/meson.build
@@ -26,6 +26,9 @@
 		install : true,
 		install_dir : get_option('libdir') / 'gplugin'
 	)
+
+	# Add the loader's path to our environment variable
+	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # tcc
 
 subdir('tests')
diff --git a/vala/tests/genie-plugins/meson.build b/vala/tests/genie-plugins/meson.build
--- a/vala/tests/genie-plugins/meson.build
+++ b/vala/tests/genie-plugins/meson.build
@@ -17,4 +17,7 @@
 	shared_library('unload-failed-plugin', 'unload-failed.gs',
 		name_prefix : '',
 		dependencies : [gplugin_dep, gplugin_vapi])
+
+	# Add the test plugins path to our environment variable
+	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # vapi
diff --git a/vala/tests/plugins/meson.build b/vala/tests/plugins/meson.build
--- a/vala/tests/plugins/meson.build
+++ b/vala/tests/plugins/meson.build
@@ -17,4 +17,7 @@
 	shared_library('vala-unload-shutdown', 'unload-shutdown.vala',
 		name_prefix : '',
 		dependencies : [gplugin_dep, gplugin_vapi])
+
+	# Add the test plugins path to our environment variable
+	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # vapi
