aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-10-07 15:51:37 +0200
committerKim Alvefur <zash@zash.se>2020-10-07 15:51:37 +0200
commit915cebae961534f07c3c70bc5ab7b3ec5b790aba (patch)
treee1b15d78a223eebe6e5390c02ae319f9f718ad86 /core
parentf7f0a20abffc3535b02ffe06235964929cc87091 (diff)
downloadprosody-915cebae961534f07c3c70bc5ab7b3ec5b790aba.tar.gz
prosody-915cebae961534f07c3c70bc5ab7b3ec5b790aba.zip
core.modulemanager: Locate resources of LuaRocks-installed modules
Extra non-code files included with a `copy_directories` directive in a LuaRocks manifest will be copied into a per-module and per-version directory under /lib/luarocks/ and all this is there to dig that out so it can be used in e.g. moduleapi :load_resource().
Diffstat (limited to 'core')
-rw-r--r--core/modulemanager.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index e23f1e55..ea5a1324 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -10,6 +10,7 @@ local logger = require "util.logger";
local log = logger.init("modulemanager");
local config = require "core.configmanager";
local pluginloader = require "util.pluginloader";
+local envload = require "util.envload";
local set = require "util.set";
local new_multitable = require "util.multitable".new;
@@ -22,6 +23,7 @@ local xpcall = require "util.xpcall".xpcall;
local debug_traceback = debug.traceback;
local setmetatable, rawget = setmetatable, rawget;
local ipairs, pairs, type, t_insert = ipairs, pairs, type, table.insert;
+local lua_version = _VERSION:match("5%.%d$");
local autoload_modules = {
prosody.platform,
@@ -196,6 +198,35 @@ local function do_load_module(host, module_name, state)
api_instance.path = err;
+ local custom_plugins = prosody.paths.installer;
+ if err:sub(1, #custom_plugins+1) == custom_plugins.."/" then
+ -- Stage 1: Make it work (you are here)
+ -- Stage 2: Make it less hacky (TODO)
+ local manifest = {};
+ local luarocks_path = custom_plugins.."/lib/luarocks/rocks-"..lua_version;
+ local manifest_filename = luarocks_path.."/manifest";
+ local load_manifest, err = envload.envloadfile(manifest_filename, manifest);
+ if not load_manifest then
+ log("error", "Could not load manifest of installed plugins: %s", err, load_manifest);
+ else
+ local ok, err = xpcall(load_manifest, debug_traceback);
+ if not ok then
+ log("error", "Could not load manifest of installed plugins: %s", err);
+ elseif type(manifest.modules) ~= "table" then
+ log("debug", "Expected 'table' but manifest.modules = %q", manifest.modules);
+ log("error", "Can't look up resource path for mod_%s because '%s' does not appear to be a LuaRocks manifest", module_name, manifest_filename);
+ else
+ local versions = manifest.modules["mod_"..module_name];
+ if type(versions) == "table" and versions[1] then
+ -- Not going to deal with multiple installed versions
+ api_instance.resource_path = luarocks_path.."/"..versions[1];
+ else
+ log("debug", "mod_%s does not appear in the installation manifest", module_name);
+ end
+ end
+ end
+ end
+
modulemap[host][module_name] = pluginenv;
local ok, err = xpcall(mod, debug_traceback);
if ok then