feat(rocks): simple rockspecs are now fully resolved by lazy without luarocks. See #1548

This commit is contained in:
Folke Lemaitre 2024-06-25 20:53:42 +02:00
parent be74a8a535
commit 6b8bf58ebf
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
5 changed files with 80 additions and 32 deletions

View File

@ -21,4 +21,8 @@ function M.get_url(rock)
return load()[rock] return load()[rock]
end end
function M.get_spec(name)
return require("lazy.community.specs")[name]
end
return M return M

View File

@ -0,0 +1,7 @@
---@type table<string, LazySpec>
return {
["plenary.nvim"] = {
"nvim-lua/plenary.nvim",
lazy = true,
},
}

View File

@ -287,7 +287,7 @@ function M.find_local_spec()
return return
end end
local path = vim.uv.cwd() local path = vim.uv.cwd()
while path ~= "" do while path and path ~= "" do
local file = path .. "/" .. M.LOCAL_SPEC local file = path .. "/" .. M.LOCAL_SPEC
if vim.fn.filereadable(file) == 1 then if vim.fn.filereadable(file) == 1 then
return { return {

View File

@ -2,7 +2,7 @@ local Config = require("lazy.core.config")
local Util = require("lazy.core.util") local Util = require("lazy.core.util")
local M = {} local M = {}
M.VERSION = 10 M.VERSION = 12
M.dirty = false M.dirty = false
---@class LazyPkg ---@class LazyPkg

View File

@ -1,4 +1,6 @@
--# selene:allow(incorrect_standard_library_use) --# selene:allow(incorrect_standard_library_use)
local Community = require("lazy.community")
local Config = require("lazy.core.config") local Config = require("lazy.core.config")
local Health = require("lazy.health") local Health = require("lazy.health")
local Util = require("lazy.util") local Util = require("lazy.util")
@ -16,11 +18,11 @@ local Util = require("lazy.util")
local M = {} local M = {}
M.dev_suffix = "-1.rockspec"
M.skip = { "lua" } M.skip = { "lua" }
M.rewrites = { M.rewrites = {
["plenary.nvim"] = { "nvim-lua/plenary.nvim", lazy = true }, ["plenary.nvim"] = { "nvim-lua/plenary.nvim", lazy = true },
} }
M.python = { "python3", "python" } M.python = { "python3", "python" }
---@class HereRocks ---@class HereRocks
@ -151,6 +153,15 @@ function M.build(task)
end end
end end
local pkg = task.plugin._.pkg
assert(pkg, "missing rockspec pkg for " .. task.plugin.name .. "\nThis shouldn't happen, please report.")
local rockspec = M.rockspec(task.plugin.dir .. "/" .. pkg.file) or {}
assert(
rockspec.package,
"missing rockspec package name for " .. task.plugin.name .. "\nThis shouldn't happen, please report."
)
local root = Config.options.rocks.root .. "/" .. task.plugin.name local root = Config.options.rocks.root .. "/" .. task.plugin.name
task:spawn(luarocks, { task:spawn(luarocks, {
args = { args = {
@ -161,8 +172,11 @@ function M.build(task)
"--dev", "--dev",
"--lua-version", "--lua-version",
"5.1", "5.1",
"make", "install", -- use install so that we can make use of pre-built rocks
"--force-fast", "--force-fast",
"--deps-mode",
"one",
rockspec.package,
}, },
cwd = task.plugin.dir, cwd = task.plugin.dir,
env = env, env = env,
@ -192,31 +206,36 @@ function M.rockspec(file)
return M.parse(file) return M.parse(file)
end end
---@param plugin LazyPlugin
function M.find_rockspec(plugin)
local rockspec_file ---@type string?
Util.ls(plugin.dir, function(path, name, t)
if t == "file" then
for _, suffix in ipairs({ "scm", "git", "dev" }) do
suffix = suffix .. "-1.rockspec"
if name:sub(-#suffix) == suffix then
rockspec_file = path
return false
end
end
end
end)
return rockspec_file
end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
---@return LazyPkgSpec? ---@return LazyPkgSpec?
function M.get(plugin) function M.get(plugin)
if M.rewrites[plugin.name] then if Community.get_spec(plugin.name) then
return { return {
file = "rewrite", file = "community",
source = "lazy", source = "lazy",
spec = M.rewrites[plugin.name], spec = Community.get_spec(plugin.name),
} }
end end
local rockspec_file ---@type string? local rockspec_file = M.find_rockspec(plugin)
Util.ls(plugin.dir, function(path, name, t) local rockspec = rockspec_file and M.rockspec(rockspec_file)
if t == "file" and name:sub(-#M.dev_suffix) == M.dev_suffix then
rockspec_file = path
return false
end
end)
if not rockspec_file then
return
end
local rockspec = M.rockspec(rockspec_file)
if not rockspec then if not rockspec then
return return
end end
@ -224,20 +243,34 @@ function M.get(plugin)
local has_lua = not not vim.uv.fs_stat(plugin.dir .. "/lua") local has_lua = not not vim.uv.fs_stat(plugin.dir .. "/lua")
---@type LazyPluginSpec ---@type LazyPluginSpec
local rewrites = {} local specs = {}
---@param dep string ---@param dep string
local rocks = vim.tbl_filter(function(dep) local rocks = vim.tbl_filter(function(dep)
local name = dep:gsub("%s.*", "") local name = dep:gsub("%s.*", "")
if M.rewrites[name] then local url = Community.get_url(name)
table.insert(rewrites, M.rewrites[name]) local spec = Community.get_spec(name)
if spec then
-- community spec
table.insert(specs, spec)
return false
elseif url then
-- Neovim plugin rock
table.insert(specs, { url, lazy = true })
return false return false
end end
return not vim.tbl_contains(M.skip, name) return not vim.tbl_contains(M.skip, name)
end, rockspec.dependencies or {}) end, rockspec.dependencies or {})
local use = not has_lua local use =
-- package without a /lua directory
not has_lua
-- has dependencies that are not skipped,
-- not in community specs,
-- and don't have a rockspec mapping
or #rocks > 0 or #rocks > 0
-- has a complex build process
or ( or (
rockspec.build rockspec.build
and rockspec.build.build_type and rockspec.build.build_type
@ -246,13 +279,17 @@ function M.get(plugin)
) )
if not use then if not use then
if #rewrites > 0 then -- community specs only
return { return #specs > 0
file = vim.fn.fnamemodify(rockspec_file, ":t"), and {
spec = rewrites, file = vim.fn.fnamemodify(rockspec_file, ":t"),
} spec = {
end plugin.name,
return specs = specs,
build = false,
},
}
or nil
end end
local lazy = nil local lazy = nil