Skip to content

Commit

Permalink
fix(rocks): try building anyway even when prerequisits have not been …
Browse files Browse the repository at this point in the history
…met. (will likely fail)
  • Loading branch information
folke committed Jul 8, 2024
1 parent 0002bfb commit f0324de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
11 changes: 9 additions & 2 deletions lua/lazy/manage/task/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ M.clean = {
skip = function(plugin)
return plugin._.is_local
end,
run = function(self)
---@param opts? {rocks_only?:boolean}
run = function(self, opts)
opts = opts or {}
local dir = self.plugin.dir:gsub("/+$", "")
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
if vim.uv.fs_stat(rock_root) then
rm(rock_root)
end

if opts.rocks_only then
return
end

rm(dir)

self.plugin._.installed = false
end,
}
Expand Down
57 changes: 32 additions & 25 deletions lua/lazy/pkg/rockspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,41 @@ function M.check(opts)
else
ok = Health.have(M.python, opts)
ok = Health.have(M.hererocks.bin("luarocks")) and ok
ok = Health.have(
Health.have(
M.hererocks.bin("lua"),
vim.tbl_extend("force", opts, {
version = "-v",
version_pattern = "5.1",
})
) and ok
)
end
else
ok = Health.have("luarocks", opts)
ok = (
Health.have(
{ "lua5.1", "lua", "lua-5.1" },
vim.tbl_extend("force", opts, {
version = "-v",
version_pattern = "5.1",
})
)
) and ok
Health.have(
{ "lua5.1", "lua", "lua-5.1" },
vim.tbl_extend("force", opts, {
version = "-v",
version_pattern = "5.1",
})
)
end
return ok
end

---@async
---@param task LazyTask
function M.build(task)
if
not M.check({
error = function(msg)
task:error(msg:gsub("[{}]", "`"))
end,
warn = function(msg)
task:warn(msg)
end,
ok = function(msg) end,
})
then
M.check({
error = function(msg)
task:error(msg:gsub("[{}]", "`"))
end,
warn = function(msg)
task:warn(msg)
end,
ok = function(msg) end,
})

if task:has_warnings() then
task:log({
"",
"This plugin requires `luarocks`. Try one of the following:",
Expand All @@ -123,7 +121,11 @@ function M.build(task)
or " - enable `hererocks` with `opts.rocks.hererocks = true`",
" - 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

if task.plugin.name == "hererocks" then
Expand Down Expand Up @@ -187,11 +189,13 @@ function M.build(task)
return
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
task:set_level() -- reset level
task:spawn(luarocks, {
ok = task:spawn(luarocks, {
args = {
"--tree",
root,
Expand All @@ -206,6 +210,9 @@ function M.build(task)
cwd = task.plugin.dir,
env = env,
})
if not ok then
require("lazy.manage.task.fs").clean.run(task, { rocks_only = true })
end
end

---@param rockspec RockSpec
Expand Down

0 comments on commit f0324de

Please sign in to comment.