diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:01 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | 98e9f4a233c12136d8ae1231c7e3263240cc7e4a (patch) | |
| tree | a765ed039a5516ddc71ed2cc8d4c52edec1705c3 /src | |
| parent | 59be57e5478b657b826e4a2865e58481ccb5a474 (diff) | |
| download | luarocks-98e9f4a233c12136d8ae1231c7e3263240cc7e4a.tar.gz luarocks-98e9f4a233c12136d8ae1231c7e3263240cc7e4a.tar.bz2 luarocks-98e9f4a233c12136d8ae1231c7e3263240cc7e4a.zip | |
Teal: convert luarocks.cmd.install
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/install.tl (renamed from src/luarocks/cmd/install.lua) | 87 |
1 files changed, 36 insertions, 51 deletions
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.tl index c3b5f811..943afdba 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.tl | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | --- Module implementing the LuaRocks "install" command. | 1 | --- Module implementing the LuaRocks "install" command. |
| 2 | -- Installs binary rocks. | 2 | -- Installs binary rocks. |
| 3 | local install = {} | 3 | local record install |
| 4 | needs_lock: function(Args): boolean | ||
| 5 | end | ||
| 4 | 6 | ||
| 5 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
| 6 | local path = require("luarocks.path") | 8 | local path = require("luarocks.path") |
| @@ -9,13 +11,20 @@ local fetch = require("luarocks.fetch") | |||
| 9 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
| 10 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
| 11 | local deps = require("luarocks.deps") | 13 | local deps = require("luarocks.deps") |
| 12 | local writer = require("luarocks.manif.writer") | 14 | local repo_writer = require("luarocks.repo_writer") |
| 13 | local remove = require("luarocks.remove") | 15 | local remove = require("luarocks.remove") |
| 14 | local search = require("luarocks.search") | 16 | local search = require("luarocks.search") |
| 15 | local queries = require("luarocks.queries") | 17 | local queries = require("luarocks.queries") |
| 16 | local cfg = require("luarocks.core.cfg") | 18 | local cfg = require("luarocks.core.cfg") |
| 17 | 19 | ||
| 18 | function install.add_to_parser(parser) | 20 | local type Parser = require("luarocks.vendor.argparse").Parser |
| 21 | |||
| 22 | local type Args = require("luarocks.core.types.args").Args | ||
| 23 | |||
| 24 | |||
| 25 | local type IOpts = require("luarocks.core.types.installs").IOpts | ||
| 26 | |||
| 27 | function install.add_to_parser(parser: Parser) | ||
| 19 | local cmd = parser:command("install", "Install a rock.", util.see_also()) -- luacheck: ignore 431 | 28 | local cmd = parser:command("install", "Install a rock.", util.see_also()) -- luacheck: ignore 431 |
| 20 | 29 | ||
| 21 | cmd:argument("rock", "The name of a rock to be fetched from a repository ".. | 30 | cmd:argument("rock", "The name of a rock to be fetched from a repository ".. |
| @@ -42,7 +51,7 @@ function install.add_to_parser(parser) | |||
| 42 | "option to work properly.") | 51 | "option to work properly.") |
| 43 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. | 52 | cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. |
| 44 | "and report if it is available for another Lua version.") | 53 | "and report if it is available for another Lua version.") |
| 45 | util.deps_mode_option(cmd) | 54 | util.deps_mode_option(cmd as Parser) |
| 46 | cmd:flag("--no-manifest", "Skip creating/updating the manifest") | 55 | cmd:flag("--no-manifest", "Skip creating/updating the manifest") |
| 47 | cmd:flag("--pin", "If the installed rock is a Lua module, create a ".. | 56 | cmd:flag("--pin", "If the installed rock is a Lua module, create a ".. |
| 48 | "luarocks.lock file listing the exact versions of each dependency found for ".. | 57 | "luarocks.lock file listing the exact versions of each dependency found for ".. |
| @@ -54,24 +63,13 @@ function install.add_to_parser(parser) | |||
| 54 | parser:flag("--sign"):hidden(true) | 63 | parser:flag("--sign"):hidden(true) |
| 55 | end | 64 | end |
| 56 | 65 | ||
| 57 | install.opts = util.opts_table("install.opts", { | ||
| 58 | namespace = "string?", | ||
| 59 | keep = "boolean", | ||
| 60 | force = "boolean", | ||
| 61 | force_fast = "boolean", | ||
| 62 | no_doc = "boolean", | ||
| 63 | deps_mode = "string", | ||
| 64 | verify = "boolean", | ||
| 65 | }) | ||
| 66 | 66 | ||
| 67 | --- Install a binary rock. | 67 | --- Install a binary rock. |
| 68 | -- @param rock_file string: local or remote filename of a rock. | 68 | -- @param rock_file string: local or remote filename of a rock. |
| 69 | -- @param opts table: installation options | 69 | -- @param opts table: installation options |
| 70 | -- @return (string, string) or (nil, string, [string]): Name and version of | 70 | -- @return (string, string) or (nil, string, [string]): Name and version of |
| 71 | -- installed rock if succeeded or nil and an error message followed by an error code. | 71 | -- installed rock if succeeded or nil and an error message followed by an error code. |
| 72 | function install.install_binary_rock(rock_file, opts) | 72 | function install.install_binary_rock(rock_file: string, opts: IOpts): string, string, string |
| 73 | assert(type(rock_file) == "string") | ||
| 74 | assert(opts:type() == "install.opts") | ||
| 75 | 73 | ||
| 76 | local namespace = opts.namespace | 74 | local namespace = opts.namespace |
| 77 | local deps_mode = opts.deps_mode | 75 | local deps_mode = opts.deps_mode |
| @@ -90,7 +88,7 @@ function install.install_binary_rock(rock_file, opts) | |||
| 90 | util.printout("Use --force to reinstall.") | 88 | util.printout("Use --force to reinstall.") |
| 91 | return name, version | 89 | return name, version |
| 92 | end | 90 | end |
| 93 | repos.delete_version(name, version, opts.deps_mode) | 91 | repo_writer.delete_version(name, version, opts.deps_mode) |
| 94 | end | 92 | end |
| 95 | 93 | ||
| 96 | local install_dir = path.install_dir(name, version) | 94 | local install_dir = path.install_dir(name, version) |
| @@ -99,9 +97,9 @@ function install.install_binary_rock(rock_file, opts) | |||
| 99 | fs.delete(install_dir) | 97 | fs.delete(install_dir) |
| 100 | fs.remove_dir_if_empty(path.versions_dir(name)) | 98 | fs.remove_dir_if_empty(path.versions_dir(name)) |
| 101 | end) | 99 | end) |
| 102 | 100 | local ok: boolean | |
| 103 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) | 101 | local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) |
| 104 | if not ok then return nil, err, errcode end | 102 | if not oks then return nil, err, errcode end |
| 105 | 103 | ||
| 106 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) | 104 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) |
| 107 | if err then | 105 | if err then |
| @@ -113,17 +111,6 @@ function install.install_binary_rock(rock_file, opts) | |||
| 113 | if err then return nil, err, errcode end | 111 | if err then return nil, err, errcode end |
| 114 | end | 112 | end |
| 115 | 113 | ||
| 116 | -- For compatibility with .rock files built with LuaRocks 1 | ||
| 117 | if not fs.exists(path.rock_manifest_file(name, version)) then | ||
| 118 | ok, err = writer.make_rock_manifest(name, version) | ||
| 119 | if err then return nil, err end | ||
| 120 | end | ||
| 121 | |||
| 122 | if namespace then | ||
| 123 | ok, err = writer.make_namespace_file(name, version, namespace) | ||
| 124 | if err then return nil, err end | ||
| 125 | end | ||
| 126 | |||
| 127 | if deps_mode ~= "none" then | 114 | if deps_mode ~= "none" then |
| 128 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) | 115 | local deplock_dir = fs.exists(dir.path(".", "luarocks.lock")) |
| 129 | and "." | 116 | and "." |
| @@ -132,12 +119,12 @@ function install.install_binary_rock(rock_file, opts) | |||
| 132 | if err then return nil, err, errcode end | 119 | if err then return nil, err, errcode end |
| 133 | end | 120 | end |
| 134 | 121 | ||
| 135 | ok, err = repos.deploy_files(name, version, repos.should_wrap_bin_scripts(rockspec), deps_mode) | 122 | ok, err = repo_writer.deploy_files(name, version, repos.should_wrap_bin_scripts(rockspec), deps_mode, namespace) |
| 136 | if err then return nil, err end | 123 | if err then return nil, err end |
| 137 | 124 | ||
| 138 | util.remove_scheduled_function(rollback) | 125 | util.remove_scheduled_function(rollback) |
| 139 | rollback = util.schedule_function(function() | 126 | rollback = util.schedule_function(function() |
| 140 | repos.delete_version(name, version, deps_mode) | 127 | repo_writer.delete_version(name, version, deps_mode) |
| 141 | end) | 128 | end) |
| 142 | 129 | ||
| 143 | ok, err = repos.run_hook(rockspec, "post_install") | 130 | ok, err = repos.run_hook(rockspec, "post_install") |
| @@ -154,9 +141,7 @@ end | |||
| 154 | -- @return (string, string) or (nil, string, [string]): Name and version of | 141 | -- @return (string, string) or (nil, string, [string]): Name and version of |
| 155 | -- the rock whose dependencies were installed if succeeded or nil and an error message | 142 | -- the rock whose dependencies were installed if succeeded or nil and an error message |
| 156 | -- followed by an error code. | 143 | -- followed by an error code. |
| 157 | function install.install_binary_rock_deps(rock_file, opts) | 144 | function install.install_binary_rock_deps(rock_file: string, opts: IOpts): string, string, string |
| 158 | assert(type(rock_file) == "string") | ||
| 159 | assert(opts:type() == "install.opts") | ||
| 160 | 145 | ||
| 161 | local name, version, arch = path.parse_name(rock_file) | 146 | local name, version, arch = path.parse_name(rock_file) |
| 162 | if not name then | 147 | if not name then |
| @@ -169,8 +154,9 @@ function install.install_binary_rock_deps(rock_file, opts) | |||
| 169 | 154 | ||
| 170 | local install_dir = path.install_dir(name, version) | 155 | local install_dir = path.install_dir(name, version) |
| 171 | 156 | ||
| 172 | local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) | 157 | local ok: boolean |
| 173 | if not ok then return nil, err, errcode end | 158 | local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) |
| 159 | if not oks then return nil, err, errcode end | ||
| 174 | 160 | ||
| 175 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) | 161 | local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) |
| 176 | if err then | 162 | if err then |
| @@ -189,19 +175,16 @@ function install.install_binary_rock_deps(rock_file, opts) | |||
| 189 | return name, version | 175 | return name, version |
| 190 | end | 176 | end |
| 191 | 177 | ||
| 192 | local function install_rock_file_deps(filename, opts) | 178 | local function install_rock_file_deps(filename: string, opts: IOpts): boolean, string |
| 193 | assert(opts:type() == "install.opts") | ||
| 194 | 179 | ||
| 195 | local name, version = install.install_binary_rock_deps(filename, opts) | 180 | local name, version = install.install_binary_rock_deps(filename, opts) |
| 196 | if not name then return nil, version end | 181 | if not name then return nil, version end |
| 197 | 182 | ||
| 198 | writer.check_dependencies(nil, opts.deps_mode) | 183 | deps.check_dependencies(nil, opts.deps_mode) |
| 199 | return name, version | 184 | return true |
| 200 | end | 185 | end |
| 201 | 186 | ||
| 202 | local function install_rock_file(filename, opts) | 187 | local function install_rock_file(filename: string, opts: IOpts): boolean, string |
| 203 | assert(type(filename) == "string") | ||
| 204 | assert(opts:type() == "install.opts") | ||
| 205 | 188 | ||
| 206 | local name, version = install.install_binary_rock(filename, opts) | 189 | local name, version = install.install_binary_rock(filename, opts) |
| 207 | if not name then return nil, version end | 190 | if not name then return nil, version end |
| @@ -219,8 +202,8 @@ local function install_rock_file(filename, opts) | |||
| 219 | end | 202 | end |
| 220 | end | 203 | end |
| 221 | 204 | ||
| 222 | writer.check_dependencies(nil, opts.deps_mode) | 205 | deps.check_dependencies(nil, opts.deps_mode) |
| 223 | return name, version | 206 | return true |
| 224 | end | 207 | end |
| 225 | 208 | ||
| 226 | --- Driver function for the "install" command. | 209 | --- Driver function for the "install" command. |
| @@ -231,13 +214,13 @@ end | |||
| 231 | -- if returned a result, installs the matching rock. | 214 | -- if returned a result, installs the matching rock. |
| 232 | -- @return boolean or (nil, string, exitcode): True if installation was | 215 | -- @return boolean or (nil, string, exitcode): True if installation was |
| 233 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | 216 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
| 234 | function install.command(args) | 217 | function install.command(args: Args): boolean, string, string |
| 235 | if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then | 218 | if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then |
| 236 | local build = require("luarocks.cmd.build") | 219 | local build = require("luarocks.cmd.build") |
| 237 | return build.command(args) | 220 | return build.command(args) |
| 238 | elseif args.rock:match("%.rock$") then | 221 | elseif args.rock:match("%.rock$") then |
| 239 | local deps_mode = deps.get_deps_mode(args) | 222 | local deps_mode = deps.get_deps_mode(args) |
| 240 | local opts = install.opts({ | 223 | local opts = { |
| 241 | namespace = args.namespace, | 224 | namespace = args.namespace, |
| 242 | keep = not not args.keep, | 225 | keep = not not args.keep, |
| 243 | force = not not args.force, | 226 | force = not not args.force, |
| @@ -245,7 +228,7 @@ function install.command(args) | |||
| 245 | no_doc = not not args.no_doc, | 228 | no_doc = not not args.no_doc, |
| 246 | deps_mode = deps_mode, | 229 | deps_mode = deps_mode, |
| 247 | verify = not not args.verify, | 230 | verify = not not args.verify, |
| 248 | }) | 231 | } |
| 249 | if args.only_deps then | 232 | if args.only_deps then |
| 250 | return install_rock_file_deps(args.rock, opts) | 233 | return install_rock_file_deps(args.rock, opts) |
| 251 | else | 234 | else |
| @@ -264,11 +247,13 @@ function install.command(args) | |||
| 264 | end | 247 | end |
| 265 | end | 248 | end |
| 266 | 249 | ||
| 267 | install.needs_lock = function(args) | 250 | install.needs_lock = function(args: Args): boolean |
| 268 | if args.pack_binary_rock then | 251 | if args.pack_binary_rock then |
| 269 | return false | 252 | return false |
| 270 | end | 253 | end |
| 271 | return true | 254 | return true |
| 272 | end | 255 | end |
| 273 | 256 | ||
| 257 | deps.installer = install.command | ||
| 258 | |||
| 274 | return install | 259 | return install |
