aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-10-10 19:34:28 +0200
committerGitHub <noreply@github.com>2022-10-10 19:34:28 +0200
commitb83c31c46e41f101778369fe00122a169099e638 (patch)
tree9247bd3ab54d2b96bbbeaeac65b885bf6492bd07
parentfix(visualforce-language-server): remove custom release resolution code (#534) (diff)
downloadmason-b83c31c46e41f101778369fe00122a169099e638.tar
mason-b83c31c46e41f101778369fe00122a169099e638.tar.gz
mason-b83c31c46e41f101778369fe00122a169099e638.tar.bz2
mason-b83c31c46e41f101778369fe00122a169099e638.tar.lz
mason-b83c31c46e41f101778369fe00122a169099e638.tar.xz
mason-b83c31c46e41f101778369fe00122a169099e638.tar.zst
mason-b83c31c46e41f101778369fe00122a169099e638.zip
feat(platform): better glibc detection (#537)
-rw-r--r--lua/mason-core/managers/github/init.lua3
-rw-r--r--lua/mason-core/platform.lua27
-rw-r--r--tests/mason-core/platform_spec.lua16
3 files changed, 35 insertions, 11 deletions
diff --git a/lua/mason-core/managers/github/init.lua b/lua/mason-core/managers/github/init.lua
index 7cdd494c..cf1e05f4 100644
--- a/lua/mason-core/managers/github/init.lua
+++ b/lua/mason-core/managers/github/init.lua
@@ -79,8 +79,7 @@ function M.release_file(opts)
local asset_file
if type(opts.asset_file) == "function" then
asset_file = opts.asset_file(source.release)
- else
- assert(type(opts.asset_file) == "string", "expected asset_file to be a string")
+ elseif type(opts.asset_file) == "string" then
asset_file = opts.asset_file --[[@as string]]
end
if not asset_file then
diff --git a/lua/mason-core/platform.lua b/lua/mason-core/platform.lua
index f6c3a4b5..fef9de00 100644
--- a/lua/mason-core/platform.lua
+++ b/lua/mason-core/platform.lua
@@ -25,14 +25,31 @@ M.sysname = uname.sysname
M.is_headless = #vim.api.nvim_list_uis() == 0
--- @return string @The libc found on the system, musl or glibc (glibc if ldd is not found)
+local function system(args)
+ if vim.fn.executable(args[1]) == 1 then
+ local ok, output = pcall(vim.fn.system, args)
+ if ok and vim.v.shell_error == 0 then
+ return true, output
+ end
+ return false, output
+ end
+ return false, args[1] .. " is not executable"
+end
+
+---@type fun(): ('"glibc"' | '"musl"')?
local get_libc = _.lazy(function()
- local _, _, libc_exit_code = os.execute "ldd --version 2>&1 | grep -q musl"
- if libc_exit_code == 0 then
- return "musl"
- else
+ local getconf_ok, getconf_output = system { "getconf", "GNU_LIBC_VERSION" }
+ if getconf_ok and getconf_output:find "glibc" then
return "glibc"
end
+ local ldd_ok, ldd_output = system { "ldd", "--version" }
+ if ldd_ok then
+ if ldd_output:find "musl" then
+ return "musl"
+ elseif ldd_output:find "GLIBC" or ldd_output:find "glibc" or ldd_output:find "GNU" then
+ return "glibc"
+ end
+ end
end)
-- Most of the code that calls into these functions executes outside of the main event loop, where API/fn functions are
diff --git a/tests/mason-core/platform_spec.lua b/tests/mason-core/platform_spec.lua
index d85354ca..dce29dab 100644
--- a/tests/mason-core/platform_spec.lua
+++ b/tests/mason-core/platform_spec.lua
@@ -25,12 +25,20 @@ describe("platform", function()
vim.loop.os_uname.returns(uname)
end
- ---@param libc string
+ ---@param libc '"glibc"' | '"musl"'
local function stub_libc(libc)
stub(os, "execute")
- local exit_code = libc == "musl" and 0 or 1
- -- selene: allow(incorrect_standard_library_use)
- os.execute.on_call_with("ldd --version 2>&1 | grep -q musl").returns(nil, nil, exit_code)
+ stub(vim.fn, "executable")
+ stub(vim.fn, "system")
+ vim.fn.executable.on_call_with("ldd").returns(1)
+ vim.fn.executable.on_call_with("getconf").returns(1)
+ if libc == "musl" then
+ vim.fn.system.on_call_with({ "getconf", "GNU_LIBC_VERSION" }).returns ""
+ vim.fn.system.on_call_with({ "ldd", "--version" }).returns "musl libc (aarch64)"
+ elseif libc == "glibc" then
+ vim.fn.system.on_call_with({ "getconf", "GNU_LIBC_VERSION" }).returns "glibc 2.35"
+ vim.fn.system.on_call_with({ "ldd", "--version" }).returns "ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35"
+ end
end
local function stub_mac()