diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-09-02 17:55:09 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
commit | 101711ad9e691f83a03c309fd7b4f093c52dee36 (patch) | |
tree | 45002b417c6adbc8a1787c2fd3aafcfa5723c474 | |
parent | 3be22b3f07dc1558c7734cf7639e3468ec8de796 (diff) | |
download | luarocks-101711ad9e691f83a03c309fd7b4f093c52dee36.tar.gz luarocks-101711ad9e691f83a03c309fd7b4f093c52dee36.tar.bz2 luarocks-101711ad9e691f83a03c309fd7b4f093c52dee36.zip |
fs: do dynamic requires in a Cyan-friendly way
We avoid doing a plain require() with a literal module name,
so that Cyan doesn't detect this as a circular dependency.
-rw-r--r-- | src/luarocks/fs.lua | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index a8156a21..8785e081 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua | |||
@@ -59,7 +59,12 @@ do | |||
59 | ["current_dir"] = true, | 59 | ["current_dir"] = true, |
60 | } | 60 | } |
61 | 61 | ||
62 | local function load_fns(fs_table, inits) | 62 | local function load_fns(module_name, inits) |
63 | local ok, fs_table = pcall(require, module_name) | ||
64 | if not ok or not type(fs_table) == "table" then | ||
65 | return | ||
66 | end | ||
67 | |||
63 | for name, fn in pairs(fs_table) do | 68 | for name, fn in pairs(fs_table) do |
64 | if name ~= "init" and not fs[name] then | 69 | if name ~= "init" and not fs[name] then |
65 | if skip_verbose_wrap[name] then | 70 | if skip_verbose_wrap[name] then |
@@ -101,10 +106,7 @@ do | |||
101 | end | 106 | end |
102 | 107 | ||
103 | for platform in each_platform("most-specific-first") do | 108 | for platform in each_platform("most-specific-first") do |
104 | local ok, fs_plat = pcall(require, patt:format(platform)) | 109 | load_fns(patt:format(platform), inits) |
105 | if ok and fs_plat then | ||
106 | load_fns(fs_plat, inits) | ||
107 | end | ||
108 | end | 110 | end |
109 | end | 111 | end |
110 | 112 | ||
@@ -130,13 +132,13 @@ do | |||
130 | load_platform_fns("luarocks.fs.%s", inits) | 132 | load_platform_fns("luarocks.fs.%s", inits) |
131 | 133 | ||
132 | -- Load platform-independent pure-Lua functionality | 134 | -- Load platform-independent pure-Lua functionality |
133 | load_fns(require("luarocks.fs.lua"), inits) | 135 | load_fns("luarocks.fs.lua", inits) |
134 | 136 | ||
135 | -- Load platform-specific fallbacks for missing Lua modules | 137 | -- Load platform-specific fallbacks for missing Lua modules |
136 | load_platform_fns("luarocks.fs.%s.tools", inits) | 138 | load_platform_fns("luarocks.fs.%s.tools", inits) |
137 | 139 | ||
138 | -- Load platform-independent external tool functionality | 140 | -- Load platform-independent external tool functionality |
139 | load_fns(require("luarocks.fs.tools"), inits) | 141 | load_fns("luarocks.fs.tools", inits) |
140 | 142 | ||
141 | -- Run platform-specific initializations after everything is loaded | 143 | -- Run platform-specific initializations after everything is loaded |
142 | for _, init in ipairs(inits) do | 144 | for _, init in ipairs(inits) do |