Comparison

core/modulemanager.lua @ 11145:be73df6765b9

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().
author Kim Alvefur <zash@zash.se>
date Wed, 07 Oct 2020 15:51:37 +0200
parent 10530:67d56dacc79c
child 11147:82d6c8e627b9
comparison
equal deleted inserted replaced
11144:2b9f7c537acb 11145:be73df6765b9
8 8
9 local logger = require "util.logger"; 9 local logger = require "util.logger";
10 local log = logger.init("modulemanager"); 10 local log = logger.init("modulemanager");
11 local config = require "core.configmanager"; 11 local config = require "core.configmanager";
12 local pluginloader = require "util.pluginloader"; 12 local pluginloader = require "util.pluginloader";
13 local envload = require "util.envload";
13 local set = require "util.set"; 14 local set = require "util.set";
14 15
15 local new_multitable = require "util.multitable".new; 16 local new_multitable = require "util.multitable".new;
16 local api = require "core.moduleapi"; -- Module API container 17 local api = require "core.moduleapi"; -- Module API container
17 18
20 21
21 local xpcall = require "util.xpcall".xpcall; 22 local xpcall = require "util.xpcall".xpcall;
22 local debug_traceback = debug.traceback; 23 local debug_traceback = debug.traceback;
23 local setmetatable, rawget = setmetatable, rawget; 24 local setmetatable, rawget = setmetatable, rawget;
24 local ipairs, pairs, type, t_insert = ipairs, pairs, type, table.insert; 25 local ipairs, pairs, type, t_insert = ipairs, pairs, type, table.insert;
26 local lua_version = _VERSION:match("5%.%d$");
25 27
26 local autoload_modules = { 28 local autoload_modules = {
27 prosody.platform, 29 prosody.platform,
28 "presence", 30 "presence",
29 "message", 31 "message",
194 return nil, err; 196 return nil, err;
195 end 197 end
196 198
197 api_instance.path = err; 199 api_instance.path = err;
198 200
201 local custom_plugins = prosody.paths.installer;
202 if err:sub(1, #custom_plugins+1) == custom_plugins.."/" then
203 -- Stage 1: Make it work (you are here)
204 -- Stage 2: Make it less hacky (TODO)
205 local manifest = {};
206 local luarocks_path = custom_plugins.."/lib/luarocks/rocks-"..lua_version;
207 local manifest_filename = luarocks_path.."/manifest";
208 local load_manifest, err = envload.envloadfile(manifest_filename, manifest);
209 if not load_manifest then
210 log("error", "Could not load manifest of installed plugins: %s", err, load_manifest);
211 else
212 local ok, err = xpcall(load_manifest, debug_traceback);
213 if not ok then
214 log("error", "Could not load manifest of installed plugins: %s", err);
215 elseif type(manifest.modules) ~= "table" then
216 log("debug", "Expected 'table' but manifest.modules = %q", manifest.modules);
217 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);
218 else
219 local versions = manifest.modules["mod_"..module_name];
220 if type(versions) == "table" and versions[1] then
221 -- Not going to deal with multiple installed versions
222 api_instance.resource_path = luarocks_path.."/"..versions[1];
223 else
224 log("debug", "mod_%s does not appear in the installation manifest", module_name);
225 end
226 end
227 end
228 end
229
199 modulemap[host][module_name] = pluginenv; 230 modulemap[host][module_name] = pluginenv;
200 local ok, err = xpcall(mod, debug_traceback); 231 local ok, err = xpcall(mod, debug_traceback);
201 if ok then 232 if ok then
202 -- Call module's "load" 233 -- Call module's "load"
203 if module_has_method(pluginenv, "load") then 234 if module_has_method(pluginenv, "load") then