Software /
code /
prosody
Changeset
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 |
parents | 11144:2b9f7c537acb |
children | 11146:87d6f5924ae9 |
files | core/modulemanager.lua |
diffstat | 1 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/modulemanager.lua Wed Oct 07 15:37:15 2020 +0200 +++ b/core/modulemanager.lua Wed Oct 07 15:51:37 2020 +0200 @@ -10,6 +10,7 @@ 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 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 @@ 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