diff options
| author | mpeterv <petjamelnik@yandex.ru> | 2014-03-20 21:40:47 +0400 |
|---|---|---|
| committer | mpeterv <petjamelnik@yandex.ru> | 2014-03-20 21:40:47 +0400 |
| commit | a3ee3e91ae5147f15f521decfe4d9188afefc782 (patch) | |
| tree | cc5df6ca8445f3a153c4276540e170fd95e19b83 | |
| parent | 3af05c7e5d7999500508c51a5d405e59c14363cc (diff) | |
| download | luarocks-a3ee3e91ae5147f15f521decfe4d9188afefc782.tar.gz luarocks-a3ee3e91ae5147f15f521decfe4d9188afefc782.tar.bz2 luarocks-a3ee3e91ae5147f15f521decfe4d9188afefc782.zip | |
Split luarocks.path module
| -rw-r--r-- | Makefile | 2 | ||||
| -rwxr-xr-x | src/bin/luarocks | 2 | ||||
| -rw-r--r-- | src/luarocks/path.lua | 154 | ||||
| -rw-r--r-- | src/luarocks/path_command.lua | 58 |
4 files changed, 114 insertions, 102 deletions
| @@ -24,7 +24,7 @@ remove.lua fs.lua manif.lua add.lua deps.lua build.lua search.lua show.lua \ | |||
| 24 | manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \ | 24 | manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \ |
| 25 | help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \ | 25 | help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \ |
| 26 | admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \ | 26 | admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \ |
| 27 | purge.lua path.lua write_rockspec.lua doc.lua | 27 | purge.lua path.lua path_command.lua write_rockspec.lua doc.lua |
| 28 | 28 | ||
| 29 | CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua | 29 | CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua |
| 30 | 30 | ||
diff --git a/src/bin/luarocks b/src/bin/luarocks index e9cfc349..9c190175 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks | |||
| @@ -16,7 +16,7 @@ commands = { | |||
| 16 | remove = "luarocks.remove", | 16 | remove = "luarocks.remove", |
| 17 | make = "luarocks.make", | 17 | make = "luarocks.make", |
| 18 | download = "luarocks.download", | 18 | download = "luarocks.download", |
| 19 | path = "luarocks.path", | 19 | path = "luarocks.path_command", |
| 20 | show = "luarocks.show", | 20 | show = "luarocks.show", |
| 21 | new_version = "luarocks.new_version", | 21 | new_version = "luarocks.new_version", |
| 22 | lint = "luarocks.lint", | 22 | lint = "luarocks.lint", |
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index d7273095..598e51d9 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
| @@ -2,31 +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 | local deps = require("luarocks.deps") | ||
| 11 | |||
| 12 | help_summary = "Return the currently configured package path." | ||
| 13 | help_arguments = "" | ||
| 14 | help = [[ | ||
| 15 | Returns the package path currently configured for this installation | ||
| 16 | of LuaRocks, formatted as shell commands to update LUA_PATH and | ||
| 17 | LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`) | ||
| 18 | ]] | ||
| 19 | 11 | ||
| 20 | --- Infer rockspec filename from a rock filename. | 12 | --- Infer rockspec filename from a rock filename. |
| 21 | -- @param rock_name string: Pathname of a rock file. | 13 | -- @param rock_name string: Pathname of a rock file. |
| 22 | -- @return string: Filename of the rockspec, without path. | 14 | -- @return string: Filename of the rockspec, without path. |
| 23 | function rockspec_name_from_rock(rock_name) | 15 | function path.rockspec_name_from_rock(rock_name) |
| 24 | assert(type(rock_name) == "string") | 16 | assert(type(rock_name) == "string") |
| 25 | local base_name = dir.base_name(rock_name) | 17 | local base_name = dir.base_name(rock_name) |
| 26 | return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" | 18 | return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" |
| 27 | end | 19 | end |
| 28 | 20 | ||
| 29 | function rocks_dir(tree) | 21 | function path.rocks_dir(tree) |
| 30 | if type(tree) == "string" then | 22 | if type(tree) == "string" then |
| 31 | return dir.path(tree, cfg.rocks_subdir) | 23 | return dir.path(tree, cfg.rocks_subdir) |
| 32 | else | 24 | else |
| @@ -35,12 +27,12 @@ function rocks_dir(tree) | |||
| 35 | end | 27 | end |
| 36 | end | 28 | end |
| 37 | 29 | ||
| 38 | function root_dir(rocks_dir) | 30 | function path.root_dir(rocks_dir) |
| 39 | assert(type(rocks_dir) == "string") | 31 | assert(type(rocks_dir) == "string") |
| 40 | return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") | 32 | return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") |
| 41 | end | 33 | end |
| 42 | 34 | ||
| 43 | function rocks_tree_to_string(tree) | 35 | function path.rocks_tree_to_string(tree) |
| 44 | if type(tree) == "string" then | 36 | if type(tree) == "string" then |
| 45 | return tree | 37 | return tree |
| 46 | else | 38 | else |
| @@ -49,7 +41,7 @@ function rocks_tree_to_string(tree) | |||
| 49 | end | 41 | end |
| 50 | end | 42 | end |
| 51 | 43 | ||
| 52 | function deploy_bin_dir(tree) | 44 | function path.deploy_bin_dir(tree) |
| 53 | if type(tree) == "string" then | 45 | if type(tree) == "string" then |
| 54 | return dir.path(tree, "bin") | 46 | return dir.path(tree, "bin") |
| 55 | else | 47 | else |
| @@ -58,7 +50,7 @@ function deploy_bin_dir(tree) | |||
| 58 | end | 50 | end |
| 59 | end | 51 | end |
| 60 | 52 | ||
| 61 | function deploy_lua_dir(tree) | 53 | function path.deploy_lua_dir(tree) |
| 62 | if type(tree) == "string" then | 54 | if type(tree) == "string" then |
| 63 | return dir.path(tree, cfg.lua_modules_path) | 55 | return dir.path(tree, cfg.lua_modules_path) |
| 64 | else | 56 | else |
| @@ -67,7 +59,7 @@ function deploy_lua_dir(tree) | |||
| 67 | end | 59 | end |
| 68 | end | 60 | end |
| 69 | 61 | ||
| 70 | function deploy_lib_dir(tree) | 62 | function path.deploy_lib_dir(tree) |
| 71 | if type(tree) == "string" then | 63 | if type(tree) == "string" then |
| 72 | return dir.path(tree, cfg.lib_modules_path) | 64 | return dir.path(tree, cfg.lib_modules_path) |
| 73 | else | 65 | else |
| @@ -76,7 +68,7 @@ function deploy_lib_dir(tree) | |||
| 76 | end | 68 | end |
| 77 | end | 69 | end |
| 78 | 70 | ||
| 79 | function manifest_file(tree) | 71 | function path.manifest_file(tree) |
| 80 | if type(tree) == "string" then | 72 | if type(tree) == "string" then |
| 81 | return dir.path(tree, cfg.rocks_subdir, "manifest") | 73 | return dir.path(tree, cfg.rocks_subdir, "manifest") |
| 82 | else | 74 | else |
| @@ -90,10 +82,10 @@ end | |||
| 90 | -- @return string: The resulting path -- does not guarantee that | 82 | -- @return string: The resulting path -- does not guarantee that |
| 91 | -- @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. |
| 92 | -- the package (and by extension, the path) exists. | 84 | -- the package (and by extension, the path) exists. |
| 93 | function versions_dir(name, tree) | 85 | function path.versions_dir(name, tree) |
| 94 | assert(type(name) == "string") | 86 | assert(type(name) == "string") |
| 95 | tree = tree or cfg.root_dir | 87 | tree = tree or cfg.root_dir |
| 96 | return dir.path(rocks_dir(tree), name) | 88 | return dir.path(path.rocks_dir(tree), name) |
| 97 | end | 89 | end |
| 98 | 90 | ||
| 99 | --- Get the local installation directory (prefix) for a package. | 91 | --- Get the local installation directory (prefix) for a package. |
| @@ -102,11 +94,11 @@ end | |||
| 102 | -- @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. |
| 103 | -- @return string: The resulting path -- does not guarantee that | 95 | -- @return string: The resulting path -- does not guarantee that |
| 104 | -- the package (and by extension, the path) exists. | 96 | -- the package (and by extension, the path) exists. |
| 105 | function install_dir(name, version, tree) | 97 | function path.install_dir(name, version, tree) |
| 106 | assert(type(name) == "string") | 98 | assert(type(name) == "string") |
| 107 | assert(type(version) == "string") | 99 | assert(type(version) == "string") |
| 108 | tree = tree or cfg.root_dir | 100 | tree = tree or cfg.root_dir |
| 109 | return dir.path(rocks_dir(tree), name, version) | 101 | return dir.path(path.rocks_dir(tree), name, version) |
| 110 | end | 102 | end |
| 111 | 103 | ||
| 112 | --- Get the local filename of the rockspec of an installed rock. | 104 | --- Get the local filename of the rockspec of an installed rock. |
| @@ -115,11 +107,11 @@ end | |||
| 115 | -- @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. |
| 116 | -- @return string: The resulting path -- does not guarantee that | 108 | -- @return string: The resulting path -- does not guarantee that |
| 117 | -- the package (and by extension, the file) exists. | 109 | -- the package (and by extension, the file) exists. |
| 118 | function rockspec_file(name, version, tree) | 110 | function path.rockspec_file(name, version, tree) |
| 119 | assert(type(name) == "string") | 111 | assert(type(name) == "string") |
| 120 | assert(type(version) == "string") | 112 | assert(type(version) == "string") |
| 121 | tree = tree or cfg.root_dir | 113 | tree = tree or cfg.root_dir |
| 122 | return dir.path(rocks_dir(tree), name, version, name.."-"..version..".rockspec") | 114 | return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec") |
| 123 | end | 115 | end |
| 124 | 116 | ||
| 125 | --- 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. |
| @@ -128,11 +120,11 @@ end | |||
| 128 | -- @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. |
| 129 | -- @return string: The resulting path -- does not guarantee that | 121 | -- @return string: The resulting path -- does not guarantee that |
| 130 | -- the package (and by extension, the file) exists. | 122 | -- the package (and by extension, the file) exists. |
| 131 | function rock_manifest_file(name, version, tree) | 123 | function path.rock_manifest_file(name, version, tree) |
| 132 | assert(type(name) == "string") | 124 | assert(type(name) == "string") |
| 133 | assert(type(version) == "string") | 125 | assert(type(version) == "string") |
| 134 | tree = tree or cfg.root_dir | 126 | tree = tree or cfg.root_dir |
| 135 | return dir.path(rocks_dir(tree), name, version, "rock_manifest") | 127 | return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") |
| 136 | end | 128 | end |
| 137 | 129 | ||
| 138 | --- Get the local installation directory for C libraries of a package. | 130 | --- Get the local installation directory for C libraries of a package. |
| @@ -141,11 +133,11 @@ end | |||
| 141 | -- @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. |
| 142 | -- @return string: The resulting path -- does not guarantee that | 134 | -- @return string: The resulting path -- does not guarantee that |
| 143 | -- the package (and by extension, the path) exists. | 135 | -- the package (and by extension, the path) exists. |
| 144 | function lib_dir(name, version, tree) | 136 | function path.lib_dir(name, version, tree) |
| 145 | assert(type(name) == "string") | 137 | assert(type(name) == "string") |
| 146 | assert(type(version) == "string") | 138 | assert(type(version) == "string") |
| 147 | tree = tree or cfg.root_dir | 139 | tree = tree or cfg.root_dir |
| 148 | return dir.path(rocks_dir(tree), name, version, "lib") | 140 | return dir.path(path.rocks_dir(tree), name, version, "lib") |
| 149 | end | 141 | end |
| 150 | 142 | ||
| 151 | --- Get the local installation directory for Lua modules of a package. | 143 | --- Get the local installation directory for Lua modules of a package. |
| @@ -154,11 +146,11 @@ end | |||
| 154 | -- @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. |
| 155 | -- @return string: The resulting path -- does not guarantee that | 147 | -- @return string: The resulting path -- does not guarantee that |
| 156 | -- the package (and by extension, the path) exists. | 148 | -- the package (and by extension, the path) exists. |
| 157 | function lua_dir(name, version, tree) | 149 | function path.lua_dir(name, version, tree) |
| 158 | assert(type(name) == "string") | 150 | assert(type(name) == "string") |
| 159 | assert(type(version) == "string") | 151 | assert(type(version) == "string") |
| 160 | tree = tree or cfg.root_dir | 152 | tree = tree or cfg.root_dir |
| 161 | return dir.path(rocks_dir(tree), name, version, "lua") | 153 | return dir.path(path.rocks_dir(tree), name, version, "lua") |
| 162 | end | 154 | end |
| 163 | 155 | ||
| 164 | --- Get the local installation directory for documentation of a package. | 156 | --- Get the local installation directory for documentation of a package. |
| @@ -167,11 +159,11 @@ end | |||
| 167 | -- @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. |
| 168 | -- @return string: The resulting path -- does not guarantee that | 160 | -- @return string: The resulting path -- does not guarantee that |
| 169 | -- the package (and by extension, the path) exists. | 161 | -- the package (and by extension, the path) exists. |
| 170 | function doc_dir(name, version, tree) | 162 | function path.doc_dir(name, version, tree) |
| 171 | assert(type(name) == "string") | 163 | assert(type(name) == "string") |
| 172 | assert(type(version) == "string") | 164 | assert(type(version) == "string") |
| 173 | tree = tree or cfg.root_dir | 165 | tree = tree or cfg.root_dir |
| 174 | return dir.path(rocks_dir(tree), name, version, "doc") | 166 | return dir.path(path.rocks_dir(tree), name, version, "doc") |
| 175 | end | 167 | end |
| 176 | 168 | ||
| 177 | --- Get the local installation directory for configuration files of a package. | 169 | --- Get the local installation directory for configuration files of a package. |
| @@ -180,11 +172,11 @@ end | |||
| 180 | -- @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. |
| 181 | -- @return string: The resulting path -- does not guarantee that | 173 | -- @return string: The resulting path -- does not guarantee that |
| 182 | -- the package (and by extension, the path) exists. | 174 | -- the package (and by extension, the path) exists. |
| 183 | function conf_dir(name, version, tree) | 175 | function path.conf_dir(name, version, tree) |
| 184 | assert(type(name) == "string") | 176 | assert(type(name) == "string") |
| 185 | assert(type(version) == "string") | 177 | assert(type(version) == "string") |
| 186 | tree = tree or cfg.root_dir | 178 | tree = tree or cfg.root_dir |
| 187 | return dir.path(rocks_dir(tree), name, version, "conf") | 179 | return dir.path(path.rocks_dir(tree), name, version, "conf") |
| 188 | end | 180 | end |
| 189 | 181 | ||
| 190 | --- Get the local installation directory for command-line scripts | 182 | --- Get the local installation directory for command-line scripts |
| @@ -194,11 +186,11 @@ end | |||
| 194 | -- @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. |
| 195 | -- @return string: The resulting path -- does not guarantee that | 187 | -- @return string: The resulting path -- does not guarantee that |
| 196 | -- the package (and by extension, the path) exists. | 188 | -- the package (and by extension, the path) exists. |
| 197 | function bin_dir(name, version, tree) | 189 | function path.bin_dir(name, version, tree) |
| 198 | assert(type(name) == "string") | 190 | assert(type(name) == "string") |
| 199 | assert(type(version) == "string") | 191 | assert(type(version) == "string") |
| 200 | tree = tree or cfg.root_dir | 192 | tree = tree or cfg.root_dir |
| 201 | return dir.path(rocks_dir(tree), name, version, "bin") | 193 | return dir.path(path.rocks_dir(tree), name, version, "bin") |
| 202 | end | 194 | end |
| 203 | 195 | ||
| 204 | --- Extract name, version and arch of a rock filename, | 196 | --- Extract name, version and arch of a rock filename, |
| @@ -206,7 +198,7 @@ end | |||
| 206 | -- @param file_name string: pathname of a rock or rockspec | 198 | -- @param file_name string: pathname of a rock or rockspec |
| 207 | -- @return (string, string, string) or nil: name, version and arch | 199 | -- @return (string, string, string) or nil: name, version and arch |
| 208 | -- or nil if name could not be parsed | 200 | -- or nil if name could not be parsed |
| 209 | function parse_name(file_name) | 201 | function path.parse_name(file_name) |
| 210 | assert(type(file_name) == "string") | 202 | assert(type(file_name) == "string") |
| 211 | if file_name:match("%.rock$") then | 203 | if file_name:match("%.rock$") then |
| 212 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") | 204 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") |
| @@ -221,7 +213,7 @@ end | |||
| 221 | -- @param version string: Package version. | 213 | -- @param version string: Package version. |
| 222 | -- @param arch string: Architecture identifier, or "rockspec" or "installed". | 214 | -- @param arch string: Architecture identifier, or "rockspec" or "installed". |
| 223 | -- @return string: A URL or pathname following LuaRocks naming conventions. | 215 | -- @return string: A URL or pathname following LuaRocks naming conventions. |
| 224 | function make_url(pathname, name, version, arch) | 216 | function path.make_url(pathname, name, version, arch) |
| 225 | assert(type(pathname) == "string") | 217 | assert(type(pathname) == "string") |
| 226 | assert(type(name) == "string") | 218 | assert(type(name) == "string") |
| 227 | assert(type(version) == "string") | 219 | assert(type(version) == "string") |
| @@ -245,7 +237,7 @@ end | |||
| 245 | -- @return string: The module identifier, or nil if given path is | 237 | -- @return string: The module identifier, or nil if given path is |
| 246 | -- 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 |
| 247 | -- path actually exists). | 239 | -- path actually exists). |
| 248 | function path_to_module(file) | 240 | function path.path_to_module(file) |
| 249 | assert(type(file) == "string") | 241 | assert(type(file) == "string") |
| 250 | 242 | ||
| 251 | local name = file:match("(.*)%."..cfg.lua_extension.."$") | 243 | local name = file:match("(.*)%."..cfg.lua_extension.."$") |
| @@ -270,7 +262,7 @@ end | |||
| 270 | -- For example, on Unix, "foo.bar.baz" will return "foo/bar". | 262 | -- For example, on Unix, "foo.bar.baz" will return "foo/bar". |
| 271 | -- @param mod string: A module name in Lua dot-separated format. | 263 | -- @param mod string: A module name in Lua dot-separated format. |
| 272 | -- @return string: A directory name using the platform's separator. | 264 | -- @return string: A directory name using the platform's separator. |
| 273 | function module_to_path(mod) | 265 | function path.module_to_path(mod) |
| 274 | assert(type(mod) == "string") | 266 | assert(type(mod) == "string") |
| 275 | return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) | 267 | return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) |
| 276 | end | 268 | end |
| @@ -279,19 +271,19 @@ end | |||
| 279 | -- Create a "variables" table in the rockspec table, containing | 271 | -- Create a "variables" table in the rockspec table, containing |
| 280 | -- adjusted variables according to the configuration file. | 272 | -- adjusted variables according to the configuration file. |
| 281 | -- @param rockspec table: The rockspec table. | 273 | -- @param rockspec table: The rockspec table. |
| 282 | function configure_paths(rockspec) | 274 | function path.configure_paths(rockspec) |
| 283 | assert(type(rockspec) == "table") | 275 | assert(type(rockspec) == "table") |
| 284 | local vars = {} | 276 | local vars = {} |
| 285 | for k,v in pairs(cfg.variables) do | 277 | for k,v in pairs(cfg.variables) do |
| 286 | vars[k] = v | 278 | vars[k] = v |
| 287 | end | 279 | end |
| 288 | local name, version = rockspec.name, rockspec.version | 280 | local name, version = rockspec.name, rockspec.version |
| 289 | vars.PREFIX = install_dir(name, version) | 281 | vars.PREFIX = path.install_dir(name, version) |
| 290 | vars.LUADIR = lua_dir(name, version) | 282 | vars.LUADIR = path.lua_dir(name, version) |
| 291 | vars.LIBDIR = lib_dir(name, version) | 283 | vars.LIBDIR = path.lib_dir(name, version) |
| 292 | vars.CONFDIR = conf_dir(name, version) | 284 | vars.CONFDIR = path.conf_dir(name, version) |
| 293 | vars.BINDIR = bin_dir(name, version) | 285 | vars.BINDIR = path.bin_dir(name, version) |
| 294 | vars.DOCDIR = doc_dir(name, version) | 286 | vars.DOCDIR = path.doc_dir(name, version) |
| 295 | rockspec.variables = vars | 287 | rockspec.variables = vars |
| 296 | end | 288 | end |
| 297 | 289 | ||
| @@ -301,7 +293,7 @@ end | |||
| 301 | -- @param name string: Rock name | 293 | -- @param name string: Rock name |
| 302 | -- @param version string: Rock version | 294 | -- @param version string: Rock version |
| 303 | -- @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. |
| 304 | function versioned_name(file, prefix, name, version) | 296 | function path.versioned_name(file, prefix, name, version) |
| 305 | assert(type(file) == "string") | 297 | assert(type(file) == "string") |
| 306 | assert(type(name) == "string") | 298 | assert(type(name) == "string") |
| 307 | assert(type(version) == "string") | 299 | assert(type(version) == "string") |
| @@ -311,12 +303,12 @@ function versioned_name(file, prefix, name, version) | |||
| 311 | return dir.path(prefix, name_version.."-"..rest) | 303 | return dir.path(prefix, name_version.."-"..rest) |
| 312 | end | 304 | end |
| 313 | 305 | ||
| 314 | function use_tree(tree) | 306 | function path.use_tree(tree) |
| 315 | cfg.root_dir = tree | 307 | cfg.root_dir = tree |
| 316 | cfg.rocks_dir = rocks_dir(tree) | 308 | cfg.rocks_dir = path.rocks_dir(tree) |
| 317 | cfg.deploy_bin_dir = deploy_bin_dir(tree) | 309 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) |
| 318 | cfg.deploy_lua_dir = deploy_lua_dir(tree) | 310 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) |
| 319 | cfg.deploy_lib_dir = deploy_lib_dir(tree) | 311 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) |
| 320 | end | 312 | end |
| 321 | 313 | ||
| 322 | --- 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. |
| @@ -326,7 +318,7 @@ end | |||
| 326 | -- @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 |
| 327 | -- 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. |
| 328 | -- @return a table with all results of invocations of fn collected. | 320 | -- @return a table with all results of invocations of fn collected. |
| 329 | function map_trees(deps_mode, fn, ...) | 321 | function path.map_trees(deps_mode, fn, ...) |
| 330 | local result = {} | 322 | local result = {} |
| 331 | if deps_mode == "one" then | 323 | if deps_mode == "one" then |
| 332 | table.insert(result, (fn(cfg.root_dir, ...)) or 0) | 324 | table.insert(result, (fn(cfg.root_dir, ...)) or 0) |
| @@ -336,7 +328,7 @@ function map_trees(deps_mode, fn, ...) | |||
| 336 | use = true | 328 | use = true |
| 337 | end | 329 | end |
| 338 | for _, tree in ipairs(cfg.rocks_trees) do | 330 | for _, tree in ipairs(cfg.rocks_trees) do |
| 339 | 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 |
| 340 | use = true | 332 | use = true |
| 341 | end | 333 | end |
| 342 | if use then | 334 | if use then |
| @@ -355,17 +347,17 @@ end | |||
| 355 | -- @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. |
| 356 | -- 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. |
| 357 | -- @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") |
| 358 | function which_i(module_name, name, version, tree, i) | 350 | function path.which_i(module_name, name, version, tree, i) |
| 359 | local deploy_dir | 351 | local deploy_dir |
| 360 | if module_name:match("%.lua$") then | 352 | if module_name:match("%.lua$") then |
| 361 | deploy_dir = deploy_lua_dir(tree) | 353 | deploy_dir = path.deploy_lua_dir(tree) |
| 362 | module_name = dir.path(deploy_dir, module_name) | 354 | module_name = dir.path(deploy_dir, module_name) |
| 363 | else | 355 | else |
| 364 | deploy_dir = deploy_lib_dir(tree) | 356 | deploy_dir = path.deploy_lib_dir(tree) |
| 365 | module_name = dir.path(deploy_dir, module_name) | 357 | module_name = dir.path(deploy_dir, module_name) |
| 366 | end | 358 | end |
| 367 | if i > 1 then | 359 | if i > 1 then |
| 368 | module_name = versioned_name(module_name, deploy_dir, name, version) | 360 | module_name = path.versioned_name(module_name, deploy_dir, name, version) |
| 369 | end | 361 | end |
| 370 | return module_name | 362 | return module_name |
| 371 | end | 363 | end |
| @@ -379,53 +371,15 @@ end | |||
| 379 | -- @param tree string: repository path (eg. "/usr/local") | 371 | -- @param tree string: repository path (eg. "/usr/local") |
| 380 | -- @param manifest table: the manifest table for the tree. | 372 | -- @param manifest table: the manifest table for the tree. |
| 381 | -- @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") |
| 382 | function which(module_name, filename, name, version, tree, manifest) | 374 | function path.which(module_name, filename, name, version, tree, manifest) |
| 383 | local versions = manifest.modules[module_name] | 375 | local versions = manifest.modules[module_name] |
| 384 | assert(versions) | 376 | assert(versions) |
| 385 | for i, name_version in ipairs(versions) do | 377 | for i, name_version in ipairs(versions) do |
| 386 | if name_version == name.."/"..version then | 378 | if name_version == name.."/"..version then |
| 387 | return which_i(filename, name, version, tree, i):gsub("//", "/") | 379 | return path.which_i(filename, name, version, tree, i):gsub("//", "/") |
| 388 | end | 380 | end |
| 389 | end | 381 | end |
| 390 | assert(false) | 382 | assert(false) |
| 391 | end | 383 | end |
| 392 | 384 | ||
| 393 | --- Driver function for "path" command. | 385 | return path |
| 394 | -- @return boolean This function always succeeds. | ||
| 395 | function run(...) | ||
| 396 | local flags = util.parse_flags(...) | ||
| 397 | local deps_mode = deps.get_deps_mode(flags) | ||
| 398 | |||
| 399 | local lr_path, lr_cpath = cfg.package_paths() | ||
| 400 | local bin_dirs = map_trees(deps_mode, deploy_bin_dir) | ||
| 401 | |||
| 402 | if flags["lr-path"] then | ||
| 403 | util.printout(util.remove_path_dupes(lr_path, ';')) | ||
| 404 | return true | ||
| 405 | elseif flags["lr-cpath"] then | ||
| 406 | util.printout(util.remove_path_dupes(lr_cpath, ';')) | ||
| 407 | return true | ||
| 408 | elseif flags["lr-bin"] then | ||
| 409 | local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) | ||
| 410 | util.printout(util.remove_path_dupes(lr_bin, ';')) | ||
| 411 | return true | ||
| 412 | end | ||
| 413 | |||
| 414 | if flags["append"] then | ||
| 415 | lr_path = package.path .. ";" .. lr_path | ||
| 416 | lr_cpath = package.cpath .. ";" .. lr_cpath | ||
| 417 | else | ||
| 418 | lr_path = lr_path.. ";" .. package.path | ||
| 419 | lr_cpath = lr_cpath .. ";" .. package.cpath | ||
| 420 | end | ||
| 421 | |||
| 422 | util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))) | ||
| 423 | util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))) | ||
| 424 | if flags["bin"] then | ||
| 425 | table.insert(bin_dirs, 1, os.getenv("PATH")) | ||
| 426 | local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) | ||
| 427 | util.printout(cfg.export_path:format(lr_bin)) | ||
| 428 | end | ||
| 429 | return true | ||
| 430 | end | ||
| 431 | |||
diff --git a/src/luarocks/path_command.lua b/src/luarocks/path_command.lua new file mode 100644 index 00000000..4e52bdc9 --- /dev/null +++ b/src/luarocks/path_command.lua | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | |||
| 2 | --- Module implementing the LuaRocks "path" command. | ||
| 3 | -- Return the currently configured package path. | ||
| 4 | local path_command = {} | ||
| 5 | |||
| 6 | local path = require("luarocks.path") | ||
| 7 | local cfg = require("luarocks.cfg") | ||
| 8 | local util = require("luarocks.util") | ||
| 9 | local deps = require("luarocks.deps") | ||
| 10 | |||
| 11 | path_command.help_summary = "Return the currently configured package path." | ||
| 12 | path_command.help_arguments = "" | ||
| 13 | path_command.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 | --- Driver function for "path" command. | ||
| 20 | -- @return boolean This function always succeeds. | ||
| 21 | function path_command.run(...) | ||
| 22 | local flags = util.parse_flags(...) | ||
| 23 | local deps_mode = deps.get_deps_mode(flags) | ||
| 24 | |||
| 25 | local lr_path, lr_cpath = cfg.package_paths() | ||
| 26 | local bin_dirs = path.map_trees(deps_mode, path.deploy_bin_dir) | ||
| 27 | |||
| 28 | if flags["lr-path"] then | ||
| 29 | util.printout(util.remove_path_dupes(lr_path, ';')) | ||
| 30 | return true | ||
| 31 | elseif flags["lr-cpath"] then | ||
| 32 | util.printout(util.remove_path_dupes(lr_cpath, ';')) | ||
| 33 | return true | ||
| 34 | elseif flags["lr-bin"] then | ||
| 35 | local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) | ||
| 36 | util.printout(util.remove_path_dupes(lr_bin, ';')) | ||
| 37 | return true | ||
| 38 | end | ||
| 39 | |||
| 40 | if flags["append"] then | ||
| 41 | lr_path = package.path .. ";" .. lr_path | ||
| 42 | lr_cpath = package.cpath .. ";" .. lr_cpath | ||
| 43 | else | ||
| 44 | lr_path = lr_path.. ";" .. package.path | ||
| 45 | lr_cpath = lr_cpath .. ";" .. package.cpath | ||
| 46 | end | ||
| 47 | |||
| 48 | util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))) | ||
| 49 | util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))) | ||
| 50 | if flags["bin"] then | ||
| 51 | table.insert(bin_dirs, 1, os.getenv("PATH")) | ||
| 52 | local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) | ||
| 53 | util.printout(cfg.export_path:format(lr_bin)) | ||
| 54 | end | ||
| 55 | return true | ||
| 56 | end | ||
| 57 | |||
| 58 | return path_command | ||
