summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Heckemann <git@sphalerite.org>2017-07-05 19:52:48 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-07-05 19:52:48 +0200
commitd6c1d02ecae43827830589dfcec57350998cabd5 (patch)
tree26720da6b6a0283711dacfebae7c7b1318c3263f
parent5e48b50da8e04d55f2a68ddc67758ddbf69fd01a (diff)
downloadweechat-d6c1d02ecae43827830589dfcec57350998cabd5.zip
core: search WEECHAT_EXTRA_LIBDIR for plugins (closes #971, issue #979)
In addition to searching the statically configured WEECHAT_LIBDIR (weechat's installation directory) for plugins, search the path given in the environment variable WEECHAT_EXTRA_LIBDIR. This makes departing from the FHS standard while keeping the plugins packaged separately easier. This change was made specifically with the Nix package manager in mind, but can easily be used by others.
-rw-r--r--src/core/wee-command.c8
-rw-r--r--src/core/wee-completion.c18
-rw-r--r--src/core/wee-debug.c12
-rw-r--r--src/core/wee-util.c29
-rw-r--r--src/plugins/plugin.c25
-rw-r--r--src/plugins/plugin.h4
-rw-r--r--tests/tests.cpp2
7 files changed, 83 insertions, 15 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 5c00f3d5b..21bae289a 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -4477,10 +4477,10 @@ COMMAND_CALLBACK(plugin)
{
plugin_argv = string_split (argv_eol[2], " ", 0, 0,
&plugin_argc);
- plugin_auto_load (plugin_argc, plugin_argv, 1, 1);
+ plugin_auto_load (plugin_argc, plugin_argv, 1, 1, 1);
}
else
- plugin_auto_load (0, NULL, 1, 1);
+ plugin_auto_load (0, NULL, 1, 1, 1);
return WEECHAT_RC_OK;
}
@@ -4514,7 +4514,7 @@ COMMAND_CALLBACK(plugin)
if (strcmp (argv[2], "*") == 0)
{
plugin_unload_all ();
- plugin_auto_load (plugin_argc, plugin_argv, 1, 1);
+ plugin_auto_load (plugin_argc, plugin_argv, 1, 1, 1);
}
else
{
@@ -4529,7 +4529,7 @@ COMMAND_CALLBACK(plugin)
else
{
plugin_unload_all ();
- plugin_auto_load (0, NULL, 1, 1);
+ plugin_auto_load (0, NULL, 1, 1, 1);
}
return WEECHAT_RC_OK;
}
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c
index 6c30084e7..96034f8d5 100644
--- a/src/core/wee-completion.c
+++ b/src/core/wee-completion.c
@@ -875,7 +875,7 @@ completion_list_add_plugins_installed_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
- char *plugin_path, *plugin_path2, *dir_name;
+ char *plugin_path, *plugin_path2, *dir_name, *extra_libdir;
int length;
/* make C compiler happy */
@@ -884,6 +884,22 @@ completion_list_add_plugins_installed_cb (const void *pointer, void *data,
(void) completion_item;
(void) buffer;
+ /* plugins in WeeChat extra lib dir */
+ extra_libdir = getenv ("WEECHAT_EXTRA_LIBDIR");
+ if (extra_libdir && extra_libdir[0])
+ {
+ length = strlen (extra_libdir) + 16 + 1;
+ dir_name = malloc (length);
+ if (dir_name)
+ {
+ snprintf (dir_name, length, "%s/plugins", extra_libdir);
+ util_exec_on_files (dir_name, 1, 0,
+ &completion_list_add_plugins_installed_exec_cb,
+ completion);
+ free (dir_name);
+ }
+ }
+
/* plugins in WeeChat home dir */
if (CONFIG_STRING(config_plugin_path)
&& CONFIG_STRING(config_plugin_path)[0])
diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c
index 9bd33b4ba..9dc9c2ec7 100644
--- a/src/core/wee-debug.c
+++ b/src/core/wee-debug.c
@@ -571,12 +571,18 @@ debug_libs_cb (const void *pointer, void *data,
void
debug_directories ()
{
+ char *extra_libdir;
+
+ extra_libdir = getenv ("WEECHAT_EXTRA_LIBDIR");
+
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("Directories:"));
- gui_chat_printf (NULL, " home : %s (%s: %s)",
+ gui_chat_printf (NULL, " home: %s (%s: %s)",
weechat_home, _("default"), WEECHAT_HOME);
- gui_chat_printf (NULL, " lib : %s", WEECHAT_LIBDIR);
- gui_chat_printf (NULL, " share : %s", WEECHAT_SHAREDIR);
+ gui_chat_printf (NULL, " lib: %s", WEECHAT_LIBDIR);
+ gui_chat_printf (NULL, " lib (extra): %s",
+ (extra_libdir && extra_libdir[0]) ? extra_libdir : "-");
+ gui_chat_printf (NULL, " share: %s", WEECHAT_SHAREDIR);
gui_chat_printf (NULL, " locale: %s", LOCALEDIR);
}
diff --git a/src/core/wee-util.c b/src/core/wee-util.c
index 5e22e454d..d9cd4e2fe 100644
--- a/src/core/wee-util.c
+++ b/src/core/wee-util.c
@@ -541,7 +541,7 @@ char *
util_search_full_lib_name_ext (const char *filename, const char *extension,
const char *plugins_dir)
{
- char *name_with_ext, *final_name;
+ char *name_with_ext, *final_name, *extra_libdir;
int length;
struct stat st;
@@ -554,6 +554,33 @@ util_search_full_lib_name_ext (const char *filename, const char *extension,
filename,
(strchr (filename, '.')) ? "" : extension);
+ /* try libdir from environment variable WEECHAT_EXTRA_LIBDIR */
+ extra_libdir = getenv ("WEECHAT_EXTRA_LIBDIR");
+ if (extra_libdir && extra_libdir[0])
+ {
+ length = strlen (extra_libdir) + strlen (name_with_ext) +
+ strlen (plugins_dir) + 16;
+ final_name = malloc(length);
+ if (!final_name)
+ {
+ free (name_with_ext);
+ return NULL;
+ }
+ snprintf (final_name, length,
+ "%s%s%s%s%s",
+ extra_libdir,
+ DIR_SEPARATOR,
+ plugins_dir,
+ DIR_SEPARATOR,
+ name_with_ext);
+ if ((stat (final_name, &st) == 0) && (st.st_size > 0))
+ {
+ free (name_with_ext);
+ return final_name;
+ }
+ free (final_name);
+ }
+
/* try WeeChat user's dir */
length = strlen (weechat_home) + strlen (name_with_ext) +
strlen (plugins_dir) + 16;
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 3ba9a59b0..ac2009a1c 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -992,10 +992,12 @@ plugin_arraylist_cmp_cb (void *data,
*/
void
-plugin_auto_load (int argc, char **argv, int load_from_plugin_path,
+plugin_auto_load (int argc, char **argv,
+ int load_from_plugin_path,
+ int load_from_extra_lib_dir,
int load_from_lib_dir)
{
- char *dir_name, *plugin_path, *plugin_path2;
+ char *dir_name, *plugin_path, *plugin_path2, *extra_libdir;
struct t_weechat_plugin *ptr_plugin;
struct t_plugin_args plugin_args;
struct t_arraylist *arraylist;
@@ -1015,7 +1017,7 @@ plugin_auto_load (int argc, char **argv, int load_from_plugin_path,
&plugin_autoload_count);
}
- /* auto-load plugins in WeeChat home dir */
+ /* auto-load plugins in custom path */
if (load_from_plugin_path
&& CONFIG_STRING(config_plugin_path)
&& CONFIG_STRING(config_plugin_path)[0])
@@ -1036,6 +1038,21 @@ plugin_auto_load (int argc, char **argv, int load_from_plugin_path,
free (plugin_path2);
}
+ /* auto-load plugins in WEECHAT_EXTRA_LIBDIR environment variable */
+ if (load_from_extra_lib_dir)
+ {
+ extra_libdir = getenv ("WEECHAT_EXTRA_LIBDIR");
+ if (extra_libdir && extra_libdir[0])
+ {
+ length = strlen (extra_libdir) + 16 + 1;
+ dir_name = malloc (length);
+ snprintf (dir_name, length, "%s/plugins", extra_libdir);
+ util_exec_on_files (dir_name, 1, 0,
+ &plugin_auto_load_file, &plugin_args);
+ free (dir_name);
+ }
+ }
+
/* auto-load plugins in WeeChat global lib dir */
if (load_from_lib_dir)
{
@@ -1337,7 +1354,7 @@ plugin_init (int auto_load, int argc, char *argv[])
if (auto_load)
{
plugin_quiet = 1;
- plugin_auto_load (argc, argv, 1, 1);
+ plugin_auto_load (argc, argv, 1, 1, 1);
plugin_display_short_list ();
plugin_quiet = 0;
}
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index 23adcc2f9..d7d3e386e 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -39,7 +39,9 @@ extern const char *plugin_get_name (struct t_weechat_plugin *plugin);
extern struct t_weechat_plugin *plugin_load (const char *filename,
int init_plugin,
int argc, char **argv);
-extern void plugin_auto_load (int argc, char **argv, int load_from_plugin_path,
+extern void plugin_auto_load (int argc, char **argv,
+ int load_from_plugin_path,
+ int load_from_extra_lib_dir,
int load_from_lib_dir);
extern void plugin_unload (struct t_weechat_plugin *plugin);
extern void plugin_unload_name (const char *name);
diff --git a/tests/tests.cpp b/tests/tests.cpp
index 57e73ddb1..41a03ca9a 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -161,7 +161,7 @@ main (int argc, char *argv[])
input_data (gui_buffer_search_main (), "/command core version");
/* auto-load plugins, only from path in option weechat.plugin.path */
- plugin_auto_load (0, NULL, 1, 0);
+ plugin_auto_load (0, NULL, 1, 0, 0);
/* run all tests */
printf ("\n");