1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 16:23:14 +02:00

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.
This commit is contained in:
Linus Heckemann
2017-07-05 19:52:48 +02:00
committed by Sébastien Helleu
parent 5e48b50da8
commit d6c1d02eca
7 changed files with 83 additions and 15 deletions
+4 -4
View File
@@ -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;
}
+17 -1
View File
@@ -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])
+9 -3
View File
@@ -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);
}
+28 -1
View File
@@ -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;
+21 -4
View File
@@ -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;
}
+3 -1
View File
@@ -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);
+1 -1
View File
@@ -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");