Skip to content

Commit 8227632

Browse files
committed
fix(rocks): if installing with luarocks (binaries) fails, then build from source. Fixes #1563
1 parent e02c5b1 commit 8227632

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lua/lazy/manage/task/init.lua

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Task.new(plugin, name, task, opts)
3737
local self = setmetatable({}, { __index = Task })
3838
self._opts = opts or {}
3939
self._log = {}
40-
self._level = vim.log.levels.TRACE
40+
self:set_level()
4141
self.plugin = plugin
4242
self.name = name
4343
---@param other LazyTask
@@ -95,6 +95,11 @@ function Task:has_warnings()
9595
return self._level >= vim.log.levels.WARN
9696
end
9797

98+
---@param level? number
99+
function Task:set_level(level)
100+
self._level = level or vim.log.levels.TRACE
101+
end
102+
98103
---@private
99104
---@param task LazyTaskFn
100105
function Task:_start(task)
@@ -218,6 +223,7 @@ function Task:spawn(cmd, opts)
218223
end
219224

220225
local running = true
226+
local ret = true
221227
---@param output string
222228
function opts.on_exit(ok, output)
223229
if not headless then
@@ -226,6 +232,7 @@ function Task:spawn(cmd, opts)
226232
if on_exit then
227233
pcall(on_exit, ok, output)
228234
end
235+
ret = ok
229236
running = false
230237
end
231238

@@ -240,6 +247,7 @@ function Task:spawn(cmd, opts)
240247
while running do
241248
coroutine.yield()
242249
end
250+
return ret
243251
end
244252

245253
function Task:prefix()

lua/lazy/pkg/rockspec.lua

+26-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function M.check(opts)
101101
return ok
102102
end
103103

104+
---@async
104105
---@param task LazyTask
105106
function M.build(task)
106107
if
@@ -163,7 +164,7 @@ function M.build(task)
163164
)
164165

165166
local root = Config.options.rocks.root .. "/" .. task.plugin.name
166-
task:spawn(luarocks, {
167+
local ok = task:spawn(luarocks, {
167168
args = {
168169
"--tree",
169170
root,
@@ -181,6 +182,30 @@ function M.build(task)
181182
cwd = task.plugin.dir,
182183
env = env,
183184
})
185+
186+
if ok then
187+
return
188+
end
189+
190+
task:warn("Failed installing " .. rockspec.package .. " with `luarocks`.\nTrying to build from source.")
191+
192+
-- install failed, so try building from source
193+
task:set_level() -- reset level
194+
task:spawn(luarocks, {
195+
args = {
196+
"--tree",
197+
root,
198+
"--dev",
199+
"--lua-version",
200+
"5.1",
201+
"make",
202+
"--force-fast",
203+
"--deps-mode",
204+
"one",
205+
},
206+
cwd = task.plugin.dir,
207+
env = env,
208+
})
184209
end
185210

186211
---@param rockspec RockSpec

0 commit comments

Comments
 (0)