Skip to content

Commit f0324de

Browse files
committedJul 8, 2024··
fix(rocks): try building anyway even when prerequisits have not been met. (will likely fail)
1 parent 0002bfb commit f0324de

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed
 

‎lua/lazy/manage/task/fs.lua

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@ M.clean = {
2121
skip = function(plugin)
2222
return plugin._.is_local
2323
end,
24-
run = function(self)
24+
---@param opts? {rocks_only?:boolean}
25+
run = function(self, opts)
26+
opts = opts or {}
2527
local dir = self.plugin.dir:gsub("/+$", "")
2628
assert(dir:find(Config.options.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
27-
rm(dir)
2829

2930
local rock_root = Config.options.rocks.root .. "/" .. self.plugin.name
3031
if vim.uv.fs_stat(rock_root) then
3132
rm(rock_root)
3233
end
3334

35+
if opts.rocks_only then
36+
return
37+
end
38+
39+
rm(dir)
40+
3441
self.plugin._.installed = false
3542
end,
3643
}

‎lua/lazy/pkg/rockspec.lua

+32-25
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,41 @@ function M.check(opts)
7878
else
7979
ok = Health.have(M.python, opts)
8080
ok = Health.have(M.hererocks.bin("luarocks")) and ok
81-
ok = Health.have(
81+
Health.have(
8282
M.hererocks.bin("lua"),
8383
vim.tbl_extend("force", opts, {
8484
version = "-v",
8585
version_pattern = "5.1",
8686
})
87-
) and ok
87+
)
8888
end
8989
else
9090
ok = Health.have("luarocks", opts)
91-
ok = (
92-
Health.have(
93-
{ "lua5.1", "lua", "lua-5.1" },
94-
vim.tbl_extend("force", opts, {
95-
version = "-v",
96-
version_pattern = "5.1",
97-
})
98-
)
99-
) and ok
91+
Health.have(
92+
{ "lua5.1", "lua", "lua-5.1" },
93+
vim.tbl_extend("force", opts, {
94+
version = "-v",
95+
version_pattern = "5.1",
96+
})
97+
)
10098
end
10199
return ok
102100
end
103101

104102
---@async
105103
---@param task LazyTask
106104
function M.build(task)
107-
if
108-
not M.check({
109-
error = function(msg)
110-
task:error(msg:gsub("[{}]", "`"))
111-
end,
112-
warn = function(msg)
113-
task:warn(msg)
114-
end,
115-
ok = function(msg) end,
116-
})
117-
then
105+
M.check({
106+
error = function(msg)
107+
task:error(msg:gsub("[{}]", "`"))
108+
end,
109+
warn = function(msg)
110+
task:warn(msg)
111+
end,
112+
ok = function(msg) end,
113+
})
114+
115+
if task:has_warnings() then
118116
task:log({
119117
"",
120118
"This plugin requires `luarocks`. Try one of the following:",
@@ -123,7 +121,11 @@ function M.build(task)
123121
or " - enable `hererocks` with `opts.rocks.hererocks = true`",
124122
" - disable `luarocks` support completely with `opts.rocks.enabled = false`",
125123
})
126-
return
124+
task:warn("\nWill try building anyway, but will likely fail...")
125+
126+
task:warn("\n" .. string.rep("-", 80) .. "\n")
127+
128+
task:set_level(vim.log.levels.WARN)
127129
end
128130

129131
if task.plugin.name == "hererocks" then
@@ -187,11 +189,13 @@ function M.build(task)
187189
return
188190
end
189191

190-
task:warn("Failed installing " .. rockspec.package .. " with `luarocks`.\nTrying to build from source.")
192+
task:warn("Failed installing " .. rockspec.package .. " with `luarocks`.")
193+
task:warn("\n" .. string.rep("-", 80) .. "\n")
194+
task:warn("Trying to build from source.")
191195

192196
-- install failed, so try building from source
193197
task:set_level() -- reset level
194-
task:spawn(luarocks, {
198+
ok = task:spawn(luarocks, {
195199
args = {
196200
"--tree",
197201
root,
@@ -206,6 +210,9 @@ function M.build(task)
206210
cwd = task.plugin.dir,
207211
env = env,
208212
})
213+
if not ok then
214+
require("lazy.manage.task.fs").clean.run(task, { rocks_only = true })
215+
end
209216
end
210217

211218
---@param rockspec RockSpec

0 commit comments

Comments
 (0)
Please sign in to comment.