fix(rocks): if installing with luarocks (binaries) fails, then build from source. Fixes #1563

This commit is contained in:
Folke Lemaitre 2024-06-27 11:33:11 +02:00
parent e02c5b1b57
commit 82276321f5
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 35 additions and 2 deletions

View File

@ -37,7 +37,7 @@ function Task.new(plugin, name, task, opts)
local self = setmetatable({}, { __index = Task })
self._opts = opts or {}
self._log = {}
self._level = vim.log.levels.TRACE
self:set_level()
self.plugin = plugin
self.name = name
---@param other LazyTask
@ -95,6 +95,11 @@ function Task:has_warnings()
return self._level >= vim.log.levels.WARN
end
---@param level? number
function Task:set_level(level)
self._level = level or vim.log.levels.TRACE
end
---@private
---@param task LazyTaskFn
function Task:_start(task)
@ -218,6 +223,7 @@ function Task:spawn(cmd, opts)
end
local running = true
local ret = true
---@param output string
function opts.on_exit(ok, output)
if not headless then
@ -226,6 +232,7 @@ function Task:spawn(cmd, opts)
if on_exit then
pcall(on_exit, ok, output)
end
ret = ok
running = false
end
@ -240,6 +247,7 @@ function Task:spawn(cmd, opts)
while running do
coroutine.yield()
end
return ret
end
function Task:prefix()

View File

@ -101,6 +101,7 @@ function M.check(opts)
return ok
end
---@async
---@param task LazyTask
function M.build(task)
if
@ -163,7 +164,7 @@ function M.build(task)
)
local root = Config.options.rocks.root .. "/" .. task.plugin.name
task:spawn(luarocks, {
local ok = task:spawn(luarocks, {
args = {
"--tree",
root,
@ -181,6 +182,30 @@ function M.build(task)
cwd = task.plugin.dir,
env = env,
})
if ok then
return
end
task:warn("Failed installing " .. rockspec.package .. " with `luarocks`.\nTrying to build from source.")
-- install failed, so try building from source
task:set_level() -- reset level
task:spawn(luarocks, {
args = {
"--tree",
root,
"--dev",
"--lua-version",
"5.1",
"make",
"--force-fast",
"--deps-mode",
"one",
},
cwd = task.plugin.dir,
env = env,
})
end
---@param rockspec RockSpec