feat: spec.rocks is no longer needed & added support for installing any luarock

This commit is contained in:
Folke Lemaitre 2024-06-24 14:14:41 +02:00
parent b3ee5b96f2
commit fcfd54835d
10 changed files with 120 additions and 235 deletions

View file

@ -82,13 +82,12 @@ function M.install(opts)
pipeline = {
"git.clone",
{ "git.checkout", lockfile = opts.lockfile },
"rocks.install",
"plugin.docs",
"wait",
"plugin.build",
},
plugins = function(plugin)
return plugin.url and not (plugin._.installed and plugin._.rocks_installed ~= false)
return plugin.url and not (plugin._.installed and not plugin._.build)
end,
}, opts):wait(function()
require("lazy.manage.lock").update()
@ -107,7 +106,6 @@ function M.update(opts)
"git.fetch",
"git.status",
{ "git.checkout", lockfile = opts.lockfile },
"rocks.install",
"plugin.docs",
"wait",
"plugin.build",
@ -224,7 +222,7 @@ function M.clear(plugins)
if plugin._.tasks then
---@param task LazyTask
plugin._.tasks = vim.tbl_filter(function(task)
return task:is_running()
return task:is_running() or task.error
end, plugin._.tasks)
end
end

View file

@ -1,90 +0,0 @@
--# selene:allow(incorrect_standard_library_use)
local Config = require("lazy.core.config")
local Util = require("lazy.core.util")
---@class LazyRock
---@field plugin string
---@field name string
---@field spec string
---@field installed boolean
local M = {}
---@type LazyRock[]
M.rocks = {}
---@param ... string
---@return string[]
function M.args(...)
local ret = {
"--tree",
Config.rocks.tree,
"--server",
Config.options.rocks.server,
"--dev",
"--lua-version",
"5.1",
}
vim.list_extend(ret, { ... })
return ret
end
---@param plugin LazyPlugin
function M.get_rockspec(plugin)
local rocks = vim.tbl_map(function(rock)
return rock.name
end, plugin._.rocks)
assert(rocks and #rocks > 0, plugin.name .. " has no rocks")
local rockspec_file = Config.rocks.specs .. "/lazy-" .. plugin.name .. "-scm-1.rockspec"
require("lazy.util").write_file(
rockspec_file,
([[
rockspec_format = "3.0"
package = "lazy-%s"
version = "scm-1"
source = { url = "%s" }
dependencies = %s
build = { type = "builtin" }
]]):format(plugin.name, plugin.url, vim.inspect(plugin.rocks))
)
return rockspec_file
end
function M.update_state()
local root = Config.rocks.tree .. "/lib/luarocks/rocks-5.1"
---@type table<string,string>
local installed = {}
Util.ls(root, function(_, name, type)
if type == "directory" then
installed[name] = name
end
end)
---@type LazyRock[]
local rocks = {}
M.rocks = rocks
for _, plugin in pairs(Config.plugins) do
if plugin.rocks then
plugin._.rocks = {}
plugin._.rocks_installed = true
for _, spec in ipairs(plugin.rocks) do
spec = vim.trim(spec)
local name = spec:gsub("%s.*", "")
local rock = {
plugin = plugin.name,
name = name,
spec = spec,
installed = installed[name] ~= nil,
}
if rock.name ~= "lua" then
plugin._.rocks_installed = plugin._.rocks_installed and rock.installed
table.insert(plugin._.rocks, rock)
table.insert(rocks, rock)
end
end
end
end
end
return M

View file

@ -1,57 +0,0 @@
local Rocks = require("lazy.manage.rocks")
---@type table<string, LazyTaskDef>
local M = {}
local running = false
local has_rocks = nil ---@type boolean?
M.install = {
skip = function(plugin)
return plugin._.rocks_installed ~= false
end,
run = function(self)
if has_rocks == nil then
has_rocks = vim.fn.executable("luarocks") == 1
end
if not has_rocks then
self.error = "This plugin has luarocks dependencies,\nbut the `luarocks` executable is not found.\nPlease install https://luarocks.org/ to continue.\n"
.. "luarock deps: "
.. vim.inspect(self.plugin.rocks)
return
end
local started = false
local function install()
started = true
self.status = "luarocks (install)"
vim.api.nvim_exec_autocmds("User", { pattern = "LazyRender", modeline = false })
self:spawn("luarocks", {
args = Rocks.args("install", "--deps-mode", "one", "--deps-only", Rocks.get_rockspec(self.plugin)),
on_exit = function(ok)
running = false
if ok then
self.plugin._.rocks_installed = true
end
end,
})
end
local timer = vim.uv.new_timer()
timer:start(0, 100, function()
if not running then
running = true
timer:stop()
vim.schedule(install)
end
end)
self.status = "luarocks (pending)"
table.insert(self._running, function()
return not started
end)
end,
}
return M