diff options
author | Hisham <hisham@gobolinux.org> | 2016-09-08 11:28:52 -0300 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-09-08 11:28:52 -0300 |
commit | c53a3c84000cfeaa5749abe3a5917b55f74c21de (patch) | |
tree | e4ef553b88ce0a9b40807271a4225774eb1f5bc5 | |
parent | 311d2ea373d01a71ad12d31bc250d8e6f6f6c3f8 (diff) | |
download | luarocks-c53a3c84000cfeaa5749abe3a5917b55f74c21de.tar.gz luarocks-c53a3c84000cfeaa5749abe3a5917b55f74c21de.tar.bz2 luarocks-c53a3c84000cfeaa5749abe3a5917b55f74c21de.zip |
Make `pack` use the same logic as `show` for finding a rock.
-rw-r--r-- | src/luarocks/doc.lua | 4 | ||||
-rw-r--r-- | src/luarocks/pack.lua | 36 | ||||
-rw-r--r-- | src/luarocks/search.lua | 33 | ||||
-rw-r--r-- | src/luarocks/show.lua | 37 |
4 files changed, 46 insertions, 64 deletions
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index ec2b1110..15460b31 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua | |||
@@ -5,7 +5,7 @@ local doc = {} | |||
5 | package.loaded["luarocks.doc"] = doc | 5 | package.loaded["luarocks.doc"] = doc |
6 | 6 | ||
7 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
8 | local show = require("luarocks.show") | 8 | local search = require("luarocks.search") |
9 | local path = require("luarocks.path") | 9 | local path = require("luarocks.path") |
10 | local dir = require("luarocks.dir") | 10 | local dir = require("luarocks.dir") |
11 | local fetch = require("luarocks.fetch") | 11 | local fetch = require("luarocks.fetch") |
@@ -63,7 +63,7 @@ function doc.command(flags, name, version) | |||
63 | return nil, "Argument missing. "..util.see_help("doc") | 63 | return nil, "Argument missing. "..util.see_help("doc") |
64 | end | 64 | end |
65 | 65 | ||
66 | local iname, iversion, repo = show.pick_installed_rock(name, version, flags["tree"]) | 66 | local iname, iversion, repo = search.pick_installed_rock(name, version, flags["tree"]) |
67 | if not iname then | 67 | if not iname then |
68 | util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...") | 68 | util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...") |
69 | return try_to_open_homepage(name, version) | 69 | return try_to_open_homepage(name, version) |
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 277cf246..fb40a576 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua | |||
@@ -85,38 +85,20 @@ end | |||
85 | 85 | ||
86 | -- @param name string: Name of package to pack. | 86 | -- @param name string: Name of package to pack. |
87 | -- @param version string or nil: A version number may also be passed. | 87 | -- @param version string or nil: A version number may also be passed. |
88 | -- @param tree string or nil: An optional tree to pick the package from. | ||
88 | -- @return string or (nil, string): The filename of the resulting | 89 | -- @return string or (nil, string): The filename of the resulting |
89 | -- .src.rock file; or nil and an error message. | 90 | -- .src.rock file; or nil and an error message. |
90 | local function do_pack_binary_rock(name, version) | 91 | local function do_pack_binary_rock(name, version, tree) |
91 | assert(type(name) == "string") | 92 | assert(type(name) == "string") |
92 | assert(type(version) == "string" or not version) | 93 | assert(type(version) == "string" or not version) |
93 | 94 | ||
94 | local query = search.make_query(name, version) | 95 | local repo, repo_url |
95 | query.exact_name = true | 96 | name, version, repo, repo_url = search.pick_installed_rock(name, version, tree) |
96 | local results = {} | 97 | if not name then |
97 | 98 | return nil, version | |
98 | search.manifest_search(results, cfg.rocks_dir, query) | ||
99 | |||
100 | if not next(results) then | ||
101 | return nil, "'"..name.."' does not seem to be an installed rock." | ||
102 | end | ||
103 | |||
104 | local versions = results[name] | ||
105 | |||
106 | if not version then | ||
107 | local first = next(versions) | ||
108 | if next(versions, first) then | ||
109 | return nil, "Please specify which version of '"..name.."' to pack." | ||
110 | end | ||
111 | version = first | ||
112 | end | ||
113 | if not version:match("[^-]+%-%d+") then | ||
114 | return nil, "Expected version "..version.." in version-revision format." | ||
115 | end | 99 | end |
116 | 100 | ||
117 | local info = versions[version][1] | 101 | local root = path.root_dir(repo_url) |
118 | |||
119 | local root = path.root_dir(info.repo) | ||
120 | local prefix = path.install_dir(name, version, root) | 102 | local prefix = path.install_dir(name, version, root) |
121 | if not fs.exists(prefix) then | 103 | if not fs.exists(prefix) then |
122 | return nil, "'"..name.." "..version.."' does not seem to be an installed rock." | 104 | return nil, "'"..name.." "..version.."' does not seem to be an installed rock." |
@@ -202,7 +184,7 @@ function pack.command(flags, arg, version) | |||
202 | if arg:match(".*%.rockspec") then | 184 | if arg:match(".*%.rockspec") then |
203 | file, err = pack.pack_source_rock(arg) | 185 | file, err = pack.pack_source_rock(arg) |
204 | else | 186 | else |
205 | file, err = do_pack_binary_rock(arg, version) | 187 | file, err = do_pack_binary_rock(arg, version, flags["tree"]) |
206 | end | 188 | end |
207 | if err then | 189 | if err then |
208 | return nil, err | 190 | return nil, err |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index eaa321d5..d22c2a18 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -416,6 +416,39 @@ function search.act_on_src_or_rockspec(action, name, version, ...) | |||
416 | return action(url, ...) | 416 | return action(url, ...) |
417 | end | 417 | end |
418 | 418 | ||
419 | function search.pick_installed_rock(name, version, given_tree) | ||
420 | local results = {} | ||
421 | local query = search.make_query(name, version) | ||
422 | query.exact_name = true | ||
423 | local tree_map = {} | ||
424 | local trees = cfg.rocks_trees | ||
425 | if given_tree then | ||
426 | trees = { given_tree } | ||
427 | end | ||
428 | for _, tree in ipairs(trees) do | ||
429 | local rocks_dir = path.rocks_dir(tree) | ||
430 | tree_map[rocks_dir] = tree | ||
431 | search.manifest_search(results, rocks_dir, query) | ||
432 | end | ||
433 | |||
434 | if not next(results) then -- | ||
435 | return nil,"cannot find package "..name.." "..(version or "").."\nUse 'list' to find installed rocks." | ||
436 | end | ||
437 | |||
438 | version = nil | ||
439 | local repo_url | ||
440 | local package, versions = util.sortedpairs(results)() | ||
441 | --question: what do we do about multiple versions? This should | ||
442 | --give us the latest version on the last repo (which is usually the global one) | ||
443 | for vs, repositories in util.sortedpairs(versions, deps.compare_versions) do | ||
444 | if not version then version = vs end | ||
445 | for _, rp in ipairs(repositories) do repo_url = rp.repo end | ||
446 | end | ||
447 | |||
448 | local repo = tree_map[repo_url] | ||
449 | return name, version, repo, repo_url | ||
450 | end | ||
451 | |||
419 | --- Driver function for "search" command. | 452 | --- Driver function for "search" command. |
420 | -- @param name string: A substring of a rock name to search. | 453 | -- @param name string: A substring of a rock name to search. |
421 | -- @param version string or nil: a version may also be passed. | 454 | -- @param version string or nil: a version may also be passed. |
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 01860e78..88f9512d 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua | |||
@@ -58,45 +58,12 @@ local function format_text(text) | |||
58 | return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) | 58 | return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) |
59 | end | 59 | end |
60 | 60 | ||
61 | function show.pick_installed_rock(name, version, tree) | ||
62 | local results = {} | ||
63 | local query = search.make_query(name, version) | ||
64 | query.exact_name = true | ||
65 | local tree_map = {} | ||
66 | local trees = cfg.rocks_trees | ||
67 | if tree then | ||
68 | trees = { tree } | ||
69 | end | ||
70 | for _, tree in ipairs(trees) do | ||
71 | local rocks_dir = path.rocks_dir(tree) | ||
72 | tree_map[rocks_dir] = tree | ||
73 | search.manifest_search(results, rocks_dir, query) | ||
74 | end | ||
75 | |||
76 | if not next(results) then -- | ||
77 | return nil,"cannot find package "..name.." "..(version or "").."\nUse 'list' to find installed rocks." | ||
78 | end | ||
79 | |||
80 | version = nil | ||
81 | local repo_url | ||
82 | local package, versions = util.sortedpairs(results)() | ||
83 | --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) | ||
85 | for vs, repositories in util.sortedpairs(versions, deps.compare_versions) do | ||
86 | if not version then version = vs end | ||
87 | for _, rp in ipairs(repositories) do repo_url = rp.repo end | ||
88 | end | ||
89 | |||
90 | local repo = tree_map[repo_url] | ||
91 | return name, version, repo, repo_url | ||
92 | end | ||
93 | |||
94 | local function installed_rock_label(name, tree) | 61 | local function installed_rock_label(name, tree) |
95 | local installed, version | 62 | local installed, version |
96 | if cfg.rocks_provided[name] then | 63 | if cfg.rocks_provided[name] then |
97 | installed, version = true, cfg.rocks_provided[name] | 64 | installed, version = true, cfg.rocks_provided[name] |
98 | else | 65 | else |
99 | installed, version = show.pick_installed_rock(name, nil, tree) | 66 | installed, version = search.pick_installed_rock(name, nil, tree) |
100 | end | 67 | end |
101 | return installed and "(using "..version..")" or "(missing)" | 68 | return installed and "(using "..version..")" or "(missing)" |
102 | end | 69 | end |
@@ -111,7 +78,7 @@ function show.command(flags, name, version) | |||
111 | end | 78 | end |
112 | 79 | ||
113 | local repo, repo_url | 80 | local repo, repo_url |
114 | name, version, repo, repo_url = show.pick_installed_rock(name, version, flags["tree"]) | 81 | name, version, repo, repo_url = search.pick_installed_rock(name, version, flags["tree"]) |
115 | if not name then | 82 | if not name then |
116 | return nil, version | 83 | return nil, version |
117 | end | 84 | end |