mirror of https://github.com/folke/lazy.nvim.git
feat(rocks): use hererocks to install luarocks when luarocks is not found
This commit is contained in:
parent
dea1f687fe
commit
d87da76679
|
@ -49,6 +49,8 @@ M.defaults = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
root = vim.fn.stdpath("data") .. "/lazy-rocks",
|
root = vim.fn.stdpath("data") .. "/lazy-rocks",
|
||||||
server = "https://nvim-neorocks.github.io/rocks-binaries/",
|
server = "https://nvim-neorocks.github.io/rocks-binaries/",
|
||||||
|
-- use hererocks to install luarocks.
|
||||||
|
hererocks = vim.fn.executable("luarocks") == 0,
|
||||||
},
|
},
|
||||||
dev = {
|
dev = {
|
||||||
---@type string | fun(plugin: LazyPlugin): string directory where you store your local plugin projects
|
---@type string | fun(plugin: LazyPlugin): string directory where you store your local plugin projects
|
||||||
|
|
|
@ -33,7 +33,9 @@ function M:load_pkgs()
|
||||||
if not Config.options.pkg.enabled then
|
if not Config.options.pkg.enabled then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local have_rockspec = false
|
||||||
for _, pkg in ipairs(Pkg.get()) do
|
for _, pkg in ipairs(Pkg.get()) do
|
||||||
|
have_rockspec = have_rockspec or pkg.source == "rockspec"
|
||||||
local meta, fragment = self:add(pkg.spec)
|
local meta, fragment = self:add(pkg.spec)
|
||||||
if meta and fragment then
|
if meta and fragment then
|
||||||
meta._.pkg = pkg
|
meta._.pkg = pkg
|
||||||
|
@ -46,6 +48,12 @@ function M:load_pkgs()
|
||||||
self.pkgs[pkg.dir] = fragment.id
|
self.pkgs[pkg.dir] = fragment.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if have_rockspec then
|
||||||
|
local hererocks = Pkg.hererocks()
|
||||||
|
if hererocks then
|
||||||
|
self:add(hererocks)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Remove a plugin and all its fragments.
|
--- Remove a plugin and all its fragments.
|
||||||
|
|
|
@ -264,8 +264,10 @@ function M.update_rocks_state()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
for _, plugin in pairs(Config.plugins) do
|
for _, plugin in pairs(Config.plugins) do
|
||||||
if plugin._.pkg and plugin._.pkg.source == "rockspec" and plugin.build == "rockspec" then
|
if plugin.build == "rockspec" then
|
||||||
plugin._.build = not installed[plugin.name]
|
plugin._.build = not installed[plugin.name]
|
||||||
|
elseif plugin.name == "hererocks" then
|
||||||
|
plugin._.build = not vim.uv.fs_stat(Config.options.rocks.root .. "/hererocks")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,8 +18,25 @@ local B = {}
|
||||||
|
|
||||||
---@param task LazyTask
|
---@param task LazyTask
|
||||||
function B.rockspec(task)
|
function B.rockspec(task)
|
||||||
|
---@type table<string, string>
|
||||||
|
local env = {}
|
||||||
|
|
||||||
|
if Config.options.rocks.hererocks then
|
||||||
|
local hererocks = Config.options.rocks.root .. "/hererocks"
|
||||||
|
local sep = jit.os:find("Windows") and ";" or ":"
|
||||||
|
local path = vim.split(vim.env.PATH, sep)
|
||||||
|
table.insert(path, 1, hererocks .. "/bin")
|
||||||
|
env = {
|
||||||
|
PATH = table.concat(path, sep),
|
||||||
|
}
|
||||||
|
local plugin = Config.plugins.hererocks
|
||||||
|
-- hererocks is still building, so skip for now
|
||||||
|
if plugin and plugin._.build then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local root = Config.options.rocks.root .. "/" .. task.plugin.name
|
local root = Config.options.rocks.root .. "/" .. task.plugin.name
|
||||||
vim.fn.mkdir(root, "p")
|
|
||||||
task:spawn("luarocks", {
|
task:spawn("luarocks", {
|
||||||
args = {
|
args = {
|
||||||
"--tree",
|
"--tree",
|
||||||
|
@ -33,6 +50,7 @@ function B.rockspec(task)
|
||||||
"--force-fast",
|
"--force-fast",
|
||||||
},
|
},
|
||||||
cwd = task.plugin.dir,
|
cwd = task.plugin.dir,
|
||||||
|
env = env,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,32 @@ local function _load()
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return LazyPluginSpec?, string?
|
||||||
|
function M.hererocks()
|
||||||
|
if not (Config.options.rocks.enabled and Config.options.rocks.hererocks) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local root = Config.options.rocks.root .. "/hererocks"
|
||||||
|
|
||||||
|
local cmd = {
|
||||||
|
"python",
|
||||||
|
"hererocks.py",
|
||||||
|
"--verbose",
|
||||||
|
"-l",
|
||||||
|
"5.1",
|
||||||
|
"-r",
|
||||||
|
"latest",
|
||||||
|
root,
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"luarocks/hererocks",
|
||||||
|
lazy = true,
|
||||||
|
build = table.concat(cmd, " "),
|
||||||
|
}, root
|
||||||
|
end
|
||||||
|
|
||||||
---@param dir string
|
---@param dir string
|
||||||
---@return LazyPkg?
|
---@return LazyPkg?
|
||||||
---@overload fun():LazyPkg[]
|
---@overload fun():LazyPkg[]
|
||||||
|
|
Loading…
Reference in New Issue