aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/path.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/path.lua')
-rw-r--r--src/luarocks/path.lua37
1 files changed, 37 insertions, 0 deletions
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