aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2012-09-24 18:24:56 -0300
committerHisham Muhammad <hisham@gobolinux.org>2012-09-24 18:24:56 -0300
commit544a0963689fe14fc3cdb0fb6fa1dcb8b2f63bda (patch)
tree6fb71b13e9804781976aa27a5e19f060d2b77cc3 /src
parentb20c561b8fcfcf4cecfd8fbb40ea7857193a4f8c (diff)
downloadluarocks-544a0963689fe14fc3cdb0fb6fa1dcb8b2f63bda.tar.gz
luarocks-544a0963689fe14fc3cdb0fb6fa1dcb8b2f63bda.tar.bz2
luarocks-544a0963689fe14fc3cdb0fb6fa1dcb8b2f63bda.zip
Show module filenames in 'luarocks show'.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/loader.lua20
-rw-r--r--src/luarocks/path.lua43
-rw-r--r--src/luarocks/show.lua20
3 files changed, 62 insertions, 21 deletions
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
184 184
185--- Return the pathname of the file that would be loaded for a module. 185--- Return the pathname of the file that would be loaded for a module.
186-- @param module string: module name (eg. "socket.core") 186-- @param module string: module name (eg. "socket.core")
187-- @return string, string, string: name of the rock containing the module 187-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
188-- (eg. "luasocket"), version of the rock (eg. "2.0.2-1"),
189-- filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
190function which(module) 188function which(module)
191 local name, version, module_name = 189 local name, version, module_name = select_module(module, path.which_i)
192 select_module(module, function(module_name, name, version, tree, i)
193 local deploy_dir
194 if module_name:match("%.lua$") then
195 deploy_dir = path.deploy_lua_dir(tree)
196 module_name = deploy_dir.."/"..module_name
197 else
198 deploy_dir = path.deploy_lib_dir(tree)
199 module_name = deploy_dir.."/"..module_name
200 end
201 if i > 1 then
202 module_name = path.versioned_name(module_name, deploy_dir, name, version)
203 end
204 return module_name
205 end)
206 return module_name 190 return module_name
207end 191end
208 192
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)
305 cfg.deploy_lib_dir = deploy_lib_dir(tree) 305 cfg.deploy_lib_dir = deploy_lib_dir(tree)
306end 306end
307 307
308--- Return the pathname of the file that would be loaded for a module, indexed.
309-- @param module_name string: module name (eg. "socket.core")
310-- @param name string: name of the package (eg. "luasocket")
311-- @param version string: version number (eg. "2.0.2-1")
312-- @param tree string: repository path (eg. "/usr/local")
313-- @param i number: the index, 1 if version is the current default, > 1 otherwise.
314-- This is done this way for use by select_module in luarocks.loader.
315-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
316function which_i(module_name, name, version, tree, i)
317 local deploy_dir
318 if module_name:match("%.lua$") then
319 deploy_dir = deploy_lua_dir(tree)
320 module_name = dir.path(deploy_dir, module_name)
321 else
322 deploy_dir = deploy_lib_dir(tree)
323 module_name = dir.path(deploy_dir, module_name)
324 end
325 if i > 1 then
326 module_name = versioned_name(module_name, deploy_dir, name, version)
327 end
328 return module_name
329end
330
331--- Return the pathname of the file that would be loaded for a module,
332-- returning the versioned pathname if given version is not the default version
333-- in the given manifest.
334-- @param module_name string: module name (eg. "socket.core")
335-- @param name string: name of the package (eg. "luasocket")
336-- @param version string: version number (eg. "2.0.2-1")
337-- @param tree string: repository path (eg. "/usr/local")
338-- @param manifest table: the manifest table for the tree.
339-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
340function which(module_name, filename, name, version, tree, manifest)
341 local versions = manifest.modules[module_name]
342 assert(versions)
343 for i, name_version in ipairs(versions) do
344 if name_version == name.."/"..version then
345 return which_i(filename, name, version, tree, i):gsub("//", "/")
346 end
347 end
348 assert(false)
349end
350
308--- Driver function for "path" command. 351--- Driver function for "path" command.
309-- @return boolean This function always succeeds. 352-- @return boolean This function always succeeds.
310function run(...) 353function 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)
55 return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) 55 return (table.concat(paragraphs, "\n\n"):gsub("%s$", ""))
56end 56end
57 57
58local function module_name(mod, filename, name, version, repo, manifest)
59 local base_dir
60 if filename:match("%.lua$") then
61 base_dir = path.deploy_lua_dir(repo)
62 else
63 base_dir = path.deploy_lib_dir(repo)
64 end
65
66 return dir.path(base_dir, filename)
67end
68
58--- Driver function for "show" command. 69--- Driver function for "show" command.
59-- @param name or nil: an existing package name. 70-- @param name or nil: an existing package name.
60-- @param version string or nil: a version may also be passed. 71-- @param version string or nil: a version may also be passed.
@@ -75,10 +86,11 @@ function run(...)
75 end 86 end
76 87
77 if not next(results) then -- 88 if not next(results) then --
78 return nil,"cannot find package "..name.."\nUse 'list' to find installed rocks" 89 return nil,"cannot find package "..name.." "..version.."\nUse 'list' to find installed rocks."
79 end 90 end
80 91
81 local version,repo_url 92 version = nil
93 local repo_url
82 local package, versions = util.sortedpairs(results)() 94 local package, versions = util.sortedpairs(results)()
83 --question: what do we do about multiple versions? This should 95 --question: what do we do about multiple versions? This should
84 --give us the latest version on the last repo (which is usually the global one) 96 --give us the latest version on the last repo (which is usually the global one)
@@ -124,7 +136,9 @@ function run(...)
124 if next(minfo.modules) then 136 if next(minfo.modules) then
125 util.printout() 137 util.printout()
126 util.printout("Modules:") 138 util.printout("Modules:")
127 util.printout("\t"..keys_as_string(minfo.modules, "\n\t")) 139 for mod, filename in util.sortedpairs(minfo.modules) do
140 util.printout("\t"..mod.." ("..path.which(mod, filename, name, version, repo, manifest)..")")
141 end
128 end 142 end
129 if next(minfo.dependencies) then 143 if next(minfo.dependencies) then
130 util.printout() 144 util.printout()