aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:49:00 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commit259b4ae048616d5a8dc92fc3e299796e2abafe89 (patch)
tree3be5cda02f373cae285ff14c9868b1b0a97d150d
parent55e67af4ef25d83432a8ccdb40baea10137f9e59 (diff)
downloadluarocks-259b4ae048616d5a8dc92fc3e299796e2abafe89.tar.gz
luarocks-259b4ae048616d5a8dc92fc3e299796e2abafe89.tar.bz2
luarocks-259b4ae048616d5a8dc92fc3e299796e2abafe89.zip
Teal: convert luarocks.cmd.make
-rw-r--r--src/luarocks/cmd/make.tl (renamed from src/luarocks/cmd/make.lua)51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.tl
index ffec8c5d..13b1d66b 100644
--- a/src/luarocks/cmd/make.lua
+++ b/src/luarocks/cmd/make.tl
@@ -3,7 +3,9 @@
3-- Builds sources in the current directory, but unlike "build", 3-- Builds sources in the current directory, but unlike "build",
4-- it does not fetch sources, etc., assuming everything is 4-- it does not fetch sources, etc., assuming everything is
5-- available in the current directory. 5-- available in the current directory.
6local make = {} 6local record make
7 needs_lock: function(Args): boolean
8end
7 9
8local build = require("luarocks.build") 10local build = require("luarocks.build")
9local util = require("luarocks.util") 11local util = require("luarocks.util")
@@ -12,11 +14,16 @@ local fetch = require("luarocks.fetch")
12local pack = require("luarocks.pack") 14local pack = require("luarocks.pack")
13local remove = require("luarocks.remove") 15local remove = require("luarocks.remove")
14local deps = require("luarocks.deps") 16local deps = require("luarocks.deps")
15local writer = require("luarocks.manif.writer")
16local dir = require("luarocks.dir") 17local dir = require("luarocks.dir")
17local fs = require("luarocks.fs") 18local fs = require("luarocks.fs")
18 19
19function make.cmd_options(parser) 20local type Parser = require("luarocks.vendor.argparse").Parser
21
22local type Args = require("luarocks.core.types.args").Args
23
24local type BOpts = require("luarocks.core.types.bopts").BOpts
25
26function make.cmd_options(parser: Parser)
20 parser:flag("--no-install", "Do not install the rock.") 27 parser:flag("--no-install", "Do not install the rock.")
21 parser:flag("--no-doc", "Install the rock without its documentation.") 28 parser:flag("--no-doc", "Install the rock without its documentation.")
22 parser:flag("--pack-binary-rock", "Do not install rock. Instead, produce a ".. 29 parser:flag("--pack-binary-rock", "Do not install rock. Instead, produce a "..
@@ -33,7 +40,7 @@ function make.cmd_options(parser)
33 "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. 40 "built. If the rockspec or src.rock is being downloaded, LuaRocks will "..
34 "attempt to download the signature as well. Otherwise, the signature ".. 41 "attempt to download the signature as well. Otherwise, the signature "..
35 "file should be already available locally in the same directory.\n".. 42 "file should be already available locally in the same directory.\n"..
36 "You need the signers public key in your local keyring for this ".. 43 "You need the signer's public key in your local keyring for this "..
37 "option to work properly.") 44 "option to work properly.")
38 parser:flag("--sign", "To be used with --pack-binary-rock. Also produce a ".. 45 parser:flag("--sign", "To be used with --pack-binary-rock. Also produce a "..
39 "signature file for the generated .rock file.") 46 "signature file for the generated .rock file.")
@@ -46,7 +53,7 @@ function make.cmd_options(parser)
46 util.deps_mode_option(parser) 53 util.deps_mode_option(parser)
47end 54end
48 55
49function make.add_to_parser(parser) 56function make.add_to_parser(parser: Parser)
50 -- luacheck: push ignore 431 57 -- luacheck: push ignore 431
51 local cmd = parser:command("make", [[ 58 local cmd = parser:command("make", [[
52Builds sources in the current directory, but unlike "build", it does not fetch 59Builds sources in the current directory, but unlike "build", it does not fetch
@@ -71,16 +78,17 @@ overrides and recreates this file scanning dependency based on ranges.
71 cmd:argument("rockspec", "Rockspec for the rock to build.") 78 cmd:argument("rockspec", "Rockspec for the rock to build.")
72 :args("?") 79 :args("?")
73 80
74 make.cmd_options(cmd) 81 make.cmd_options(cmd as Parser)
75end 82end
76 83
77--- Driver function for "make" command. 84--- Driver function for "make" command.
78-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an 85-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
79-- error message otherwise. exitcode is optionally returned. 86-- error message otherwise. exitcode is optionally returned.
80function make.command(args) 87function make.command(args: Args): boolean, string
88 local name, namespace, version: string, string, string
81 local rockspec_filename = args.rockspec 89 local rockspec_filename = args.rockspec
82 if not rockspec_filename then 90 if not rockspec_filename then
83 local err 91 local err: string
84 rockspec_filename, err = util.get_default_rockspec() 92 rockspec_filename, err = util.get_default_rockspec()
85 if not rockspec_filename then 93 if not rockspec_filename then
86 return nil, err 94 return nil, err
@@ -96,10 +104,10 @@ function make.command(args)
96 return nil, err 104 return nil, err
97 end 105 end
98 106
99 local name, namespace = util.split_namespace(rockspec.name) 107 name, namespace = util.split_namespace(rockspec.name)
100 namespace = namespace or args.namespace 108 namespace = namespace or args.namespace
101 109
102 local opts = build.opts({ 110 local opts: BOpts = {
103 need_to_fetch = false, 111 need_to_fetch = false,
104 minimal_mode = true, 112 minimal_mode = true,
105 deps_mode = deps.get_deps_mode(args), 113 deps_mode = deps.get_deps_mode(args),
@@ -111,17 +119,22 @@ function make.command(args)
111 pin = not not args.pin, 119 pin = not not args.pin,
112 rebuild = true, 120 rebuild = true,
113 no_install = not not args.no_install 121 no_install = not not args.no_install
114 }) 122 }
115 123
116 if args.sign and not args.pack_binary_rock then 124 if args.sign and not args.pack_binary_rock then
117 return nil, "In the make command, --sign is meant to be used only with --pack-binary-rock" 125 return nil, "In the make command, --sign is meant to be used only with --pack-binary-rock"
118 end 126 end
119 127
120 if args.no_install then 128 if args.no_install then
121 return build.build_rockspec(rockspec, opts, cwd) 129 name, version = build.build_rockspec(rockspec, opts, cwd)
130 if name then
131 return true
132 else
133 return nil, version
134 end
122 elseif args.pack_binary_rock then 135 elseif args.pack_binary_rock then
123 return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function() 136 return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function(): string, string
124 local name, version = build.build_rockspec(rockspec, opts, cwd) -- luacheck: ignore 431 137 name, version = build.build_rockspec(rockspec, opts, cwd) -- luacheck: ignore 431
125 if name and args.no_doc then 138 if name and args.no_doc then
126 util.remove_doc_dir(name, version) 139 util.remove_doc_dir(name, version)
127 end 140 end
@@ -130,12 +143,12 @@ function make.command(args)
130 else 143 else
131 local ok, err = build.build_rockspec(rockspec, opts, cwd) 144 local ok, err = build.build_rockspec(rockspec, opts, cwd)
132 if not ok then return nil, err end 145 if not ok then return nil, err end
133 local name, version = ok, err -- luacheck: ignore 421 146 name, version = ok, err -- luacheck: ignore 421
134 147
135 if opts.build_only_deps then 148 if opts.build_only_deps then
136 util.printout("Stopping after installing dependencies for " ..name.." "..version) 149 util.printout("Stopping after installing dependencies for " ..name.." "..version)
137 util.printout() 150 util.printout()
138 return name, version 151 return name ~= nil, version
139 end 152 end
140 153
141 if args.no_doc then 154 if args.no_doc then
@@ -151,12 +164,12 @@ function make.command(args)
151 end 164 end
152 end 165 end
153 166
154 writer.check_dependencies(nil, deps.get_deps_mode(args)) 167 deps.check_dependencies(nil, deps.get_deps_mode(args))
155 return name, version 168 return name ~= nil, version
156 end 169 end
157end 170end
158 171
159make.needs_lock = function(args) 172make.needs_lock = function(args: Args): boolean
160 if args.pack_binary_rock or args.no_install then 173 if args.pack_binary_rock or args.no_install then
161 return false 174 return false
162 end 175 end