diff options
Diffstat (limited to 'src/luarocks/path.lua')
| -rw-r--r-- | src/luarocks/path.lua | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index c7ab9283..b3b01704 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
| @@ -14,6 +14,8 @@ path.versioned_name = core.versioned_name | |||
| 14 | path.path_to_module = core.path_to_module | 14 | path.path_to_module = core.path_to_module |
| 15 | path.deploy_lua_dir = core.deploy_lua_dir | 15 | path.deploy_lua_dir = core.deploy_lua_dir |
| 16 | path.deploy_lib_dir = core.deploy_lib_dir | 16 | path.deploy_lib_dir = core.deploy_lib_dir |
| 17 | path.map_trees = core.map_trees | ||
| 18 | path.rocks_tree_to_string = core.rocks_tree_to_string | ||
| 17 | 19 | ||
| 18 | --- Infer rockspec filename from a rock filename. | 20 | --- Infer rockspec filename from a rock filename. |
| 19 | -- @param rock_name string: Pathname of a rock file. | 21 | -- @param rock_name string: Pathname of a rock file. |
| @@ -226,43 +228,6 @@ function path.use_tree(tree) | |||
| 226 | -- .. package.cpath | 228 | -- .. package.cpath |
| 227 | end | 229 | end |
| 228 | 230 | ||
| 229 | function path.rocks_tree_to_string(tree) | ||
| 230 | if type(tree) == "string" then | ||
| 231 | return tree | ||
| 232 | else | ||
| 233 | assert(type(tree) == "table") | ||
| 234 | return tree.root | ||
| 235 | end | ||
| 236 | end | ||
| 237 | |||
| 238 | --- Apply a given function to the active rocks trees based on chosen dependency mode. | ||
| 239 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | ||
| 240 | -- "all" for all trees, "order" for all trees with priority >= the current default, | ||
| 241 | -- "none" for no trees (this function becomes a nop). | ||
| 242 | -- @param fn function: function to be applied, with the tree dir (string) as the first | ||
| 243 | -- argument and the remaining varargs of map_trees as the following arguments. | ||
| 244 | -- @return a table with all results of invocations of fn collected. | ||
| 245 | function path.map_trees(deps_mode, fn, ...) | ||
| 246 | local result = {} | ||
| 247 | if deps_mode == "one" then | ||
| 248 | table.insert(result, (fn(cfg.root_dir, ...)) or 0) | ||
| 249 | elseif deps_mode == "all" or deps_mode == "order" then | ||
| 250 | local use = false | ||
| 251 | if deps_mode == "all" then | ||
| 252 | use = true | ||
| 253 | end | ||
| 254 | for _, tree in ipairs(cfg.rocks_trees) do | ||
| 255 | if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then | ||
| 256 | use = true | ||
| 257 | end | ||
| 258 | if use then | ||
| 259 | table.insert(result, (fn(tree, ...)) or 0) | ||
| 260 | end | ||
| 261 | end | ||
| 262 | end | ||
| 263 | return result | ||
| 264 | end | ||
| 265 | |||
| 266 | --- Get the namespace of a locally-installed rock, if any. | 231 | --- Get the namespace of a locally-installed rock, if any. |
| 267 | -- @param name string: The rock name, without a namespace. | 232 | -- @param name string: The rock name, without a namespace. |
| 268 | -- @param version string: The rock version. | 233 | -- @param version string: The rock version. |
