From 544a0963689fe14fc3cdb0fb6fa1dcb8b2f63bda Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 24 Sep 2012 18:24:56 -0300 Subject: Show module filenames in 'luarocks show'. --- src/luarocks/loader.lua | 20 ++------------------ src/luarocks/path.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ src/luarocks/show.lua | 20 +++++++++++++++++--- 3 files changed, 62 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 139bcb8b..a116766c 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -184,25 +184,9 @@ end --- Return the pathname of the file that would be loaded for a module. -- @param module string: module name (eg. "socket.core") --- @return string, string, string: name of the rock containing the module --- (eg. "luasocket"), version of the rock (eg. "2.0.2-1"), --- filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") +-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") function which(module) - local name, version, module_name = - select_module(module, function(module_name, name, version, tree, i) - local deploy_dir - if module_name:match("%.lua$") then - deploy_dir = path.deploy_lua_dir(tree) - module_name = deploy_dir.."/"..module_name - else - deploy_dir = path.deploy_lib_dir(tree) - module_name = deploy_dir.."/"..module_name - end - if i > 1 then - module_name = path.versioned_name(module_name, deploy_dir, name, version) - end - return module_name - end) + local name, version, module_name = select_module(module, path.which_i) return module_name end diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 1c94b639..bbd928a0 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -305,6 +305,49 @@ function use_tree(tree) cfg.deploy_lib_dir = deploy_lib_dir(tree) end +--- Return the pathname of the file that would be loaded for a module, indexed. +-- @param module_name string: module name (eg. "socket.core") +-- @param name string: name of the package (eg. "luasocket") +-- @param version string: version number (eg. "2.0.2-1") +-- @param tree string: repository path (eg. "/usr/local") +-- @param i number: the index, 1 if version is the current default, > 1 otherwise. +-- This is done this way for use by select_module in luarocks.loader. +-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") +function which_i(module_name, name, version, tree, i) + local deploy_dir + if module_name:match("%.lua$") then + deploy_dir = deploy_lua_dir(tree) + module_name = dir.path(deploy_dir, module_name) + else + deploy_dir = deploy_lib_dir(tree) + module_name = dir.path(deploy_dir, module_name) + end + if i > 1 then + module_name = versioned_name(module_name, deploy_dir, name, version) + end + return module_name +end + +--- Return the pathname of the file that would be loaded for a module, +-- returning the versioned pathname if given version is not the default version +-- in the given manifest. +-- @param module_name string: module name (eg. "socket.core") +-- @param name string: name of the package (eg. "luasocket") +-- @param version string: version number (eg. "2.0.2-1") +-- @param tree string: repository path (eg. "/usr/local") +-- @param manifest table: the manifest table for the tree. +-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") +function which(module_name, filename, name, version, tree, manifest) + local versions = manifest.modules[module_name] + assert(versions) + for i, name_version in ipairs(versions) do + if name_version == name.."/"..version then + return which_i(filename, name, version, tree, i):gsub("//", "/") + end + end + assert(false) +end + --- Driver function for "path" command. -- @return boolean This function always succeeds. function run(...) diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 5a052b58..68c1a738 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -55,6 +55,17 @@ local function format_text(text) return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) end +local function module_name(mod, filename, name, version, repo, manifest) + local base_dir + if filename:match("%.lua$") then + base_dir = path.deploy_lua_dir(repo) + else + base_dir = path.deploy_lib_dir(repo) + end + + return dir.path(base_dir, filename) +end + --- Driver function for "show" command. -- @param name or nil: an existing package name. -- @param version string or nil: a version may also be passed. @@ -75,10 +86,11 @@ function run(...) end if not next(results) then -- - return nil,"cannot find package "..name.."\nUse 'list' to find installed rocks" + return nil,"cannot find package "..name.." "..version.."\nUse 'list' to find installed rocks." end - local version,repo_url + version = nil + local repo_url local package, versions = util.sortedpairs(results)() --question: what do we do about multiple versions? This should --give us the latest version on the last repo (which is usually the global one) @@ -124,7 +136,9 @@ function run(...) if next(minfo.modules) then util.printout() util.printout("Modules:") - util.printout("\t"..keys_as_string(minfo.modules, "\n\t")) + for mod, filename in util.sortedpairs(minfo.modules) do + util.printout("\t"..mod.." ("..path.which(mod, filename, name, version, repo, manifest)..")") + end end if next(minfo.dependencies) then util.printout() -- cgit v1.2.3-55-g6feb