From d09f92a84d0a9267a066af2d6978f9a51e555f5f Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 31 Aug 2018 15:48:47 +0200 Subject: show: base listing of modules on rock_manifest List modules based on rock_manifest, for better precision. Overall management of modules should be moved to use rock_manifest instead of the modules list from the general local manifest, but this is a good first step. --- src/luarocks/cmd/show.lua | 34 ++++++++++++++++++++++++++++------ src/luarocks/queries.lua | 5 +++-- src/luarocks/repos.lua | 34 ++++++++++++++++------------------ 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index b6242cbc..c90a6bea 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua @@ -4,6 +4,7 @@ local show = {} local queries = require("luarocks.queries") local search = require("luarocks.search") +local dir = require("luarocks.core.dir") local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") local path = require("luarocks.path") @@ -44,10 +45,10 @@ local friendly_template = [[ ?location :Installed in: \t${location} ?commands : ?commands :Commands: -*commands :\t${name} (${repo}) +*commands :\t${name} (${file}) ?modules : ?modules :Modules: -*modules :\t${name} (${repo}) +*modules :\t${name} (${file}) ?bdeps : ?bdeps :Has build dependency on: *bdeps :\t${name} (${label}) @@ -74,8 +75,8 @@ local porcelain_template = [[ ?issues :issues\t${issues} ?labels :labels\t${labels} ?location :location\t${location} -*commands :command\t${name}\t${repo} -*modules :module\t${name}\t${repo} +*commands :command\t${name}\t${file} +*modules :module\t${name}\t${file} *bdeps :build_dependency\t${name}\t${label} *tdeps :test_dependency\t${name}\t${label} *deps :dependency\t${name}\t${label} @@ -147,11 +148,32 @@ end local function files_to_list(name, version, item_set, item_type, repo) local ret = {} for item_name in util.sortedpairs(item_set) do - table.insert(ret, { name = item_name, repo = repos.which(name, version, item_type, item_name, repo) }) + table.insert(ret, { name = item_name, file = repos.which(name, version, item_type, item_name, repo) }) end return ret end +local function modules_to_list(name, version, repo) + local ret = {} + local rock_manifest = manif.load_rock_manifest(name, version, repo) + + local lua_dir = path.lua_dir(name, version, repo) + local lib_dir = path.lib_dir(name, version, repo) + repos.recurse_rock_manifest_entry(rock_manifest.lua, function(pathname, modname) + table.insert(ret, { name = modname, file = dir.path(lua_dir, pathname) }) + end) + repos.recurse_rock_manifest_entry(rock_manifest.lib, function(pathname, modname) + table.insert(ret, { name = modname, file = dir.path(lib_dir, pathname) }) + end) + table.sort(ret, function(a, b) + if a.name == b.name then + return a.file < b.file + end + return a.name < b.name + end) + return ret +end + local function deps_to_list(dependencies, tree) local ret = {} for _, dep in ipairs(dependencies or {}) do @@ -188,7 +210,7 @@ local function show_rock(template, namespace, name, version, rockspec, repo, min labels = desc.labels and table.concat(desc.labels, ", "), location = path.rocks_tree_to_string(repo), commands = files_to_list(name, version, minfo.commands, "command", repo), - modules = files_to_list(name, version, minfo.modules, "module", repo), + modules = modules_to_list(name, version, repo), bdeps = deps_to_list(rockspec.build_dependencies, tree), tdeps = deps_to_list(rockspec.test_dependencies, tree), deps = deps_to_list(rockspec.dependencies, tree), diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua index 92d76460..15dc5fac 100644 --- a/src/luarocks/queries.lua +++ b/src/luarocks/queries.lua @@ -198,10 +198,11 @@ function query_mt:__tostring() if #self.constraints > 0 then local pretty = {} for _, c in ipairs(self.constraints) do + local v = c.version.string if c.op == "==" then - table.insert(pretty, tostring(c.version)) + table.insert(pretty, v) else - table.insert(pretty, c.op .. " " .. tostring(c.version)) + table.insert(pretty, c.op .. " " .. v) end end table.insert(out, " ") diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index dd2a5142..37a81c20 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -51,31 +51,37 @@ function repos.is_installed(name, version) return fs.is_dir(path.install_dir(name, version)) end -local function recurse_rock_manifest_tree(file_tree, action) - assert(type(file_tree) == "table") +function repos.recurse_rock_manifest_entry(entry, action) + assert(entry == nil or type(entry) == "table") assert(type(action) == "function") - local function do_recurse_rock_manifest_tree(tree, parent_path) + if entry == nil then + return true + end + + local function do_recurse_rock_manifest_tree(tree, parent_path, parent_mod) for file, sub in pairs(tree) do local sub_path = (parent_path and (parent_path .. "/") or "") .. file + local sub_mod = (parent_mod and (parent_mod .. ".") or "") .. file local ok, err if type(sub) == "table" then - ok, err = do_recurse_rock_manifest_tree(sub, sub_path) + ok, err = do_recurse_rock_manifest_tree(sub, sub_path, sub_mod) else - ok, err = action(sub_path) + local mod_no_ext = sub_mod:gsub("%.[^.]*$", "") + ok, err = action(sub_path, mod_no_ext) end - if not ok then return nil, err end + if err then return nil, err end end return true end - return do_recurse_rock_manifest_tree(file_tree) + return do_recurse_rock_manifest_tree(entry) end local function store_package_data(result, rock_manifest, deploy_type) if rock_manifest[deploy_type] then - recurse_rock_manifest_tree(rock_manifest[deploy_type], function(file_path) + repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path) local _, item_name = manif.get_provided_item(deploy_type, file_path) result[item_name] = file_path return true @@ -280,11 +286,7 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) if not rock_manifest then return nil, load_err end local function deploy_file_tree(deploy_type, source_dir, move_fn, suffix) - if not rock_manifest[deploy_type] then - return true - end - - return recurse_rock_manifest_tree(rock_manifest[deploy_type], function(file_path) + return repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path) local source = dir.path(source_dir, file_path) local target, prepare_err = prepare_target(name, version, deploy_type, file_path, suffix) @@ -363,11 +365,7 @@ function repos.delete_version(name, version, deps_mode, quick) if not rock_manifest then return nil, load_err end local function delete_deployed_file_tree(deploy_type, suffix) - if not rock_manifest[deploy_type] then - return true - end - - return recurse_rock_manifest_tree(rock_manifest[deploy_type], function(file_path) + return repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path) local non_versioned, versioned = get_deploy_paths(name, version, deploy_type, file_path) -- Figure out if the file is deployed using versioned or non-versioned name. -- cgit v1.2.3-55-g6feb