2023-06-30 20:19:30 +01:00
|
|
|
local Config = require("lazy.core.config")
|
2023-10-09 10:25:42 +01:00
|
|
|
local Loader = require("lazy.core.loader")
|
|
|
|
local Util = require("lazy.util")
|
2022-11-28 10:04:32 +00:00
|
|
|
|
|
|
|
---@type table<string, LazyTaskDef>
|
|
|
|
local M = {}
|
|
|
|
|
2023-06-30 17:22:39 +01:00
|
|
|
---@param plugin LazyPlugin
|
|
|
|
local function get_build_file(plugin)
|
|
|
|
for _, path in ipairs({ "build.lua", "build/init.lua" }) do
|
2024-06-24 13:16:00 +01:00
|
|
|
if Util.file_exists(plugin.dir .. "/" .. path) then
|
2023-06-30 17:22:39 +01:00
|
|
|
return path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-24 13:16:00 +01:00
|
|
|
local B = {}
|
|
|
|
|
|
|
|
---@param task LazyTask
|
|
|
|
function B.rockspec(task)
|
2024-06-25 06:55:30 +01:00
|
|
|
---@type table<string, string>
|
|
|
|
local env = {}
|
|
|
|
|
2024-06-25 05:40:50 +01:00
|
|
|
local luarocks = "luarocks"
|
2024-06-25 06:55:30 +01:00
|
|
|
if Config.options.rocks.hererocks then
|
2024-06-25 05:40:50 +01:00
|
|
|
local is_win = jit.os:find("Windows")
|
|
|
|
local sep = is_win and ";" or ":"
|
|
|
|
local hererocks = Config.options.rocks.root .. "/hererocks/bin"
|
|
|
|
if is_win then
|
|
|
|
hererocks = hererocks:gsub("/", "\\")
|
|
|
|
end
|
2024-06-25 06:55:30 +01:00
|
|
|
local path = vim.split(vim.env.PATH, sep)
|
2024-06-25 05:40:50 +01:00
|
|
|
table.insert(path, 1, hererocks)
|
2024-06-25 06:55:30 +01:00
|
|
|
env = {
|
|
|
|
PATH = table.concat(path, sep),
|
|
|
|
}
|
2024-06-25 05:40:50 +01:00
|
|
|
if is_win then
|
|
|
|
luarocks = luarocks .. ".bat"
|
|
|
|
end
|
2024-06-25 06:55:30 +01:00
|
|
|
local plugin = Config.plugins.hererocks
|
|
|
|
-- hererocks is still building, so skip for now
|
|
|
|
if plugin and plugin._.build then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-24 13:16:00 +01:00
|
|
|
local root = Config.options.rocks.root .. "/" .. task.plugin.name
|
2024-06-25 05:40:50 +01:00
|
|
|
task:spawn(luarocks, {
|
2024-06-24 13:16:00 +01:00
|
|
|
args = {
|
|
|
|
"--tree",
|
|
|
|
root,
|
|
|
|
"--server",
|
|
|
|
Config.options.rocks.server,
|
|
|
|
"--dev",
|
|
|
|
"--lua-version",
|
|
|
|
"5.1",
|
|
|
|
"make",
|
|
|
|
"--force-fast",
|
|
|
|
},
|
|
|
|
cwd = task.plugin.dir,
|
2024-06-25 06:55:30 +01:00
|
|
|
env = env,
|
2024-06-24 13:16:00 +01:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param task LazyTask
|
|
|
|
---@param build string
|
|
|
|
function B.cmd(task, build)
|
|
|
|
local cmd = vim.api.nvim_parse_cmd(build:sub(2), {}) --[[@as vim.api.keyset.cmd]]
|
|
|
|
task.output = vim.api.nvim_cmd(cmd, { output = true })
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param task LazyTask
|
|
|
|
---@param build string
|
|
|
|
function B.shell(task, build)
|
|
|
|
local shell = vim.env.SHELL or vim.o.shell
|
|
|
|
local shell_args = shell:find("cmd.exe", 1, true) and "/c" or "-c"
|
|
|
|
|
|
|
|
task:spawn(shell, {
|
|
|
|
args = { shell_args, build },
|
|
|
|
cwd = task.plugin.dir,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2022-12-01 06:43:28 +00:00
|
|
|
M.build = {
|
2023-01-01 08:41:43 +00:00
|
|
|
---@param opts? {force:boolean}
|
|
|
|
skip = function(plugin, opts)
|
|
|
|
if opts and opts.force then
|
|
|
|
return false
|
|
|
|
end
|
2024-06-24 13:16:00 +01:00
|
|
|
return not ((plugin._.dirty or plugin._.build) and (plugin.build or get_build_file(plugin)))
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
run = function(self)
|
2023-01-13 08:19:51 +00:00
|
|
|
vim.cmd([[silent! runtime plugin/rplugin.vim]])
|
|
|
|
|
2024-06-24 13:16:00 +01:00
|
|
|
if self.plugin.build ~= "rockspec" then
|
|
|
|
Loader.load(self.plugin, { task = "build" })
|
|
|
|
end
|
2022-12-03 16:45:40 +00:00
|
|
|
|
2022-12-24 08:17:29 +00:00
|
|
|
local builders = self.plugin.build
|
2023-06-30 17:22:39 +01:00
|
|
|
|
2023-11-04 09:14:03 +00:00
|
|
|
-- Skip if `build` is set to `false`
|
|
|
|
if builders == false then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-06-24 13:16:00 +01:00
|
|
|
builders = builders or get_build_file(self.plugin)
|
|
|
|
|
2022-12-24 08:17:29 +00:00
|
|
|
if builders then
|
|
|
|
builders = type(builders) == "table" and builders or { builders }
|
|
|
|
---@cast builders (string|fun(LazyPlugin))[]
|
|
|
|
for _, build in ipairs(builders) do
|
2024-06-24 13:16:00 +01:00
|
|
|
if type(build) == "function" then
|
|
|
|
self:async(function()
|
|
|
|
build(self.plugin)
|
|
|
|
end)
|
|
|
|
elseif build == "rockspec" then
|
|
|
|
B.rockspec(self)
|
|
|
|
elseif build:sub(1, 1) == ":" then
|
|
|
|
B.cmd(self, build)
|
|
|
|
elseif build:match("%.lua$") then
|
|
|
|
local file = self.plugin.dir .. "/" .. build
|
|
|
|
local chunk, err = loadfile(file)
|
|
|
|
if not chunk or err then
|
|
|
|
error(err)
|
|
|
|
end
|
|
|
|
self:async(chunk)
|
2022-12-24 08:17:29 +00:00
|
|
|
else
|
2024-06-24 13:16:00 +01:00
|
|
|
B.shell(self, build)
|
2022-12-24 08:17:29 +00:00
|
|
|
end
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
M.docs = {
|
2022-11-28 12:11:20 +00:00
|
|
|
skip = function(plugin)
|
|
|
|
return not plugin._.dirty
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
run = function(self)
|
|
|
|
local docs = self.plugin.dir .. "/doc/"
|
|
|
|
if Util.file_exists(docs) then
|
|
|
|
self.output = vim.api.nvim_cmd({ cmd = "helptags", args = { docs } }, { output = true })
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
return M
|