diff options
Diffstat (limited to 'src/luarocks/path.lua')
| -rw-r--r-- | src/luarocks/path.lua | 114 |
1 files changed, 54 insertions, 60 deletions
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 200829d0..598e51d9 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
| @@ -2,30 +2,23 @@ | |||
| 2 | --- LuaRocks-specific path handling functions. | 2 | --- LuaRocks-specific path handling functions. |
| 3 | -- All paths are configured in this module, making it a single | 3 | -- All paths are configured in this module, making it a single |
| 4 | -- point where the layout of the local installation is defined in LuaRocks. | 4 | -- point where the layout of the local installation is defined in LuaRocks. |
| 5 | module("luarocks.path", package.seeall) | 5 | --module("luarocks.path", package.seeall) |
| 6 | local path = {} | ||
| 6 | 7 | ||
| 7 | local dir = require("luarocks.dir") | 8 | local dir = require("luarocks.dir") |
| 8 | local cfg = require("luarocks.cfg") | 9 | local cfg = require("luarocks.cfg") |
| 9 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
| 10 | 11 | ||
| 11 | help_summary = "Return the currently configured package path." | ||
| 12 | help_arguments = "" | ||
| 13 | help = [[ | ||
| 14 | Returns the package path currently configured for this installation | ||
| 15 | of LuaRocks, formatted as shell commands to update LUA_PATH and | ||
| 16 | LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`) | ||
| 17 | ]] | ||
| 18 | |||
| 19 | --- Infer rockspec filename from a rock filename. | 12 | --- Infer rockspec filename from a rock filename. |
| 20 | -- @param rock_name string: Pathname of a rock file. | 13 | -- @param rock_name string: Pathname of a rock file. |
| 21 | -- @return string: Filename of the rockspec, without path. | 14 | -- @return string: Filename of the rockspec, without path. |
| 22 | function rockspec_name_from_rock(rock_name) | 15 | function path.rockspec_name_from_rock(rock_name) |
| 23 | assert(type(rock_name) == "string") | 16 | assert(type(rock_name) == "string") |
| 24 | local base_name = dir.base_name(rock_name) | 17 | local base_name = dir.base_name(rock_name) |
| 25 | return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" | 18 | return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" |
| 26 | end | 19 | end |
| 27 | 20 | ||
| 28 | function rocks_dir(tree) | 21 | function path.rocks_dir(tree) |
| 29 | if type(tree) == "string" then | 22 | if type(tree) == "string" then |
| 30 | return dir.path(tree, cfg.rocks_subdir) | 23 | return dir.path(tree, cfg.rocks_subdir) |
| 31 | else | 24 | else |
| @@ -34,12 +27,12 @@ function rocks_dir(tree) | |||
| 34 | end | 27 | end |
| 35 | end | 28 | end |
| 36 | 29 | ||
| 37 | function root_dir(rocks_dir) | 30 | function path.root_dir(rocks_dir) |
| 38 | assert(type(rocks_dir) == "string") | 31 | assert(type(rocks_dir) == "string") |
| 39 | return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") | 32 | return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") |
| 40 | end | 33 | end |
| 41 | 34 | ||
| 42 | function rocks_tree_to_string(tree) | 35 | function path.rocks_tree_to_string(tree) |
| 43 | if type(tree) == "string" then | 36 | if type(tree) == "string" then |
| 44 | return tree | 37 | return tree |
| 45 | else | 38 | else |
| @@ -48,7 +41,7 @@ function rocks_tree_to_string(tree) | |||
| 48 | end | 41 | end |
| 49 | end | 42 | end |
| 50 | 43 | ||
| 51 | function deploy_bin_dir(tree) | 44 | function path.deploy_bin_dir(tree) |
| 52 | if type(tree) == "string" then | 45 | if type(tree) == "string" then |
| 53 | return dir.path(tree, "bin") | 46 | return dir.path(tree, "bin") |
| 54 | else | 47 | else |
| @@ -57,7 +50,7 @@ function deploy_bin_dir(tree) | |||
| 57 | end | 50 | end |
| 58 | end | 51 | end |
| 59 | 52 | ||
| 60 | function deploy_lua_dir(tree) | 53 | function path.deploy_lua_dir(tree) |
| 61 | if type(tree) == "string" then | 54 | if type(tree) == "string" then |
| 62 | return dir.path(tree, cfg.lua_modules_path) | 55 | return dir.path(tree, cfg.lua_modules_path) |
| 63 | else | 56 | else |
| @@ -66,7 +59,7 @@ function deploy_lua_dir(tree) | |||
| 66 | end | 59 | end |
| 67 | end | 60 | end |
| 68 | 61 | ||
| 69 | function deploy_lib_dir(tree) | 62 | function path.deploy_lib_dir(tree) |
| 70 | if type(tree) == "string" then | 63 | if type(tree) == "string" then |
| 71 | return dir.path(tree, cfg.lib_modules_path) | 64 | return dir.path(tree, cfg.lib_modules_path) |
| 72 | else | 65 | else |
| @@ -75,7 +68,7 @@ function deploy_lib_dir(tree) | |||
| 75 | end | 68 | end |
| 76 | end | 69 | end |
| 77 | 70 | ||
| 78 | function manifest_file(tree) | 71 | function path.manifest_file(tree) |
| 79 | if type(tree) == "string" then | 72 | if type(tree) == "string" then |
| 80 | return dir.path(tree, cfg.rocks_subdir, "manifest") | 73 | return dir.path(tree, cfg.rocks_subdir, "manifest") |
| 81 | else | 74 | else |
| @@ -89,10 +82,10 @@ end | |||
| 89 | -- @return string: The resulting path -- does not guarantee that | 82 | -- @return string: The resulting path -- does not guarantee that |
| 90 | -- @param tree string or nil: If given, specifies the local tree to use. | 83 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 91 | -- the package (and by extension, the path) exists. | 84 | -- the package (and by extension, the path) exists. |
| 92 | function versions_dir(name, tree) | 85 | function path.versions_dir(name, tree) |
| 93 | assert(type(name) == "string") | 86 | assert(type(name) == "string") |
| 94 | tree = tree or cfg.root_dir | 87 | tree = tree or cfg.root_dir |
| 95 | return dir.path(rocks_dir(tree), name) | 88 | return dir.path(path.rocks_dir(tree), name) |
| 96 | end | 89 | end |
| 97 | 90 | ||
| 98 | --- Get the local installation directory (prefix) for a package. | 91 | --- Get the local installation directory (prefix) for a package. |
| @@ -101,11 +94,11 @@ end | |||
| 101 | -- @param tree string or nil: If given, specifies the local tree to use. | 94 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 102 | -- @return string: The resulting path -- does not guarantee that | 95 | -- @return string: The resulting path -- does not guarantee that |
| 103 | -- the package (and by extension, the path) exists. | 96 | -- the package (and by extension, the path) exists. |
| 104 | function install_dir(name, version, tree) | 97 | function path.install_dir(name, version, tree) |
| 105 | assert(type(name) == "string") | 98 | assert(type(name) == "string") |
| 106 | assert(type(version) == "string") | 99 | assert(type(version) == "string") |
| 107 | tree = tree or cfg.root_dir | 100 | tree = tree or cfg.root_dir |
| 108 | return dir.path(rocks_dir(tree), name, version) | 101 | return dir.path(path.rocks_dir(tree), name, version) |
| 109 | end | 102 | end |
| 110 | 103 | ||
| 111 | --- Get the local filename of the rockspec of an installed rock. | 104 | --- Get the local filename of the rockspec of an installed rock. |
| @@ -114,11 +107,11 @@ end | |||
| 114 | -- @param tree string or nil: If given, specifies the local tree to use. | 107 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 115 | -- @return string: The resulting path -- does not guarantee that | 108 | -- @return string: The resulting path -- does not guarantee that |
| 116 | -- the package (and by extension, the file) exists. | 109 | -- the package (and by extension, the file) exists. |
| 117 | function rockspec_file(name, version, tree) | 110 | function path.rockspec_file(name, version, tree) |
| 118 | assert(type(name) == "string") | 111 | assert(type(name) == "string") |
| 119 | assert(type(version) == "string") | 112 | assert(type(version) == "string") |
| 120 | tree = tree or cfg.root_dir | 113 | tree = tree or cfg.root_dir |
| 121 | return dir.path(rocks_dir(tree), name, version, name.."-"..version..".rockspec") | 114 | return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec") |
| 122 | end | 115 | end |
| 123 | 116 | ||
| 124 | --- Get the local filename of the rock_manifest file of an installed rock. | 117 | --- Get the local filename of the rock_manifest file of an installed rock. |
| @@ -127,11 +120,11 @@ end | |||
| 127 | -- @param tree string or nil: If given, specifies the local tree to use. | 120 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 128 | -- @return string: The resulting path -- does not guarantee that | 121 | -- @return string: The resulting path -- does not guarantee that |
| 129 | -- the package (and by extension, the file) exists. | 122 | -- the package (and by extension, the file) exists. |
| 130 | function rock_manifest_file(name, version, tree) | 123 | function path.rock_manifest_file(name, version, tree) |
| 131 | assert(type(name) == "string") | 124 | assert(type(name) == "string") |
| 132 | assert(type(version) == "string") | 125 | assert(type(version) == "string") |
| 133 | tree = tree or cfg.root_dir | 126 | tree = tree or cfg.root_dir |
| 134 | return dir.path(rocks_dir(tree), name, version, "rock_manifest") | 127 | return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") |
| 135 | end | 128 | end |
| 136 | 129 | ||
| 137 | --- Get the local installation directory for C libraries of a package. | 130 | --- Get the local installation directory for C libraries of a package. |
| @@ -140,11 +133,11 @@ end | |||
| 140 | -- @param tree string or nil: If given, specifies the local tree to use. | 133 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 141 | -- @return string: The resulting path -- does not guarantee that | 134 | -- @return string: The resulting path -- does not guarantee that |
| 142 | -- the package (and by extension, the path) exists. | 135 | -- the package (and by extension, the path) exists. |
| 143 | function lib_dir(name, version, tree) | 136 | function path.lib_dir(name, version, tree) |
| 144 | assert(type(name) == "string") | 137 | assert(type(name) == "string") |
| 145 | assert(type(version) == "string") | 138 | assert(type(version) == "string") |
| 146 | tree = tree or cfg.root_dir | 139 | tree = tree or cfg.root_dir |
| 147 | return dir.path(rocks_dir(tree), name, version, "lib") | 140 | return dir.path(path.rocks_dir(tree), name, version, "lib") |
| 148 | end | 141 | end |
| 149 | 142 | ||
| 150 | --- Get the local installation directory for Lua modules of a package. | 143 | --- Get the local installation directory for Lua modules of a package. |
| @@ -153,11 +146,11 @@ end | |||
| 153 | -- @param tree string or nil: If given, specifies the local tree to use. | 146 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 154 | -- @return string: The resulting path -- does not guarantee that | 147 | -- @return string: The resulting path -- does not guarantee that |
| 155 | -- the package (and by extension, the path) exists. | 148 | -- the package (and by extension, the path) exists. |
| 156 | function lua_dir(name, version, tree) | 149 | function path.lua_dir(name, version, tree) |
| 157 | assert(type(name) == "string") | 150 | assert(type(name) == "string") |
| 158 | assert(type(version) == "string") | 151 | assert(type(version) == "string") |
| 159 | tree = tree or cfg.root_dir | 152 | tree = tree or cfg.root_dir |
| 160 | return dir.path(rocks_dir(tree), name, version, "lua") | 153 | return dir.path(path.rocks_dir(tree), name, version, "lua") |
| 161 | end | 154 | end |
| 162 | 155 | ||
| 163 | --- Get the local installation directory for documentation of a package. | 156 | --- Get the local installation directory for documentation of a package. |
| @@ -166,11 +159,11 @@ end | |||
| 166 | -- @param tree string or nil: If given, specifies the local tree to use. | 159 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 167 | -- @return string: The resulting path -- does not guarantee that | 160 | -- @return string: The resulting path -- does not guarantee that |
| 168 | -- the package (and by extension, the path) exists. | 161 | -- the package (and by extension, the path) exists. |
| 169 | function doc_dir(name, version, tree) | 162 | function path.doc_dir(name, version, tree) |
| 170 | assert(type(name) == "string") | 163 | assert(type(name) == "string") |
| 171 | assert(type(version) == "string") | 164 | assert(type(version) == "string") |
| 172 | tree = tree or cfg.root_dir | 165 | tree = tree or cfg.root_dir |
| 173 | return dir.path(rocks_dir(tree), name, version, "doc") | 166 | return dir.path(path.rocks_dir(tree), name, version, "doc") |
| 174 | end | 167 | end |
| 175 | 168 | ||
| 176 | --- Get the local installation directory for configuration files of a package. | 169 | --- Get the local installation directory for configuration files of a package. |
| @@ -179,11 +172,11 @@ end | |||
| 179 | -- @param tree string or nil: If given, specifies the local tree to use. | 172 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 180 | -- @return string: The resulting path -- does not guarantee that | 173 | -- @return string: The resulting path -- does not guarantee that |
| 181 | -- the package (and by extension, the path) exists. | 174 | -- the package (and by extension, the path) exists. |
| 182 | function conf_dir(name, version, tree) | 175 | function path.conf_dir(name, version, tree) |
| 183 | assert(type(name) == "string") | 176 | assert(type(name) == "string") |
| 184 | assert(type(version) == "string") | 177 | assert(type(version) == "string") |
| 185 | tree = tree or cfg.root_dir | 178 | tree = tree or cfg.root_dir |
| 186 | return dir.path(rocks_dir(tree), name, version, "conf") | 179 | return dir.path(path.rocks_dir(tree), name, version, "conf") |
| 187 | end | 180 | end |
| 188 | 181 | ||
| 189 | --- Get the local installation directory for command-line scripts | 182 | --- Get the local installation directory for command-line scripts |
| @@ -193,11 +186,11 @@ end | |||
| 193 | -- @param tree string or nil: If given, specifies the local tree to use. | 186 | -- @param tree string or nil: If given, specifies the local tree to use. |
| 194 | -- @return string: The resulting path -- does not guarantee that | 187 | -- @return string: The resulting path -- does not guarantee that |
| 195 | -- the package (and by extension, the path) exists. | 188 | -- the package (and by extension, the path) exists. |
| 196 | function bin_dir(name, version, tree) | 189 | function path.bin_dir(name, version, tree) |
| 197 | assert(type(name) == "string") | 190 | assert(type(name) == "string") |
| 198 | assert(type(version) == "string") | 191 | assert(type(version) == "string") |
| 199 | tree = tree or cfg.root_dir | 192 | tree = tree or cfg.root_dir |
| 200 | return dir.path(rocks_dir(tree), name, version, "bin") | 193 | return dir.path(path.rocks_dir(tree), name, version, "bin") |
| 201 | end | 194 | end |
| 202 | 195 | ||
| 203 | --- Extract name, version and arch of a rock filename, | 196 | --- Extract name, version and arch of a rock filename, |
| @@ -205,7 +198,7 @@ end | |||
| 205 | -- @param file_name string: pathname of a rock or rockspec | 198 | -- @param file_name string: pathname of a rock or rockspec |
| 206 | -- @return (string, string, string) or nil: name, version and arch | 199 | -- @return (string, string, string) or nil: name, version and arch |
| 207 | -- or nil if name could not be parsed | 200 | -- or nil if name could not be parsed |
| 208 | function parse_name(file_name) | 201 | function path.parse_name(file_name) |
| 209 | assert(type(file_name) == "string") | 202 | assert(type(file_name) == "string") |
| 210 | if file_name:match("%.rock$") then | 203 | if file_name:match("%.rock$") then |
| 211 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") | 204 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") |
| @@ -220,7 +213,7 @@ end | |||
| 220 | -- @param version string: Package version. | 213 | -- @param version string: Package version. |
| 221 | -- @param arch string: Architecture identifier, or "rockspec" or "installed". | 214 | -- @param arch string: Architecture identifier, or "rockspec" or "installed". |
| 222 | -- @return string: A URL or pathname following LuaRocks naming conventions. | 215 | -- @return string: A URL or pathname following LuaRocks naming conventions. |
| 223 | function make_url(pathname, name, version, arch) | 216 | function path.make_url(pathname, name, version, arch) |
| 224 | assert(type(pathname) == "string") | 217 | assert(type(pathname) == "string") |
| 225 | assert(type(name) == "string") | 218 | assert(type(name) == "string") |
| 226 | assert(type(version) == "string") | 219 | assert(type(version) == "string") |
| @@ -244,7 +237,7 @@ end | |||
| 244 | -- @return string: The module identifier, or nil if given path is | 237 | -- @return string: The module identifier, or nil if given path is |
| 245 | -- not a conformant module path (the function does not check if the | 238 | -- not a conformant module path (the function does not check if the |
| 246 | -- path actually exists). | 239 | -- path actually exists). |
| 247 | function path_to_module(file) | 240 | function path.path_to_module(file) |
| 248 | assert(type(file) == "string") | 241 | assert(type(file) == "string") |
| 249 | 242 | ||
| 250 | local name = file:match("(.*)%."..cfg.lua_extension.."$") | 243 | local name = file:match("(.*)%."..cfg.lua_extension.."$") |
| @@ -269,7 +262,7 @@ end | |||
| 269 | -- For example, on Unix, "foo.bar.baz" will return "foo/bar". | 262 | -- For example, on Unix, "foo.bar.baz" will return "foo/bar". |
| 270 | -- @param mod string: A module name in Lua dot-separated format. | 263 | -- @param mod string: A module name in Lua dot-separated format. |
| 271 | -- @return string: A directory name using the platform's separator. | 264 | -- @return string: A directory name using the platform's separator. |
| 272 | function module_to_path(mod) | 265 | function path.module_to_path(mod) |
| 273 | assert(type(mod) == "string") | 266 | assert(type(mod) == "string") |
| 274 | return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) | 267 | return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) |
| 275 | end | 268 | end |
| @@ -278,19 +271,19 @@ end | |||
| 278 | -- Create a "variables" table in the rockspec table, containing | 271 | -- Create a "variables" table in the rockspec table, containing |
| 279 | -- adjusted variables according to the configuration file. | 272 | -- adjusted variables according to the configuration file. |
| 280 | -- @param rockspec table: The rockspec table. | 273 | -- @param rockspec table: The rockspec table. |
| 281 | function configure_paths(rockspec) | 274 | function path.configure_paths(rockspec) |
| 282 | assert(type(rockspec) == "table") | 275 | assert(type(rockspec) == "table") |
| 283 | local vars = {} | 276 | local vars = {} |
| 284 | for k,v in pairs(cfg.variables) do | 277 | for k,v in pairs(cfg.variables) do |
| 285 | vars[k] = v | 278 | vars[k] = v |
| 286 | end | 279 | end |
| 287 | local name, version = rockspec.name, rockspec.version | 280 | local name, version = rockspec.name, rockspec.version |
| 288 | vars.PREFIX = install_dir(name, version) | 281 | vars.PREFIX = path.install_dir(name, version) |
| 289 | vars.LUADIR = lua_dir(name, version) | 282 | vars.LUADIR = path.lua_dir(name, version) |
| 290 | vars.LIBDIR = lib_dir(name, version) | 283 | vars.LIBDIR = path.lib_dir(name, version) |
| 291 | vars.CONFDIR = conf_dir(name, version) | 284 | vars.CONFDIR = path.conf_dir(name, version) |
| 292 | vars.BINDIR = bin_dir(name, version) | 285 | vars.BINDIR = path.bin_dir(name, version) |
| 293 | vars.DOCDIR = doc_dir(name, version) | 286 | vars.DOCDIR = path.doc_dir(name, version) |
| 294 | rockspec.variables = vars | 287 | rockspec.variables = vars |
| 295 | end | 288 | end |
| 296 | 289 | ||
| @@ -300,7 +293,7 @@ end | |||
| 300 | -- @param name string: Rock name | 293 | -- @param name string: Rock name |
| 301 | -- @param version string: Rock version | 294 | -- @param version string: Rock version |
| 302 | -- @return string: a pathname with the same directory parts and a versioned basename. | 295 | -- @return string: a pathname with the same directory parts and a versioned basename. |
| 303 | function versioned_name(file, prefix, name, version) | 296 | function path.versioned_name(file, prefix, name, version) |
| 304 | assert(type(file) == "string") | 297 | assert(type(file) == "string") |
| 305 | assert(type(name) == "string") | 298 | assert(type(name) == "string") |
| 306 | assert(type(version) == "string") | 299 | assert(type(version) == "string") |
| @@ -310,12 +303,12 @@ function versioned_name(file, prefix, name, version) | |||
| 310 | return dir.path(prefix, name_version.."-"..rest) | 303 | return dir.path(prefix, name_version.."-"..rest) |
| 311 | end | 304 | end |
| 312 | 305 | ||
| 313 | function use_tree(tree) | 306 | function path.use_tree(tree) |
| 314 | cfg.root_dir = tree | 307 | cfg.root_dir = tree |
| 315 | cfg.rocks_dir = rocks_dir(tree) | 308 | cfg.rocks_dir = path.rocks_dir(tree) |
| 316 | cfg.deploy_bin_dir = deploy_bin_dir(tree) | 309 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) |
| 317 | cfg.deploy_lua_dir = deploy_lua_dir(tree) | 310 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) |
| 318 | cfg.deploy_lib_dir = deploy_lib_dir(tree) | 311 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) |
| 319 | end | 312 | end |
| 320 | 313 | ||
| 321 | --- Apply a given function to the active rocks trees based on chosen dependency mode. | 314 | --- Apply a given function to the active rocks trees based on chosen dependency mode. |
| @@ -325,7 +318,7 @@ end | |||
| 325 | -- @param fn function: function to be applied, with the tree dir (string) as the first | 318 | -- @param fn function: function to be applied, with the tree dir (string) as the first |
| 326 | -- argument and the remaining varargs of map_trees as the following arguments. | 319 | -- argument and the remaining varargs of map_trees as the following arguments. |
| 327 | -- @return a table with all results of invocations of fn collected. | 320 | -- @return a table with all results of invocations of fn collected. |
| 328 | function map_trees(deps_mode, fn, ...) | 321 | function path.map_trees(deps_mode, fn, ...) |
| 329 | local result = {} | 322 | local result = {} |
| 330 | if deps_mode == "one" then | 323 | if deps_mode == "one" then |
| 331 | table.insert(result, (fn(cfg.root_dir, ...)) or 0) | 324 | table.insert(result, (fn(cfg.root_dir, ...)) or 0) |
| @@ -335,7 +328,7 @@ function map_trees(deps_mode, fn, ...) | |||
| 335 | use = true | 328 | use = true |
| 336 | end | 329 | end |
| 337 | for _, tree in ipairs(cfg.rocks_trees) do | 330 | for _, tree in ipairs(cfg.rocks_trees) do |
| 338 | if dir.normalize(rocks_tree_to_string(tree)) == dir.normalize(rocks_tree_to_string(cfg.root_dir)) then | 331 | if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then |
| 339 | use = true | 332 | use = true |
| 340 | end | 333 | end |
| 341 | if use then | 334 | if use then |
| @@ -354,17 +347,17 @@ end | |||
| 354 | -- @param i number: the index, 1 if version is the current default, > 1 otherwise. | 347 | -- @param i number: the index, 1 if version is the current default, > 1 otherwise. |
| 355 | -- This is done this way for use by select_module in luarocks.loader. | 348 | -- This is done this way for use by select_module in luarocks.loader. |
| 356 | -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") | 349 | -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") |
| 357 | function which_i(module_name, name, version, tree, i) | 350 | function path.which_i(module_name, name, version, tree, i) |
| 358 | local deploy_dir | 351 | local deploy_dir |
| 359 | if module_name:match("%.lua$") then | 352 | if module_name:match("%.lua$") then |
| 360 | deploy_dir = deploy_lua_dir(tree) | 353 | deploy_dir = path.deploy_lua_dir(tree) |
| 361 | module_name = dir.path(deploy_dir, module_name) | 354 | module_name = dir.path(deploy_dir, module_name) |
| 362 | else | 355 | else |
| 363 | deploy_dir = deploy_lib_dir(tree) | 356 | deploy_dir = path.deploy_lib_dir(tree) |
| 364 | module_name = dir.path(deploy_dir, module_name) | 357 | module_name = dir.path(deploy_dir, module_name) |
| 365 | end | 358 | end |
| 366 | if i > 1 then | 359 | if i > 1 then |
| 367 | module_name = versioned_name(module_name, deploy_dir, name, version) | 360 | module_name = path.versioned_name(module_name, deploy_dir, name, version) |
| 368 | end | 361 | end |
| 369 | return module_name | 362 | return module_name |
| 370 | end | 363 | end |
| @@ -378,14 +371,15 @@ end | |||
| 378 | -- @param tree string: repository path (eg. "/usr/local") | 371 | -- @param tree string: repository path (eg. "/usr/local") |
| 379 | -- @param manifest table: the manifest table for the tree. | 372 | -- @param manifest table: the manifest table for the tree. |
| 380 | -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") | 373 | -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") |
| 381 | function which(module_name, filename, name, version, tree, manifest) | 374 | function path.which(module_name, filename, name, version, tree, manifest) |
| 382 | local versions = manifest.modules[module_name] | 375 | local versions = manifest.modules[module_name] |
| 383 | assert(versions) | 376 | assert(versions) |
| 384 | for i, name_version in ipairs(versions) do | 377 | for i, name_version in ipairs(versions) do |
| 385 | if name_version == name.."/"..version then | 378 | if name_version == name.."/"..version then |
| 386 | return which_i(filename, name, version, tree, i):gsub("//", "/") | 379 | return path.which_i(filename, name, version, tree, i):gsub("//", "/") |
| 387 | end | 380 | end |
| 388 | end | 381 | end |
| 389 | assert(false) | 382 | assert(false) |
| 390 | end | 383 | end |
| 391 | 384 | ||
| 385 | return path | ||
