diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2019-07-25 15:48:08 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-07-25 18:47:00 -0300 |
commit | 7b730490ade3690d1b39bbb9f5c51c4cead974ed (patch) | |
tree | 17c14a727f80955af380223ec0c8b75dbf03293e | |
parent | 869a628bec218b94b4b312fadcedf13262fa5b03 (diff) | |
download | luarocks-7b730490ade3690d1b39bbb9f5c51c4cead974ed.tar.gz luarocks-7b730490ade3690d1b39bbb9f5c51c4cead974ed.tar.bz2 luarocks-7b730490ade3690d1b39bbb9f5c51c4cead974ed.zip |
fs: fix initialization of platform-specific fallbacks
-rw-r--r-- | src/luarocks/core/cfg.lua | 15 | ||||
-rw-r--r-- | src/luarocks/fs.lua | 33 |
2 files changed, 28 insertions, 20 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 0505b11d..a1ebe4e4 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -806,12 +806,21 @@ function cfg.init(detected, warning) | |||
806 | return platforms[name] | 806 | return platforms[name] |
807 | end | 807 | end |
808 | 808 | ||
809 | function cfg.each_platform() | 809 | -- @param direction (optional) "least-specific-first" (default) or "most-specific-first" |
810 | local i = 0 | 810 | function cfg.each_platform(direction) |
811 | direction = direction or "least-specific-first" | ||
812 | local i, delta | ||
813 | if direction == "least-specific-first" then | ||
814 | i = 0 | ||
815 | delta = 1 | ||
816 | else | ||
817 | i = #platform_order + 1 | ||
818 | delta = -1 | ||
819 | end | ||
811 | return function() | 820 | return function() |
812 | local p | 821 | local p |
813 | repeat | 822 | repeat |
814 | i = i + 1 | 823 | i = i + delta |
815 | p = platform_order[i] | 824 | p = platform_order[i] |
816 | until (not p) or platforms[p] | 825 | until (not p) or platforms[p] |
817 | return p | 826 | return p |
diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index 849ee4d3..f3c474eb 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua | |||
@@ -51,7 +51,7 @@ end | |||
51 | do | 51 | do |
52 | local function load_fns(fs_table, inits) | 52 | local function load_fns(fs_table, inits) |
53 | for name, fn in pairs(fs_table) do | 53 | for name, fn in pairs(fs_table) do |
54 | if not fs[name] then | 54 | if name ~= "init" and not fs[name] then |
55 | fs[name] = fn | 55 | fs[name] = fn |
56 | end | 56 | end |
57 | end | 57 | end |
@@ -60,6 +60,15 @@ do | |||
60 | end | 60 | end |
61 | end | 61 | end |
62 | 62 | ||
63 | local function load_platform_fns(patt, inits) | ||
64 | for platform in cfg.each_platform("most-specific-first") do | ||
65 | local ok, fs_plat = pcall(require, patt:format(platform)) | ||
66 | if ok and fs_plat then | ||
67 | load_fns(fs_plat, inits) | ||
68 | end | ||
69 | end | ||
70 | end | ||
71 | |||
63 | function fs.init() | 72 | function fs.init() |
64 | if fs.current_dir then | 73 | if fs.current_dir then |
65 | -- already initialized | 74 | -- already initialized |
@@ -73,26 +82,16 @@ do | |||
73 | local inits = {} | 82 | local inits = {} |
74 | 83 | ||
75 | -- Load platform-specific functions | 84 | -- Load platform-specific functions |
76 | local loaded_platform = nil | 85 | load_platform_fns("luarocks.fs.%s", inits) |
77 | for platform in cfg.each_platform() do | ||
78 | local ok, fs_plat = pcall(require, "luarocks.fs."..platform) | ||
79 | if ok and fs_plat then | ||
80 | loaded_platform = platform | ||
81 | load_fns(fs_plat, inits) | ||
82 | break | ||
83 | end | ||
84 | end | ||
85 | 86 | ||
86 | -- Load platform-independent pure-Lua functionality | 87 | -- Load platform-independent pure-Lua functionality |
87 | local fs_lua = require("luarocks.fs.lua") | 88 | load_fns(require("luarocks.fs.lua"), inits) |
88 | load_fns(fs_lua, inits) | ||
89 | 89 | ||
90 | -- Load platform-specific fallbacks for missing Lua modules | 90 | -- Load platform-specific fallbacks for missing Lua modules |
91 | local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") | 91 | load_platform_fns("luarocks.fs.%s.tools", inits) |
92 | if ok and fs_plat_tools then | 92 | |
93 | load_fns(fs_plat_tools, inits) | 93 | -- Load platform-independent external tool functionality |
94 | load_fns(require("luarocks.fs.tools")) | 94 | load_fns(require("luarocks.fs.tools"), inits) |
95 | end | ||
96 | 95 | ||
97 | -- Run platform-specific initializations after everything is loaded | 96 | -- Run platform-specific initializations after everything is loaded |
98 | for _, init in ipairs(inits) do | 97 | for _, init in ipairs(inits) do |