aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2016-10-14 16:38:51 -0700
committerHisham <hisham@gobolinux.org>2016-10-14 16:38:51 -0700
commit075196e8b5d315888a8ae110fa9a18089044ae3b (patch)
treeeca3eb78c23f8d85dbe625564a2d66966d6281f1 /src
parentdbca97cdcc15e386554b2631a0ae7aca02500abf (diff)
parent1fea0e3a0972bcc6b4319cd3d9e79834562486bc (diff)
downloadluarocks-075196e8b5d315888a8ae110fa9a18089044ae3b.tar.gz
luarocks-075196e8b5d315888a8ae110fa9a18089044ae3b.tar.bz2
luarocks-075196e8b5d315888a8ae110fa9a18089044ae3b.zip
Merge branch 'master' into luarocks-3
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/core/cfg.lua8
-rw-r--r--src/luarocks/core/util.lua79
-rw-r--r--src/luarocks/doc.lua4
-rw-r--r--src/luarocks/loader.lua29
-rw-r--r--src/luarocks/pack.lua38
-rw-r--r--src/luarocks/search.lua33
-rw-r--r--src/luarocks/show.lua37
7 files changed, 123 insertions, 105 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 73bff097..b5c60ed1 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -6,10 +6,9 @@
6-- file format documentation</a> for details. 6-- file format documentation</a> for details.
7-- 7--
8-- End-users shouldn't edit this file. They can override any defaults 8-- End-users shouldn't edit this file. They can override any defaults
9-- set in this file using their system-wide $LUAROCKS_SYSCONFIG file 9-- set in this file using their system-wide or user-specific configuration
10-- (see luarocks.site_config) or their user-specific configuration file 10-- files. Run `luarocks` with no arguments to see the locations of
11-- (~/.luarocks/config.lua on Unix or %APPDATA%/luarocks/config.lua on 11-- these files in your platform.
12-- Windows).
13 12
14local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION = 13local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION =
15 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION 14 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION
@@ -477,6 +476,7 @@ if cfg.platforms.mingw32 then
477 defaults.variables.RANLIB = "ranlib" 476 defaults.variables.RANLIB = "ranlib"
478 defaults.variables.CFLAGS = "-O2" 477 defaults.variables.CFLAGS = "-O2"
479 defaults.variables.LIBFLAG = "-shared" 478 defaults.variables.LIBFLAG = "-shared"
479 defaults.makefile = "Makefile"
480 defaults.external_deps_patterns = { 480 defaults.external_deps_patterns = {
481 bin = { "?.exe", "?.bat" }, 481 bin = { "?.exe", "?.bat" },
482 -- mingw lookup list from http://stackoverflow.com/a/15853231/1793220 482 -- mingw lookup list from http://stackoverflow.com/a/15853231/1793220
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua
index f2e409d1..85b59af6 100644
--- a/src/luarocks/core/util.lua
+++ b/src/luarocks/core/util.lua
@@ -213,52 +213,59 @@ local function default_sort(a, b)
213 end 213 end
214end 214end
215 215
216--- The iterator function used internally by util.sortedpairs. 216--- A table iterator generator that returns elements sorted by key,
217-- to be used in "for" loops.
217-- @param tbl table: The table to be iterated. 218-- @param tbl table: The table to be iterated.
218-- @param sort_function function or nil: An optional comparison function 219-- @param sort_function function or table or nil: An optional comparison function
219-- to be used by table.sort when sorting keys. 220-- to be used by table.sort when sorting keys, or an array listing an explicit order
220-- @see sortedpairs 221-- for keys. If a value itself is an array, it is taken so that the first element
221local function sortedpairs_iterator(tbl, sort_function) 222-- is a string representing the field name, and the second element is a priority table
222 local ks = util.keys(tbl) 223-- for that key, which is returned by the iterator as the third value after the key
223 if not sort_function or type(sort_function) == "function" then 224-- and the value.
224 table.sort(ks, sort_function or default_sort) 225-- @return function: the iterator function.
225 for _, k in ipairs(ks) do 226function util.sortedpairs(tbl, sort_function)
226 coroutine.yield(k, tbl[k]) 227 sort_function = sort_function or default_sort
227 end 228 local keys = util.keys(tbl)
229 local sub_orders = {}
230
231 if type(sort_function) == "function" then
232 table.sort(keys, sort_function)
228 else 233 else
229 local order = sort_function 234 local order = sort_function
230 local done = {} 235 local ordered_keys = {}
231 for _, k in ipairs(order) do 236 local all_keys = keys
232 local sub_order 237 keys = {}
233 if type(k) == "table" then 238
234 sub_order = k[2] 239 for _, order_entry in ipairs(order) do
235 k = k[1] 240 local key, sub_order
241 if type(order_entry) == "table" then
242 key = order_entry[1]
243 sub_order = order_entry[2]
244 else
245 key = order_entry
236 end 246 end
237 if tbl[k] then 247
238 done[k] = true 248 if tbl[key] then
239 coroutine.yield(k, tbl[k], sub_order) 249 ordered_keys[key] = true
250 sub_orders[key] = sub_order
251 table.insert(keys, key)
240 end 252 end
241 end 253 end
242 table.sort(ks, default_sort) 254
243 for _, k in ipairs(ks) do 255 table.sort(all_keys, default_sort)
244 if not done[k] then 256 for _, key in ipairs(all_keys) do
245 coroutine.yield(k, tbl[k]) 257 if not ordered_keys[key] then
258 table.insert(keys, key)
246 end 259 end
247 end 260 end
248 end 261 end
249end
250 262
251--- A table iterator generator that returns elements sorted by key, 263 local i = 1
252-- to be used in "for" loops. 264 return function()
253-- @param tbl table: The table to be iterated. 265 local key = keys[i]
254-- @param sort_function function or table or nil: An optional comparison function 266 i = i + 1
255-- to be used by table.sort when sorting keys, or an array listing an explicit order 267 return key, tbl[key], sub_orders[key]
256-- for keys. If a value itself is an array, it is taken so that the first element 268 end
257-- is a string representing the field name, and the second element is a priority table
258-- for that key.
259-- @return function: the iterator function.
260function util.sortedpairs(tbl, sort_function)
261 return coroutine.wrap(function() sortedpairs_iterator(tbl, sort_function) end)
262end 269end
263 270
264return util 271return util
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua
index 8378bbc2..63c4c4e3 100644
--- a/src/luarocks/doc.lua
+++ b/src/luarocks/doc.lua
@@ -4,7 +4,7 @@
4local doc = {} 4local doc = {}
5 5
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local show = require("luarocks.show") 7local search = require("luarocks.search")
8local path = require("luarocks.path") 8local path = require("luarocks.path")
9local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
10local fetch = require("luarocks.fetch") 10local fetch = require("luarocks.fetch")
@@ -61,7 +61,7 @@ function doc.command(flags, name, version)
61 return nil, "Argument missing. "..util.see_help("doc") 61 return nil, "Argument missing. "..util.see_help("doc")
62 end 62 end
63 63
64 local iname, iversion, repo = show.pick_installed_rock(name, version, flags["tree"]) 64 local iname, iversion, repo = search.pick_installed_rock(name, version, flags["tree"])
65 if not iname then 65 if not iname then
66 util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...") 66 util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...")
67 return try_to_open_homepage(name, version) 67 return try_to_open_homepage(name, version)
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua
index 0faaebda..b8072110 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -25,6 +25,28 @@ local util = require("luarocks.core.util")
25local require = nil 25local require = nil
26-------------------------------------------------------------------------------- 26--------------------------------------------------------------------------------
27 27
28-- Workaround for wrappers produced by older versions of LuaRocks
29local temporary_global = false
30if luarocks then
31 -- The site_config.lua file generated by old versions uses module(),
32 -- so it produces a global `luarocks` table. Since we have the table,
33 -- add the `loader` field to make the old wrappers happy.
34 luarocks.loader = loader
35else
36 -- When a new version is installed on top of an old version,
37 -- site_config.lua may be replaced, and then it no longer creates
38 -- a global.
39 -- Detect when being called via -lluarocks.loader; this is
40 -- most likely a wrapper.
41 local info = debug.getinfo(2, "nS")
42 if info.what == "C" and not info.name then
43 luarocks = { loader = loader }
44 temporary_global = true
45 -- For the other half of this hack,
46 -- see the next use of `temporary_global` below.
47 end
48end
49
28loader.context = {} 50loader.context = {}
29 51
30-- Contains a table when rocks trees are loaded, 52-- Contains a table when rocks trees are loaded,
@@ -58,6 +80,13 @@ function loader.add_context(name, version)
58 -- assert(type(name) == "string") 80 -- assert(type(name) == "string")
59 -- assert(type(version) == "string") 81 -- assert(type(version) == "string")
60 82
83 if temporary_global then
84 -- The first thing a wrapper does is to call add_context.
85 -- From here on, it's safe to clean the global environment.
86 luarocks = nil
87 temporary_global = false
88 end
89
61 if loader.context[name] then 90 if loader.context[name] then
62 return 91 return
63 end 92 end
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index b85653e9..989d49ee 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -83,38 +83,20 @@ end
83 83
84-- @param name string: Name of package to pack. 84-- @param name string: Name of package to pack.
85-- @param version string or nil: A version number may also be passed. 85-- @param version string or nil: A version number may also be passed.
86-- @param tree string or nil: An optional tree to pick the package from.
86-- @return string or (nil, string): The filename of the resulting 87-- @return string or (nil, string): The filename of the resulting
87-- .src.rock file; or nil and an error message. 88-- .src.rock file; or nil and an error message.
88local function do_pack_binary_rock(name, version) 89local function do_pack_binary_rock(name, version, tree)
89 assert(type(name) == "string") 90 assert(type(name) == "string")
90 assert(type(version) == "string" or not version) 91 assert(type(version) == "string" or not version)
91 92
92 local query = search.make_query(name, version) 93 local repo, repo_url
93 query.exact_name = true 94 name, version, repo, repo_url = search.pick_installed_rock(name, version, tree)
94 local results = {} 95 if not name then
95 96 return nil, version
96 search.manifest_search(results, cfg.rocks_dir, query)
97
98 if not next(results) then
99 return nil, "'"..name.."' does not seem to be an installed rock."
100 end
101
102 local versions = results[name]
103
104 if not version then
105 local first = next(versions)
106 if next(versions, first) then
107 return nil, "Please specify which version of '"..name.."' to pack."
108 end
109 version = first
110 end
111 if not version:match("[^-]+%-%d+") then
112 return nil, "Expected version "..version.." in version-revision format."
113 end 97 end
114 98
115 local info = versions[version][1] 99 local root = path.root_dir(repo_url)
116
117 local root = path.root_dir(info.repo)
118 local prefix = path.install_dir(name, version, root) 100 local prefix = path.install_dir(name, version, root)
119 if not fs.exists(prefix) then 101 if not fs.exists(prefix) then
120 return nil, "'"..name.." "..version.."' does not seem to be an installed rock." 102 return nil, "'"..name.." "..version.."' does not seem to be an installed rock."
@@ -180,7 +162,7 @@ function pack.pack_binary_rock(name, version, cmd, ...)
180 if not rname then 162 if not rname then
181 rname, rversion = name, version 163 rname, rversion = name, version
182 end 164 end
183 return do_pack_binary_rock(rname, rversion) 165 return do_pack_binary_rock(rname, rversion, temp_dir)
184end 166end
185 167
186--- Driver function for the "pack" command. 168--- Driver function for the "pack" command.
@@ -200,7 +182,7 @@ function pack.command(flags, arg, version)
200 if arg:match(".*%.rockspec") then 182 if arg:match(".*%.rockspec") then
201 file, err = pack.pack_source_rock(arg) 183 file, err = pack.pack_source_rock(arg)
202 else 184 else
203 file, err = do_pack_binary_rock(arg, version) 185 file, err = do_pack_binary_rock(arg, version, flags["tree"])
204 end 186 end
205 if err then 187 if err then
206 return nil, err 188 return nil, err
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 7d4f3e81..44eff694 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -415,6 +415,39 @@ function search.act_on_src_or_rockspec(action, name, version, ...)
415 return action(url, ...) 415 return action(url, ...)
416end 416end
417 417
418function search.pick_installed_rock(name, version, given_tree)
419 local results = {}
420 local query = search.make_query(name, version)
421 query.exact_name = true
422 local tree_map = {}
423 local trees = cfg.rocks_trees
424 if given_tree then
425 trees = { given_tree }
426 end
427 for _, tree in ipairs(trees) do
428 local rocks_dir = path.rocks_dir(tree)
429 tree_map[rocks_dir] = tree
430 search.manifest_search(results, rocks_dir, query)
431 end
432
433 if not next(results) then --
434 return nil,"cannot find package "..name.." "..(version or "").."\nUse 'list' to find installed rocks."
435 end
436
437 version = nil
438 local repo_url
439 local package, versions = util.sortedpairs(results)()
440 --question: what do we do about multiple versions? This should
441 --give us the latest version on the last repo (which is usually the global one)
442 for vs, repositories in util.sortedpairs(versions, deps.compare_versions) do
443 if not version then version = vs end
444 for _, rp in ipairs(repositories) do repo_url = rp.repo end
445 end
446
447 local repo = tree_map[repo_url]
448 return name, version, repo, repo_url
449end
450
418--- Driver function for "search" command. 451--- Driver function for "search" command.
419-- @param name string: A substring of a rock name to search. 452-- @param name string: A substring of a rock name to search.
420-- @param version string or nil: a version may also be passed. 453-- @param version string or nil: a version may also be passed.
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua
index f0bf2164..66ac6448 100644
--- a/src/luarocks/show.lua
+++ b/src/luarocks/show.lua
@@ -56,45 +56,12 @@ local function format_text(text)
56 return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) 56 return (table.concat(paragraphs, "\n\n"):gsub("%s$", ""))
57end 57end
58 58
59function show.pick_installed_rock(name, version, tree)
60 local results = {}
61 local query = search.make_query(name, version)
62 query.exact_name = true
63 local tree_map = {}
64 local trees = cfg.rocks_trees
65 if tree then
66 trees = { tree }
67 end
68 for _, tree in ipairs(trees) do
69 local rocks_dir = path.rocks_dir(tree)
70 tree_map[rocks_dir] = tree
71 search.manifest_search(results, rocks_dir, query)
72 end
73
74 if not next(results) then --
75 return nil,"cannot find package "..name.." "..(version or "").."\nUse 'list' to find installed rocks."
76 end
77
78 version = nil
79 local repo_url
80 local package, versions = util.sortedpairs(results)()
81 --question: what do we do about multiple versions? This should
82 --give us the latest version on the last repo (which is usually the global one)
83 for vs, repositories in util.sortedpairs(versions, deps.compare_versions) do
84 if not version then version = vs end
85 for _, rp in ipairs(repositories) do repo_url = rp.repo end
86 end
87
88 local repo = tree_map[repo_url]
89 return name, version, repo, repo_url
90end
91
92local function installed_rock_label(name, tree) 59local function installed_rock_label(name, tree)
93 local installed, version 60 local installed, version
94 if cfg.rocks_provided[name] then 61 if cfg.rocks_provided[name] then
95 installed, version = true, cfg.rocks_provided[name] 62 installed, version = true, cfg.rocks_provided[name]
96 else 63 else
97 installed, version = show.pick_installed_rock(name, nil, tree) 64 installed, version = search.pick_installed_rock(name, nil, tree)
98 end 65 end
99 return installed and "(using "..version..")" or "(missing)" 66 return installed and "(using "..version..")" or "(missing)"
100end 67end
@@ -109,7 +76,7 @@ function show.command(flags, name, version)
109 end 76 end
110 77
111 local repo, repo_url 78 local repo, repo_url
112 name, version, repo, repo_url = show.pick_installed_rock(name, version, flags["tree"]) 79 name, version, repo, repo_url = search.pick_installed_rock(name, version, flags["tree"])
113 if not name then 80 if not name then
114 return nil, version 81 return nil, version
115 end 82 end