diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2016-11-13 16:01:17 -0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-13 16:01:17 -0200 |
| commit | 9f4fa981c5defaaf7b82b629ff68f1e3ec58650f (patch) | |
| tree | 35f0bb1d1e4df0b5780f16e84cadc943f5eec15d | |
| parent | 5e5d324e19135b1de0d3014ea203b910abc22853 (diff) | |
| parent | 47530921d71ef34fcd29a631584ca38af0df99d7 (diff) | |
| download | luarocks-9f4fa981c5defaaf7b82b629ff68f1e3ec58650f.tar.gz luarocks-9f4fa981c5defaaf7b82b629ff68f1e3ec58650f.tar.bz2 luarocks-9f4fa981c5defaaf7b82b629ff68f1e3ec58650f.zip | |
Merge pull request #652 from mpeterv/fix-which
`luarocks show `improvements: fix module paths, add command listing
| -rw-r--r-- | src/luarocks/cmd/show.lua | 21 | ||||
| -rw-r--r-- | src/luarocks/path.lua | 21 | ||||
| -rw-r--r-- | src/luarocks/repos.lua | 27 |
3 files changed, 42 insertions, 27 deletions
diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index 1ff81e08..ad48b153 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua | |||
| @@ -9,6 +9,7 @@ local path = require("luarocks.path") | |||
| 9 | local deps = require("luarocks.deps") | 9 | local deps = require("luarocks.deps") |
| 10 | local fetch = require("luarocks.fetch") | 10 | local fetch = require("luarocks.fetch") |
| 11 | local manif = require("luarocks.manif") | 11 | local manif = require("luarocks.manif") |
| 12 | local repos = require("luarocks.repos") | ||
| 12 | 13 | ||
| 13 | show.help_summary = "Show information about an installed rock." | 14 | show.help_summary = "Show information about an installed rock." |
| 14 | 15 | ||
| @@ -66,6 +67,12 @@ local function installed_rock_label(name, tree) | |||
| 66 | return installed and "(using "..version..")" or "(missing)" | 67 | return installed and "(using "..version..")" or "(missing)" |
| 67 | end | 68 | end |
| 68 | 69 | ||
| 70 | local function print_items(name, version, item_set, item_type, repo) | ||
| 71 | for item_name in util.sortedpairs(item_set) do | ||
| 72 | util.printout("\t"..item_name.." ("..repos.which(name, version, item_type, item_name, repo)..")") | ||
| 73 | end | ||
| 74 | end | ||
| 75 | |||
| 69 | --- Driver function for "show" command. | 76 | --- Driver function for "show" command. |
| 70 | -- @param name or nil: an existing package name. | 77 | -- @param name or nil: an existing package name. |
| 71 | -- @param version string or nil: a version may also be passed. | 78 | -- @param version string or nil: a version may also be passed. |
| @@ -121,13 +128,19 @@ function show.command(flags, name, version) | |||
| 121 | util.printout("Labels: ", table.concat(descript.labels, ", ")) | 128 | util.printout("Labels: ", table.concat(descript.labels, ", ")) |
| 122 | end | 129 | end |
| 123 | util.printout("Installed in: ", path.rocks_tree_to_string(repo)) | 130 | util.printout("Installed in: ", path.rocks_tree_to_string(repo)) |
| 131 | |||
| 132 | if next(minfo.commands) then | ||
| 133 | util.printout() | ||
| 134 | util.printout("Commands: ") | ||
| 135 | print_items(name, version, minfo.commands, "command", repo) | ||
| 136 | end | ||
| 137 | |||
| 124 | if next(minfo.modules) then | 138 | if next(minfo.modules) then |
| 125 | util.printout() | 139 | util.printout() |
| 126 | util.printout("Modules:") | 140 | util.printout("Modules: ") |
| 127 | for mod, filename in util.sortedpairs(minfo.modules) do | 141 | print_items(name, version, minfo.modules, "module", repo) |
| 128 | util.printout("\t"..mod.." ("..path.which(mod, filename, name, version, repo, manifest)..")") | ||
| 129 | end | ||
| 130 | end | 142 | end |
| 143 | |||
| 131 | local direct_deps = {} | 144 | local direct_deps = {} |
| 132 | if #rockspec.dependencies > 0 then | 145 | if #rockspec.dependencies > 0 then |
| 133 | util.printout() | 146 | util.printout() |
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 83e9c295..71893cf1 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
| @@ -231,25 +231,4 @@ function path.use_tree(tree) | |||
| 231 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | 231 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) |
| 232 | end | 232 | end |
| 233 | 233 | ||
| 234 | --- Return the pathname of the file that would be loaded for a module, | ||
| 235 | -- returning the versioned pathname if given version is not the default version | ||
| 236 | -- in the given manifest. | ||
| 237 | -- @param module_name string: module name (eg. "socket.core") | ||
| 238 | -- @param file_name string: module file name as in manifest (eg. "socket/core.so") | ||
| 239 | -- @param name string: name of the package (eg. "luasocket") | ||
| 240 | -- @param version string: version number (eg. "2.0.2-1") | ||
| 241 | -- @param tree string: repository path (eg. "/usr/local") | ||
| 242 | -- @param manifest table: the manifest table for the tree. | ||
| 243 | -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") | ||
| 244 | function path.which(module_name, file_name, name, version, tree, manifest) | ||
| 245 | local versions = manifest.modules[module_name] | ||
| 246 | assert(versions) | ||
| 247 | for i, name_version in ipairs(versions) do | ||
| 248 | if name_version == name.."/"..version then | ||
| 249 | return path.which_i(file_name, name, version, tree, i):gsub("//", "/") | ||
| 250 | end | ||
| 251 | end | ||
| 252 | assert(false) | ||
| 253 | end | ||
| 254 | |||
| 255 | return path | 234 | return path |
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 7c3251b9..5d5dedd6 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
| @@ -231,8 +231,9 @@ end | |||
| 231 | -- item from the newest version of lexicographically smallest package | 231 | -- item from the newest version of lexicographically smallest package |
| 232 | -- is deployed using non-versioned name and others use versioned names. | 232 | -- is deployed using non-versioned name and others use versioned names. |
| 233 | 233 | ||
| 234 | local function get_deploy_paths(name, version, deploy_type, file_path) | 234 | local function get_deploy_paths(name, version, deploy_type, file_path, repo) |
| 235 | local deploy_dir = cfg["deploy_" .. deploy_type .. "_dir"] | 235 | repo = repo or cfg.root_dir |
| 236 | local deploy_dir = path["deploy_" .. deploy_type .. "_dir"](repo) | ||
| 236 | local non_versioned = dir.path(deploy_dir, file_path) | 237 | local non_versioned = dir.path(deploy_dir, file_path) |
| 237 | local versioned = path.versioned_name(non_versioned, deploy_dir, name, version) | 238 | local versioned = path.versioned_name(non_versioned, deploy_dir, name, version) |
| 238 | return non_versioned, versioned | 239 | return non_versioned, versioned |
| @@ -423,4 +424,26 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
| 423 | return writer.remove_from_manifest(name, version, nil, deps_mode) | 424 | return writer.remove_from_manifest(name, version, nil, deps_mode) |
| 424 | end | 425 | end |
| 425 | 426 | ||
| 427 | --- Find full path to a file providing a module or a command | ||
| 428 | -- in a package. | ||
| 429 | -- @param name string: name of package. | ||
| 430 | -- @param version string: exact package version in string format. | ||
| 431 | -- @param item_type string: "module" or "command". | ||
| 432 | -- @param item_name string: module or command name. | ||
| 433 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. | ||
| 434 | -- @return string: absolute path to the file providing given module | ||
| 435 | -- or command. | ||
| 436 | function repos.which(name, version, item_type, item_name, repo) | ||
| 437 | local deploy_type, file_path = manif.get_providing_file(name, version, item_type, item_name, repo) | ||
| 438 | local non_versioned, versioned = get_deploy_paths(name, version, deploy_type, file_path, repo) | ||
| 439 | local cur_name, cur_version = manif.get_current_provider(item_type, item_name) | ||
| 440 | local deploy_path = (name == cur_name and version == cur_version) and non_versioned or versioned | ||
| 441 | |||
| 442 | if deploy_type == "bin" and cfg.wrapper_suffix and cfg.wrapper_suffix ~= "" then | ||
| 443 | deploy_path = find_suffixed(deploy_path, cfg.wrapper_suffix) or deploy_path | ||
| 444 | end | ||
| 445 | |||
| 446 | return deploy_path | ||
| 447 | end | ||
| 448 | |||
| 426 | return repos | 449 | return repos |
