diff --git a/lua/lazy/manage/task/init.lua b/lua/lazy/manage/task/init.lua index 6693adc..8dbffc5 100644 --- a/lua/lazy/manage/task/init.lua +++ b/lua/lazy/manage/task/init.lua @@ -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() diff --git a/lua/lazy/pkg/rockspec.lua b/lua/lazy/pkg/rockspec.lua index 04ff937..2580afa 100644 --- a/lua/lazy/pkg/rockspec.lua +++ b/lua/lazy/pkg/rockspec.lua @@ -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