aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:49:02 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commitedd7bd5093060a37ea82628b309b766148bf4014 (patch)
treecab2761a0673cc68143609312ad3a1ac02a02571
parentcc5723ecad8db0b1ffbd4c85d265d54287e0c732 (diff)
downloadluarocks-edd7bd5093060a37ea82628b309b766148bf4014.tar.gz
luarocks-edd7bd5093060a37ea82628b309b766148bf4014.tar.bz2
luarocks-edd7bd5093060a37ea82628b309b766148bf4014.zip
Teal: convert luarocks.cmd.build
-rw-r--r--src/luarocks/cmd/build.tl (renamed from src/luarocks/cmd/build.lua)61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.tl
index 8049596f..c8d6a579 100644
--- a/src/luarocks/cmd/build.lua
+++ b/src/luarocks/cmd/build.tl
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "build" command. 2--- Module implementing the LuaRocks "build" command.
3-- Builds a rock, compiling its C parts if any. 3-- Builds a rock, compiling its C parts if any.
4local cmd_build = {} 4local record cmd_build
5 needs_lock: function(Args): boolean
6end
5 7
6local pack = require("luarocks.pack") 8local pack = require("luarocks.pack")
7local path = require("luarocks.path") 9local path = require("luarocks.path")
@@ -13,12 +15,19 @@ local deps = require("luarocks.deps")
13local remove = require("luarocks.remove") 15local remove = require("luarocks.remove")
14local cfg = require("luarocks.core.cfg") 16local cfg = require("luarocks.core.cfg")
15local build = require("luarocks.build") 17local build = require("luarocks.build")
16local writer = require("luarocks.manif.writer")
17local search = require("luarocks.search") 18local search = require("luarocks.search")
18local make = require("luarocks.cmd.make") 19local make = require("luarocks.cmd.make")
19local repos = require("luarocks.repos") 20local repos = require("luarocks.repos")
20 21
21function cmd_build.add_to_parser(parser) 22local type Parser = require("luarocks.vendor.argparse").Parser
23
24local type Args = require("luarocks.core.types.args").Args
25
26local type BOpts = require("luarocks.core.types.bopts").BOpts
27
28local type Rockspec = require("luarocks.core.types.rockspec").Rockspec
29
30function cmd_build.add_to_parser(parser: Parser)
22 local cmd = parser:command("build", "Build and install a rock, compiling its C parts if any.\n".. -- luacheck: ignore 431 31 local cmd = parser:command("build", "Build and install a rock, compiling its C parts if any.\n".. -- luacheck: ignore 431
23 "If the sources contain a luarocks.lock file, uses it as an authoritative source for ".. 32 "If the sources contain a luarocks.lock file, uses it as an authoritative source for "..
24 "exact version of dependencies.\n".. 33 "exact version of dependencies.\n"..
@@ -41,7 +50,7 @@ function cmd_build.add_to_parser(parser)
41 "versions of each dependency found for this rock (recursively), ".. 50 "versions of each dependency found for this rock (recursively), "..
42 "and store it in the rock's directory. ".. 51 "and store it in the rock's directory. "..
43 "Ignores any existing luarocks.lock file in the rock's sources.") 52 "Ignores any existing luarocks.lock file in the rock's sources.")
44 make.cmd_options(cmd) 53 make.cmd_options(cmd as Parser)
45end 54end
46 55
47--- Build and install a rock. 56--- Build and install a rock.
@@ -49,15 +58,13 @@ end
49-- @param opts table: build options 58-- @param opts table: build options
50-- @return boolean or (nil, string, [string]): True if build was successful, 59-- @return boolean or (nil, string, [string]): True if build was successful,
51-- or false and an error message and an optional error code. 60-- or false and an error message and an optional error code.
52local function build_rock(rock_filename, opts) 61local function build_rock(rock_filename: string, opts: BOpts): boolean, string, string
53 assert(type(rock_filename) == "string")
54 assert(opts:type() == "build.opts")
55 62
56 local cwd = fs.absolute_name(dir.path(".")) 63 local cwd = fs.absolute_name(dir.path("."))
57 64
58 local ok, err, errcode 65 local ok, err, errcode: boolean, string, string
59 66
60 local unpack_dir 67 local unpack_dir: string
61 unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_filename, nil, opts.verify) 68 unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_filename, nil, opts.verify)
62 if not unpack_dir then 69 if not unpack_dir then
63 return nil, err, errcode 70 return nil, err, errcode
@@ -68,25 +75,23 @@ local function build_rock(rock_filename, opts)
68 ok, err = fs.change_dir(unpack_dir) 75 ok, err = fs.change_dir(unpack_dir)
69 if not ok then return nil, err end 76 if not ok then return nil, err end
70 77
71 local rockspec 78 local rockspec: Rockspec
72 rockspec, err, errcode = fetch.load_rockspec(rockspec_filename) 79 rockspec, err, errcode = fetch.load_rockspec(rockspec_filename)
73 if not rockspec then 80 if not rockspec then
74 return nil, err, errcode 81 return nil, err, errcode
75 end 82 end
76 83
77 ok, err, errcode = build.build_rockspec(rockspec, opts, cwd) 84 local n, v = build.build_rockspec(rockspec, opts, cwd)
85
86 ok, err, errcode = n ~= nil, v, nil
78 87
79 fs.pop_dir() 88 fs.pop_dir()
80 return ok, err, errcode 89 return ok, err, errcode
81end 90end
82 91
83local function do_build(name, namespace, version, opts) 92local function do_build(name: string, namespace: string, version: string, opts: BOpts): string, string, string
84 assert(type(name) == "string")
85 assert(type(namespace) == "string" or not namespace)
86 assert(version == nil or type(version) == "string")
87 assert(opts:type() == "build.opts")
88 93
89 local url, err 94 local url, err: string, string
90 if name:match("%.rockspec$") or name:match("%.rock$") then 95 if name:match("%.rockspec$") or name:match("%.rock$") then
91 url = name 96 url = name
92 else 97 else
@@ -118,7 +123,11 @@ local function do_build(name, namespace, version, opts)
118 opts.need_to_fetch = false 123 opts.need_to_fetch = false
119 end 124 end
120 125
121 return build_rock(url, opts) 126 local ok, err, errcode = build_rock(url, opts)
127 if not ok then
128 return nil, err, errcode
129 end
130 return name, version
122end 131end
123 132
124--- Driver function for "build" command. 133--- Driver function for "build" command.
@@ -127,12 +136,12 @@ end
127-- When passing a package name, a version number may also be given. 136-- When passing a package name, a version number may also be given.
128-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an 137-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
129-- error message otherwise. exitcode is optionally returned. 138-- error message otherwise. exitcode is optionally returned.
130function cmd_build.command(args) 139function cmd_build.command(args: Args): boolean, string, string
131 if not args.rock then 140 if not args.rock then
132 return make.command(args) 141 return make.command(args)
133 end 142 end
134 143
135 local opts = build.opts({ 144 local opts = {
136 need_to_fetch = true, 145 need_to_fetch = true,
137 minimal_mode = false, 146 minimal_mode = false,
138 deps_mode = deps.get_deps_mode(args), 147 deps_mode = deps.get_deps_mode(args),
@@ -144,14 +153,14 @@ function cmd_build.command(args)
144 pin = not not args.pin, 153 pin = not not args.pin,
145 rebuild = not not (args.force or args.force_fast), 154 rebuild = not not (args.force or args.force_fast),
146 no_install = false 155 no_install = false
147 }) 156 }
148 157
149 if args.sign and not args.pack_binary_rock then 158 if args.sign and not args.pack_binary_rock then
150 return nil, "In the build command, --sign is meant to be used only with --pack-binary-rock" 159 return nil, "In the build command, --sign is meant to be used only with --pack-binary-rock"
151 end 160 end
152 161
153 if args.pack_binary_rock then 162 if args.pack_binary_rock then
154 return pack.pack_binary_rock(args.rock, args.namespace, args.version, args.sign, function() 163 return pack.pack_binary_rock(args.rock, args.namespace, args.version, args.sign, function(): string, string
155 local name, version = do_build(args.rock, args.namespace, args.version, opts) 164 local name, version = do_build(args.rock, args.namespace, args.version, opts)
156 if name and args.no_doc then 165 if name and args.no_doc then
157 util.remove_doc_dir(name, version) 166 util.remove_doc_dir(name, version)
@@ -165,7 +174,7 @@ function cmd_build.command(args)
165 return nil, version 174 return nil, version
166 end 175 end
167 if skip == "skip" then 176 if skip == "skip" then
168 return name, version 177 return name ~= nil, version
169 end 178 end
170 179
171 if args.no_doc then 180 if args.no_doc then
@@ -187,12 +196,12 @@ function cmd_build.command(args)
187 end 196 end
188 197
189 if opts.deps_mode ~= "none" then 198 if opts.deps_mode ~= "none" then
190 writer.check_dependencies(nil, deps.get_deps_mode(args)) 199 deps.check_dependencies(nil, deps.get_deps_mode(args))
191 end 200 end
192 return name, version 201 return name ~= nil, version
193end 202end
194 203
195cmd_build.needs_lock = function(args) 204cmd_build.needs_lock = function(args: Args): boolean
196 if args.pack_binary_rock then 205 if args.pack_binary_rock then
197 return false 206 return false
198 end 207 end