diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-21 11:56:09 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-21 11:56:09 +0300 |
commit | 016c5c90704ee6207bd100c0f4384254fd86d8c6 (patch) | |
tree | 9013952f7616b1f887f8ce8830ac1bcb44b64309 | |
parent | c9f088bc218c0c764a940f701132417b2bf896a0 (diff) | |
download | luarocks-016c5c90704ee6207bd100c0f4384254fd86d8c6.tar.gz luarocks-016c5c90704ee6207bd100c0f4384254fd86d8c6.tar.bz2 luarocks-016c5c90704ee6207bd100c0f4384254fd86d8c6.zip |
fix dynamic require workaround
-rw-r--r-- | src/luarocks/build.lua | 52 | ||||
-rw-r--r-- | src/luarocks/build.tl | 35 | ||||
-rw-r--r-- | src/luarocks/fetch.lua | 66 | ||||
-rw-r--r-- | src/luarocks/fetch.tl | 64 |
4 files changed, 17 insertions, 200 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index bc674a1a..effc3f1b 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -1,17 +1,5 @@ | |||
1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local pcall = _tl_compat and _tl_compat.pcall or pcall; local string = _tl_compat and _tl_compat.string or string | 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local pcall = _tl_compat and _tl_compat.pcall or pcall; local string = _tl_compat and _tl_compat.string or string |
2 | local build = {Op_b = {}, Builds = {}, } | 2 | local build = {Builds = {}, } |
3 | |||
4 | |||
5 | |||
6 | |||
7 | |||
8 | |||
9 | |||
10 | |||
11 | |||
12 | |||
13 | |||
14 | |||
15 | 3 | ||
16 | 4 | ||
17 | 5 | ||
@@ -47,8 +35,6 @@ local deplocks = require("luarocks.deplocks") | |||
47 | 35 | ||
48 | 36 | ||
49 | 37 | ||
50 | |||
51 | |||
52 | do | 38 | do |
53 | 39 | ||
54 | 40 | ||
@@ -243,38 +229,15 @@ local function run_build_driver(rockspec, no_install) | |||
243 | btype = "builtin" | 229 | btype = "builtin" |
244 | rockspec.build.type = btype | 230 | rockspec.build.type = btype |
245 | end | 231 | end |
232 | local driver | ||
246 | if cfg.accepted_build_types and not fun.contains(cfg.accepted_build_types, btype) then | 233 | if cfg.accepted_build_types and not fun.contains(cfg.accepted_build_types, btype) then |
247 | return nil, "This rockspec uses the '" .. btype .. "' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." | 234 | return nil, "This rockspec uses the '" .. btype .. "' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." |
248 | end | 235 | end |
249 | local pok, driver_str, driver | 236 | local pok, driver_str = pcall(require, "luarocks.build." .. btype) |
250 | if btype == "builtin" then | 237 | if not (type(driver_str) == "table") then |
251 | pok, driver_str = pcall(require, "luarocks.build.builtin") | 238 | return nil, "Failed initializing build back-end for build type '" .. btype .. "': " .. driver_str |
252 | if not pok or not (type(driver_str) == "table") then | 239 | else |
253 | return nil, "Failed initializing build back-end for build type '" .. btype .. "': " .. driver_str | 240 | driver = driver_str |
254 | else | ||
255 | driver = driver_str | ||
256 | end | ||
257 | elseif btype == "cmake" then | ||
258 | pok, driver_str = pcall(require, "luarocks.build.cmake") | ||
259 | if not pok or not (type(driver_str) == "table") then | ||
260 | return nil, "Failed initializing build back-end for build type '" .. btype .. "': " .. driver_str | ||
261 | else | ||
262 | driver = driver_str | ||
263 | end | ||
264 | elseif btype == "make" then | ||
265 | pok, driver_str = pcall(require, "luarocks.build.make") | ||
266 | if not pok or not (type(driver_str) == "table") then | ||
267 | return nil, "Failed initializing build back-end for build type '" .. btype .. "': " .. driver_str | ||
268 | else | ||
269 | driver = driver_str | ||
270 | end | ||
271 | elseif btype == "command" then | ||
272 | pok, driver_str = pcall(require, "luarocks.build.command") | ||
273 | if not pok or not (type(driver_str) == "table") then | ||
274 | return nil, "Failed initializing build back-end for build type '" .. btype .. "': " .. driver_str | ||
275 | else | ||
276 | driver = driver_str | ||
277 | end | ||
278 | end | 241 | end |
279 | 242 | ||
280 | if not driver.skip_lua_inc_lib_check then | 243 | if not driver.skip_lua_inc_lib_check then |
@@ -413,7 +376,6 @@ end | |||
413 | 376 | ||
414 | 377 | ||
415 | 378 | ||
416 | |||
417 | function build.build_rockspec(rockspec, opts, cwd) | 379 | function build.build_rockspec(rockspec, opts, cwd) |
418 | 380 | ||
419 | cwd = cwd or dir.path(".") | 381 | cwd = cwd or dir.path(".") |
diff --git a/src/luarocks/build.tl b/src/luarocks/build.tl index b11ceb80..38c2d826 100644 --- a/src/luarocks/build.tl +++ b/src/luarocks/build.tl | |||
@@ -229,38 +229,15 @@ local function run_build_driver(rockspec: Rockspec, no_install: boolean): boolea | |||
229 | btype = "builtin" | 229 | btype = "builtin" |
230 | rockspec.build.type = btype | 230 | rockspec.build.type = btype |
231 | end | 231 | end |
232 | local driver: Builds | ||
232 | if cfg.accepted_build_types and not fun.contains(cfg.accepted_build_types, btype) then | 233 | if cfg.accepted_build_types and not fun.contains(cfg.accepted_build_types, btype) then |
233 | return nil, "This rockspec uses the '"..btype.."' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." | 234 | return nil, "This rockspec uses the '"..btype.."' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." |
234 | end | 235 | end |
235 | local pok, driver_str, driver: boolean, Builds | string, Builds | 236 | local pok, driver_str = pcall(require, "luarocks.build." .. btype) as (boolean, Builds | string) |
236 | if btype == "builtin" then | 237 | if not driver_str is Builds then |
237 | pok, driver_str = pcall(require, "luarocks.build.builtin") as (boolean, Builds | string) | 238 | return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver_str |
238 | if not pok or not driver_str is Builds then | 239 | else |
239 | return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver_str as string | 240 | driver = driver_str as Builds |
240 | else | ||
241 | driver = driver_str as Builds | ||
242 | end | ||
243 | elseif btype == "cmake" then | ||
244 | pok, driver_str = pcall(require, "luarocks.build.cmake") as (boolean, Builds | string) | ||
245 | if not pok or not driver_str is Builds then | ||
246 | return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver_str as string | ||
247 | else | ||
248 | driver = driver_str as Builds | ||
249 | end | ||
250 | elseif btype == "make" then | ||
251 | pok, driver_str = pcall(require, "luarocks.build.make") as (boolean, Builds | string) | ||
252 | if not pok or not driver_str is Builds then | ||
253 | return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver_str as string | ||
254 | else | ||
255 | driver = driver_str as Builds | ||
256 | end | ||
257 | elseif btype == "command" then | ||
258 | pok, driver_str = pcall(require, "luarocks.build.command") as (boolean, Builds | string) | ||
259 | if not pok or not driver_str is Builds then | ||
260 | return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver_str as string | ||
261 | else | ||
262 | driver = driver_str as Builds | ||
263 | end | ||
264 | end | 241 | end |
265 | 242 | ||
266 | if not driver.skip_lua_inc_lib_check then | 243 | if not driver.skip_lua_inc_lib_check then |
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 2c6f7e28..fdc17d2c 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
@@ -19,7 +19,6 @@ local cfg = require("luarocks.core.cfg") | |||
19 | 19 | ||
20 | 20 | ||
21 | 21 | ||
22 | |||
23 | local function ensure_trailing_slash(url) | 22 | local function ensure_trailing_slash(url) |
24 | return (url:gsub("/*$", "/")) | 23 | return (url:gsub("/*$", "/")) |
25 | end | 24 | end |
@@ -436,7 +435,6 @@ end | |||
436 | 435 | ||
437 | 436 | ||
438 | function fetch.load_local_rockspec(rel_filename, quick) | 437 | function fetch.load_local_rockspec(rel_filename, quick) |
439 | assert(type(rel_filename) == "string") | ||
440 | local abs_filename = fs.absolute_name(rel_filename) | 438 | local abs_filename = fs.absolute_name(rel_filename) |
441 | 439 | ||
442 | local basename = dir.base_name(abs_filename) | 440 | local basename = dir.base_name(abs_filename) |
@@ -581,68 +579,8 @@ function fetch.fetch_sources(rockspec, extract, dest_dir) | |||
581 | if dir.is_basic_protocol(protocol) then | 579 | if dir.is_basic_protocol(protocol) then |
582 | proto = fetch | 580 | proto = fetch |
583 | else | 581 | else |
584 | local protocolfilename = protocol:gsub("[+-]", "_") | 582 | ok, proto = pcall(require, "luarocks.fetch." .. protocol:gsub("[+-]", "_")) |
585 | if protocolfilename == "cvs" then | 583 | if not ok then |
586 | ok, proto = pcall(require, "luarocks.fetch.cvs") | ||
587 | if not ok then | ||
588 | return nil, "Unknown protocol " .. protocol | ||
589 | end | ||
590 | elseif protocolfilename == "git_file" then | ||
591 | ok, proto = pcall(require, "luarocks.fetch.git_file") | ||
592 | if not ok then | ||
593 | return nil, "Unknown protocol " .. protocol | ||
594 | end | ||
595 | elseif protocolfilename == "git_http" then | ||
596 | ok, proto = pcall(require, "luarocks.fetch.git_http") | ||
597 | if not ok then | ||
598 | return nil, "Unknown protocol " .. protocol | ||
599 | end | ||
600 | elseif protocolfilename == "git_https" then | ||
601 | ok, proto = pcall(require, "luarocks.fetch.git_https") | ||
602 | if not ok then | ||
603 | return nil, "Unknown protocol " .. protocol | ||
604 | end | ||
605 | elseif protocolfilename == "git_ssh" then | ||
606 | ok, proto = pcall(require, "luarocks.fetch.git_ssh") | ||
607 | if not ok then | ||
608 | return nil, "Unknown protocol " .. protocol | ||
609 | end | ||
610 | elseif protocolfilename == "git" then | ||
611 | ok, proto = pcall(require, "luarocks.fetch.git") | ||
612 | if not ok then | ||
613 | return nil, "Unknown protocol " .. protocol | ||
614 | end | ||
615 | elseif protocolfilename == "hg_http" then | ||
616 | ok, proto = pcall(require, "luarocks.fetch.hg_http") | ||
617 | if not ok then | ||
618 | return nil, "Unknown protocol " .. protocol | ||
619 | end | ||
620 | elseif protocolfilename == "hg_https" then | ||
621 | ok, proto = pcall(require, "luarocks.fetch.hg_https") | ||
622 | if not ok then | ||
623 | return nil, "Unknown protocol " .. protocol | ||
624 | end | ||
625 | elseif protocolfilename == "hg_ssh" then | ||
626 | ok, proto = pcall(require, "luarocks.fetch.hg_ssh") | ||
627 | if not ok then | ||
628 | return nil, "Unknown protocol " .. protocol | ||
629 | end | ||
630 | elseif protocolfilename == "hg" then | ||
631 | ok, proto = pcall(require, "luarocks.fetch.hg") | ||
632 | if not ok then | ||
633 | return nil, "Unknown protocol " .. protocol | ||
634 | end | ||
635 | elseif protocolfilename == "sscm" then | ||
636 | ok, proto = pcall(require, "luarocks.fetch.sscm") | ||
637 | if not ok then | ||
638 | return nil, "Unknown protocol " .. protocol | ||
639 | end | ||
640 | elseif protocolfilename == "svn" then | ||
641 | ok, proto = pcall(require, "luarocks.fetch.svn") | ||
642 | if not ok then | ||
643 | return nil, "Unknown protocol " .. protocol | ||
644 | end | ||
645 | else | ||
646 | return nil, "Unknown protocol " .. protocol | 584 | return nil, "Unknown protocol " .. protocol |
647 | end | 585 | end |
648 | end | 586 | end |
diff --git a/src/luarocks/fetch.tl b/src/luarocks/fetch.tl index 6ee1c616..b4927529 100644 --- a/src/luarocks/fetch.tl +++ b/src/luarocks/fetch.tl | |||
@@ -579,68 +579,8 @@ function fetch.fetch_sources(rockspec: Rockspec, extract: boolean, dest_dir?: st | |||
579 | if dir.is_basic_protocol(protocol) then | 579 | if dir.is_basic_protocol(protocol) then |
580 | proto = fetch as Fetch | 580 | proto = fetch as Fetch |
581 | else | 581 | else |
582 | local protocolfilename = protocol:gsub("[+-]", "_") | 582 | ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) as (boolean, Fetch) |
583 | if protocolfilename == "cvs" then | 583 | if not ok then |
584 | ok, proto = pcall(require, "luarocks.fetch.cvs") as (boolean, Fetch) | ||
585 | if not ok then | ||
586 | return nil, "Unknown protocol "..protocol | ||
587 | end | ||
588 | elseif protocolfilename == "git_file" then | ||
589 | ok, proto = pcall(require, "luarocks.fetch.git_file") as (boolean, Fetch) | ||
590 | if not ok then | ||
591 | return nil, "Unknown protocol "..protocol | ||
592 | end | ||
593 | elseif protocolfilename == "git_http" then | ||
594 | ok, proto = pcall(require, "luarocks.fetch.git_http") as (boolean, Fetch) | ||
595 | if not ok then | ||
596 | return nil, "Unknown protocol "..protocol | ||
597 | end | ||
598 | elseif protocolfilename == "git_https" then | ||
599 | ok, proto = pcall(require, "luarocks.fetch.git_https") as (boolean, Fetch) | ||
600 | if not ok then | ||
601 | return nil, "Unknown protocol "..protocol | ||
602 | end | ||
603 | elseif protocolfilename == "git_ssh" then | ||
604 | ok, proto = pcall(require, "luarocks.fetch.git_ssh") as (boolean, Fetch) | ||
605 | if not ok then | ||
606 | return nil, "Unknown protocol "..protocol | ||
607 | end | ||
608 | elseif protocolfilename == "git" then | ||
609 | ok, proto = pcall(require, "luarocks.fetch.git") as (boolean, Fetch) | ||
610 | if not ok then | ||
611 | return nil, "Unknown protocol "..protocol | ||
612 | end | ||
613 | elseif protocolfilename == "hg_http" then | ||
614 | ok, proto = pcall(require, "luarocks.fetch.hg_http") as (boolean, Fetch) | ||
615 | if not ok then | ||
616 | return nil, "Unknown protocol "..protocol | ||
617 | end | ||
618 | elseif protocolfilename == "hg_https" then | ||
619 | ok, proto = pcall(require, "luarocks.fetch.hg_https") as (boolean, Fetch) | ||
620 | if not ok then | ||
621 | return nil, "Unknown protocol "..protocol | ||
622 | end | ||
623 | elseif protocolfilename == "hg_ssh" then | ||
624 | ok, proto = pcall(require, "luarocks.fetch.hg_ssh") as (boolean, Fetch) | ||
625 | if not ok then | ||
626 | return nil, "Unknown protocol "..protocol | ||
627 | end | ||
628 | elseif protocolfilename == "hg" then | ||
629 | ok, proto = pcall(require, "luarocks.fetch.hg") as (boolean, Fetch) | ||
630 | if not ok then | ||
631 | return nil, "Unknown protocol "..protocol | ||
632 | end | ||
633 | elseif protocolfilename == "sscm" then | ||
634 | ok, proto = pcall(require, "luarocks.fetch.sscm") as (boolean, Fetch) | ||
635 | if not ok then | ||
636 | return nil, "Unknown protocol "..protocol | ||
637 | end | ||
638 | elseif protocolfilename == "svn" then | ||
639 | ok, proto = pcall(require, "luarocks.fetch.svn") as (boolean, Fetch) | ||
640 | if not ok then | ||
641 | return nil, "Unknown protocol "..protocol | ||
642 | end | ||
643 | else | ||
644 | return nil, "Unknown protocol "..protocol | 584 | return nil, "Unknown protocol "..protocol |
645 | end | 585 | end |
646 | end | 586 | end |