fix(rocks): try building anyway even when prerequisits have not been met. (will likely fail)

This commit is contained in:
Folke Lemaitre 2024-07-08 07:45:43 +02:00
parent 0002bfbd9f
commit f0324defdd
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 41 additions and 27 deletions

View File

@ -21,16 +21,23 @@ M.clean = {
skip = function(plugin) skip = function(plugin)
return plugin._.is_local return plugin._.is_local
end, end,
run = function(self) ---@param opts? {rocks_only?:boolean}
run = function(self, opts)
opts = opts or {}
local dir = self.plugin.dir:gsub("/+$", "") local dir = self.plugin.dir:gsub("/+$", "")
assert(dir:find(Config.options.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!") assert(dir:find(Config.options.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
rm(dir)
local rock_root = Config.options.rocks.root .. "/" .. self.plugin.name local rock_root = Config.options.rocks.root .. "/" .. self.plugin.name
if vim.uv.fs_stat(rock_root) then if vim.uv.fs_stat(rock_root) then
rm(rock_root) rm(rock_root)
end end
if opts.rocks_only then
return
end
rm(dir)
self.plugin._.installed = false self.plugin._.installed = false
end, end,
} }

View File

@ -78,25 +78,23 @@ function M.check(opts)
else else
ok = Health.have(M.python, opts) ok = Health.have(M.python, opts)
ok = Health.have(M.hererocks.bin("luarocks")) and ok ok = Health.have(M.hererocks.bin("luarocks")) and ok
ok = Health.have( Health.have(
M.hererocks.bin("lua"), M.hererocks.bin("lua"),
vim.tbl_extend("force", opts, { vim.tbl_extend("force", opts, {
version = "-v", version = "-v",
version_pattern = "5.1", version_pattern = "5.1",
}) })
) and ok )
end end
else else
ok = Health.have("luarocks", opts) ok = Health.have("luarocks", opts)
ok = ( Health.have(
Health.have( { "lua5.1", "lua", "lua-5.1" },
{ "lua5.1", "lua", "lua-5.1" }, vim.tbl_extend("force", opts, {
vim.tbl_extend("force", opts, { version = "-v",
version = "-v", version_pattern = "5.1",
version_pattern = "5.1", })
}) )
)
) and ok
end end
return ok return ok
end end
@ -104,17 +102,17 @@ end
---@async ---@async
---@param task LazyTask ---@param task LazyTask
function M.build(task) function M.build(task)
if M.check({
not M.check({ error = function(msg)
error = function(msg) task:error(msg:gsub("[{}]", "`"))
task:error(msg:gsub("[{}]", "`")) end,
end, warn = function(msg)
warn = function(msg) task:warn(msg)
task:warn(msg) end,
end, ok = function(msg) end,
ok = function(msg) end, })
})
then if task:has_warnings() then
task:log({ task:log({
"", "",
"This plugin requires `luarocks`. Try one of the following:", "This plugin requires `luarocks`. Try one of the following:",
@ -123,7 +121,11 @@ function M.build(task)
or " - enable `hererocks` with `opts.rocks.hererocks = true`", or " - enable `hererocks` with `opts.rocks.hererocks = true`",
" - disable `luarocks` support completely with `opts.rocks.enabled = false`", " - disable `luarocks` support completely with `opts.rocks.enabled = false`",
}) })
return task:warn("\nWill try building anyway, but will likely fail...")
task:warn("\n" .. string.rep("-", 80) .. "\n")
task:set_level(vim.log.levels.WARN)
end end
if task.plugin.name == "hererocks" then if task.plugin.name == "hererocks" then
@ -187,11 +189,13 @@ function M.build(task)
return return
end end
task:warn("Failed installing " .. rockspec.package .. " with `luarocks`.\nTrying to build from source.") task:warn("Failed installing " .. rockspec.package .. " with `luarocks`.")
task:warn("\n" .. string.rep("-", 80) .. "\n")
task:warn("Trying to build from source.")
-- install failed, so try building from source -- install failed, so try building from source
task:set_level() -- reset level task:set_level() -- reset level
task:spawn(luarocks, { ok = task:spawn(luarocks, {
args = { args = {
"--tree", "--tree",
root, root,
@ -206,6 +210,9 @@ function M.build(task)
cwd = task.plugin.dir, cwd = task.plugin.dir,
env = env, env = env,
}) })
if not ok then
require("lazy.manage.task.fs").clean.run(task, { rocks_only = true })
end
end end
---@param rockspec RockSpec ---@param rockspec RockSpec