@@ -8,25 +8,67 @@ local M = {}
8
8
--- @param plugin LazyPlugin
9
9
local function get_build_file (plugin )
10
10
for _ , path in ipairs ({ " build.lua" , " build/init.lua" }) do
11
- path = plugin .dir .. " /" .. path
12
- if Util .file_exists (path ) then
11
+ if Util .file_exists (plugin .dir .. " /" .. path ) then
13
12
return path
14
13
end
15
14
end
16
15
end
17
16
17
+ local B = {}
18
+
19
+ --- @param task LazyTask
20
+ function B .rockspec (task )
21
+ local root = Config .options .rocks .root .. " /" .. task .plugin .name
22
+ vim .fn .mkdir (root , " p" )
23
+ task :spawn (" luarocks" , {
24
+ args = {
25
+ " --tree" ,
26
+ root ,
27
+ " --server" ,
28
+ Config .options .rocks .server ,
29
+ " --dev" ,
30
+ " --lua-version" ,
31
+ " 5.1" ,
32
+ " make" ,
33
+ " --force-fast" ,
34
+ },
35
+ cwd = task .plugin .dir ,
36
+ })
37
+ end
38
+
39
+ --- @param task LazyTask
40
+ --- @param build string
41
+ function B .cmd (task , build )
42
+ local cmd = vim .api .nvim_parse_cmd (build :sub (2 ), {}) --[[ @as vim.api.keyset.cmd]]
43
+ task .output = vim .api .nvim_cmd (cmd , { output = true })
44
+ end
45
+
46
+ --- @param task LazyTask
47
+ --- @param build string
48
+ function B .shell (task , build )
49
+ local shell = vim .env .SHELL or vim .o .shell
50
+ local shell_args = shell :find (" cmd.exe" , 1 , true ) and " /c" or " -c"
51
+
52
+ task :spawn (shell , {
53
+ args = { shell_args , build },
54
+ cwd = task .plugin .dir ,
55
+ })
56
+ end
57
+
18
58
M .build = {
19
59
--- @param opts ? { force : boolean }
20
60
skip = function (plugin , opts )
21
61
if opts and opts .force then
22
62
return false
23
63
end
24
- return not (plugin ._ .dirty and (plugin .build or get_build_file (plugin )))
64
+ return not (( plugin ._ .dirty or plugin . _ . build ) and (plugin .build or get_build_file (plugin )))
25
65
end ,
26
66
run = function (self )
27
67
vim .cmd ([[ silent! runtime plugin/rplugin.vim]] )
28
68
29
- Loader .load (self .plugin , { task = " build" })
69
+ if self .plugin .build ~= " rockspec" then
70
+ Loader .load (self .plugin , { task = " build" })
71
+ end
30
72
31
73
local builders = self .plugin .build
32
74
@@ -35,39 +77,29 @@ M.build = {
35
77
return
36
78
end
37
79
38
- local build_file = get_build_file (self .plugin )
39
- if build_file then
40
- if builders then
41
- if Config .options .build .warn_on_override then
42
- Util .warn (
43
- (" Plugin **%s** provides its own build script, but you also defined a `build` command.\n The `build.lua` file will not be used" ):format (
44
- self .plugin .name
45
- )
46
- )
47
- end
48
- else
49
- builders = function ()
50
- Loader .source (build_file )
51
- end
52
- end
53
- end
80
+ builders = builders or get_build_file (self .plugin )
81
+
54
82
if builders then
55
83
builders = type (builders ) == " table" and builders or { builders }
56
84
--- @cast builders (string | fun ( LazyPlugin )) []
57
85
for _ , build in ipairs (builders ) do
58
- if type (build ) == " string" and build :sub (1 , 1 ) == " :" then
59
- local cmd = vim .api .nvim_parse_cmd (build :sub (2 ), {})
60
- self .output = vim .api .nvim_cmd (cmd , { output = true })
61
- elseif type (build ) == " function" then
62
- build (self .plugin )
86
+ if type (build ) == " function" then
87
+ self :async (function ()
88
+ build (self .plugin )
89
+ end )
90
+ elseif build == " rockspec" then
91
+ B .rockspec (self )
92
+ elseif build :sub (1 , 1 ) == " :" then
93
+ B .cmd (self , build )
94
+ elseif build :match (" %.lua$" ) then
95
+ local file = self .plugin .dir .. " /" .. build
96
+ local chunk , err = loadfile (file )
97
+ if not chunk or err then
98
+ error (err )
99
+ end
100
+ self :async (chunk )
63
101
else
64
- local shell = vim .env .SHELL or vim .o .shell
65
- local shell_args = shell :find (" cmd.exe" , 1 , true ) and " /c" or " -c"
66
-
67
- self :spawn (shell , {
68
- args = { shell_args , build },
69
- cwd = self .plugin .dir ,
70
- })
102
+ B .shell (self , build )
71
103
end
72
104
end
73
105
end
0 commit comments