aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2016-11-14 14:15:47 -0200
committerHisham <hisham@gobolinux.org>2016-11-14 14:15:47 -0200
commit1e7800c2993cf828f448a534106aa4046a48a591 (patch)
treef6d69aae8083deef3242d1c04c868eb7351eaa2f
parentb75ca805cf6c92214568b28540a931b70367a548 (diff)
downloadluarocks-1e7800c2993cf828f448a534106aa4046a48a591.tar.gz
luarocks-1e7800c2993cf828f448a534106aa4046a48a591.tar.bz2
luarocks-1e7800c2993cf828f448a534106aa4046a48a591.zip
Move get_versions from luarocks.core.manif to luarocks.manif.
All functions that were in core only for get_versions are moved out as well. Made possible by PR #654.
-rw-r--r--src/luarocks/core/dir.lua12
-rw-r--r--src/luarocks/core/manif.lua28
-rw-r--r--src/luarocks/core/path.lua37
-rw-r--r--src/luarocks/dir.lua12
-rw-r--r--src/luarocks/manif.lua27
-rw-r--r--src/luarocks/path.lua37
6 files changed, 76 insertions, 77 deletions
diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua
index 240bb38a..05b2c72d 100644
--- a/src/luarocks/core/dir.lua
+++ b/src/luarocks/core/dir.lua
@@ -39,17 +39,5 @@ function dir.split_url(url)
39 return protocol, pathname 39 return protocol, pathname
40end 40end
41 41
42--- Normalize a url or local path.
43-- URLs should be in the "protocol://path" format. System independent
44-- forward slashes are used, removing trailing and double slashes
45-- @param url string: an URL or a local pathname.
46-- @return string: Normalized result.
47function dir.normalize(name)
48 local protocol, pathname = dir.split_url(name)
49 pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/")
50 if protocol ~= "file" then pathname = protocol .."://"..pathname end
51 return pathname
52end
53
54return dir 42return dir
55 43
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua
index 49619e7f..549cfb4c 100644
--- a/src/luarocks/core/manif.lua
+++ b/src/luarocks/core/manif.lua
@@ -6,8 +6,6 @@ local persist = require("luarocks.core.persist")
6local type_check = require("luarocks.core.type_check") 6local type_check = require("luarocks.core.type_check")
7local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
8local dir = require("luarocks.core.dir") 8local dir = require("luarocks.core.dir")
9local util = require("luarocks.core.util")
10local path = require("luarocks.core.path")
11local require = nil 9local require = nil
12-------------------------------------------------------------------------------- 10--------------------------------------------------------------------------------
13 11
@@ -77,30 +75,4 @@ function manif.load_local_manifest(repo_url)
77 return manif.manifest_loader(pathname, repo_url, nil, true) 75 return manif.manifest_loader(pathname, repo_url, nil, true)
78end 76end
79 77
80--- Get all versions of a package listed in a manifest file.
81-- @param name string: a package name.
82-- @param deps_mode string: "one", to use only the currently
83-- configured tree; "order" to select trees based on order
84-- (use the current tree and all trees below it on the list)
85-- or "all", to use all trees.
86-- @return table: An array of strings listing installed
87-- versions of a package.
88function manif.get_versions(name, deps_mode)
89 assert(type(name) == "string")
90 assert(type(deps_mode) == "string")
91
92 local version_set = {}
93 path.map_trees(deps_mode, function(tree)
94 local manifest = manif.load_local_manifest(path.rocks_dir(tree))
95
96 if manifest and manifest.repository[name] then
97 for version in pairs(manifest.repository[name]) do
98 version_set[version] = true
99 end
100 end
101 end)
102
103 return util.keys(version_set)
104end
105
106return manif 78return manif
diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua
index a4eb8b4b..ed85aeac 100644
--- a/src/luarocks/core/path.lua
+++ b/src/luarocks/core/path.lua
@@ -111,41 +111,4 @@ function path.which_i(file_name, name, version, tree, i)
111 return file_name 111 return file_name
112end 112end
113 113
114function path.rocks_tree_to_string(tree)
115 if type(tree) == "string" then
116 return tree
117 else
118 assert(type(tree) == "table")
119 return tree.root
120 end
121end
122
123--- Apply a given function to the active rocks trees based on chosen dependency mode.
124-- @param deps_mode string: Dependency mode: "one" for the current default tree,
125-- "all" for all trees, "order" for all trees with priority >= the current default,
126-- "none" for no trees (this function becomes a nop).
127-- @param fn function: function to be applied, with the tree dir (string) as the first
128-- argument and the remaining varargs of map_trees as the following arguments.
129-- @return a table with all results of invocations of fn collected.
130function path.map_trees(deps_mode, fn, ...)
131 local result = {}
132 if deps_mode == "one" then
133 table.insert(result, (fn(cfg.root_dir, ...)) or 0)
134 elseif deps_mode == "all" or deps_mode == "order" then
135 local use = false
136 if deps_mode == "all" then
137 use = true
138 end
139 for _, tree in ipairs(cfg.rocks_trees) do
140 if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then
141 use = true
142 end
143 if use then
144 table.insert(result, (fn(tree, ...)) or 0)
145 end
146 end
147 end
148 return result
149end
150
151return path 114return path
diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua
index ad7fb870..71477804 100644
--- a/src/luarocks/dir.lua
+++ b/src/luarocks/dir.lua
@@ -24,4 +24,16 @@ function dir.dir_name(pathname)
24 return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or "" 24 return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or ""
25end 25end
26 26
27--- Normalize a url or local path.
28-- URLs should be in the "protocol://path" format. System independent
29-- forward slashes are used, removing trailing and double slashes
30-- @param url string: an URL or a local pathname.
31-- @return string: Normalized result.
32function dir.normalize(name)
33 local protocol, pathname = dir.split_url(name)
34 pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/")
35 if protocol ~= "file" then pathname = protocol .."://"..pathname end
36 return pathname
37end
38
27return dir 39return dir
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index 7fdfecda..7f3085db 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -11,6 +11,7 @@ local dir = require("luarocks.dir")
11local fs = require("luarocks.fs") 11local fs = require("luarocks.fs")
12local cfg = require("luarocks.core.cfg") 12local cfg = require("luarocks.core.cfg")
13local path = require("luarocks.path") 13local path = require("luarocks.path")
14local util = require("luarocks.util")
14 15
15manif.rock_manifest_cache = {} 16manif.rock_manifest_cache = {}
16 17
@@ -194,4 +195,30 @@ function manif.get_providing_file(name, version, item_type, item_name, repo)
194 return type(subtree) == "string" and "lib" or "lua", file_path 195 return type(subtree) == "string" and "lib" or "lua", file_path
195end 196end
196 197
198--- Get all versions of a package listed in a manifest file.
199-- @param name string: a package name.
200-- @param deps_mode string: "one", to use only the currently
201-- configured tree; "order" to select trees based on order
202-- (use the current tree and all trees below it on the list)
203-- or "all", to use all trees.
204-- @return table: An array of strings listing installed
205-- versions of a package.
206function manif.get_versions(name, deps_mode)
207 assert(type(name) == "string")
208 assert(type(deps_mode) == "string")
209
210 local version_set = {}
211 path.map_trees(deps_mode, function(tree)
212 local manifest = manif.load_local_manifest(path.rocks_dir(tree))
213
214 if manifest and manifest.repository[name] then
215 for version in pairs(manifest.repository[name]) do
216 version_set[version] = true
217 end
218 end
219 end)
220
221 return util.keys(version_set)
222end
223
197return manif 224return manif
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 71893cf1..37898435 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -231,4 +231,41 @@ 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)
232end 232end
233 233
234function path.rocks_tree_to_string(tree)
235 if type(tree) == "string" then
236 return tree
237 else
238 assert(type(tree) == "table")
239 return tree.root
240 end
241end
242
243--- Apply a given function to the active rocks trees based on chosen dependency mode.
244-- @param deps_mode string: Dependency mode: "one" for the current default tree,
245-- "all" for all trees, "order" for all trees with priority >= the current default,
246-- "none" for no trees (this function becomes a nop).
247-- @param fn function: function to be applied, with the tree dir (string) as the first
248-- argument and the remaining varargs of map_trees as the following arguments.
249-- @return a table with all results of invocations of fn collected.
250function path.map_trees(deps_mode, fn, ...)
251 local result = {}
252 if deps_mode == "one" then
253 table.insert(result, (fn(cfg.root_dir, ...)) or 0)
254 elseif deps_mode == "all" or deps_mode == "order" then
255 local use = false
256 if deps_mode == "all" then
257 use = true
258 end
259 for _, tree in ipairs(cfg.rocks_trees) do
260 if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then
261 use = true
262 end
263 if use then
264 table.insert(result, (fn(tree, ...)) or 0)
265 end
266 end
267 end
268 return result
269end
270
234return path 271return path