@@ -26,17 +26,17 @@ M.status = {
26
26
TO_RECLONE = 6 ,
27
27
}
28
28
29
- --- @nodoc
29
+ --- List of packages to build
30
+ local BuildQueue = {}
31
+
30
32
--- Table of pgks loaded from the lockfile
31
33
--- @type pack.Package[]
32
34
local Lock = {}
33
35
34
- --- @nodoc
35
36
--- Table of pkgs loaded from the user configuration
36
37
--- @type pack.Package[]
37
38
local Packages = {}
38
39
39
- --- @nodoc
40
40
--- @type table<string , string>
41
41
local Path = {
42
42
lock = vim .fs .joinpath (vim .fn .stdpath (' state' ), ' pack-lock.json' ),
223
223
224
224
--- @param pkg pack.Package
225
225
--- @param counter function
226
- --- @param build_queue table
227
- local function clone (pkg , counter , build_queue )
226
+ local function clone (pkg , counter )
228
227
local args = vim .list_extend ({ ' git' , ' clone' , pkg .url }, Config .clone_args )
229
228
if pkg .branch then
230
229
vim .list_extend (args , { ' -b' , pkg .branch })
@@ -236,7 +235,7 @@ local function clone(pkg, counter, build_queue)
236
235
pkg .status = M .status .CLONED
237
236
lock_write ()
238
237
if pkg .build then
239
- table.insert (build_queue , pkg )
238
+ table.insert (BuildQueue , pkg )
240
239
end
241
240
end
242
241
counter (pkg .name , Messages .install , ok and ' ok' or ' err' )
245
244
246
245
--- @param pkg pack.Package
247
246
--- @param counter function
248
- --- @param build_queue table
249
- local function pull (pkg , counter , build_queue )
247
+ local function pull (pkg , counter )
250
248
local prev_hash = Lock [pkg .name ] and Lock [pkg .name ].hash or pkg .hash
251
249
vim .system (vim .list_extend ({ ' git' , ' pull' }, Config .pull_args ), { cwd = pkg .dir }, function (obj )
252
250
if obj .code ~= 0 then
@@ -268,19 +266,18 @@ local function pull(pkg, counter, build_queue)
268
266
lock_write ()
269
267
counter (pkg .name , Messages .update , ' ok' )
270
268
if pkg .build then
271
- table.insert (build_queue , pkg )
269
+ table.insert (BuildQueue , pkg )
272
270
end
273
271
end )
274
272
end
275
273
276
274
--- @param pkg pack.Package
277
275
--- @param counter function
278
- --- @param build_queue table
279
- local function clone_or_pull (pkg , counter , build_queue )
276
+ local function clone_or_pull (pkg , counter )
280
277
if Filter .to_update (pkg ) then
281
- pull (pkg , counter , build_queue )
278
+ pull (pkg , counter )
282
279
elseif Filter .to_install (pkg ) then
283
- clone (pkg , counter , build_queue )
280
+ clone (pkg , counter )
284
281
end
285
282
end
286
283
@@ -295,34 +292,41 @@ local function move(src, dst)
295
292
end
296
293
end
297
294
298
- --- @param pkg pack.Package
299
- local function run_build (pkg )
300
- local t = type (pkg .build )
301
- if t == ' function' then
302
- --- @diagnostic disable-next-line : param-type-mismatch
303
- local ok = pcall (pkg .build )
304
- report (pkg .name , Messages .build , ok and ' ok' or ' err' )
305
- elseif t == ' string' and pkg .build :sub (1 , 1 ) == ' :' then
306
- --- @diagnostic disable-next-line : param-type-mismatch
307
- local ok = pcall (vim .cmd , pkg .build )
308
- report (pkg .name , Messages .build , ok and ' ok' or ' err' )
309
- elseif t == ' string' then
310
- local args = {}
311
- for word in pkg .build :gmatch (' %S+' ) do
312
- table.insert (args , word )
295
+ local function process_build_queue ()
296
+ local failed = {}
297
+
298
+ local after = function (pkg , ok )
299
+ report (pkg .name , Messages .build , ok )
300
+ if not ok then
301
+ table.insert (failed , pkg )
313
302
end
314
- vim .system (
315
- args ,
316
- { cwd = pkg .dir },
317
- vim .schedule_wrap (
318
- function (obj ) report (pkg .name , Messages .build , obj .code == 0 and ' ok' or ' err' ) end
303
+ end
304
+
305
+ for _ , pkg in ipairs (BuildQueue ) do
306
+ local t = type (pkg .build )
307
+ if t == ' function' then
308
+ --- @diagnostic disable-next-line : param-type-mismatch
309
+ local ok = pcall (pkg .build )
310
+ after (pkg , ok )
311
+ elseif t == ' string' and vim .startswith (pkg .build , ' :' ) then
312
+ --- @diagnostic disable-next-line : param-type-mismatch
313
+ local ok = pcall (vim .cmd , pkg .build )
314
+ after (pkg , ok )
315
+ elseif t == ' string' then
316
+ local args = vim .split (pkg .build , ' %s' , { trimempty = true })
317
+ vim .system (
318
+ args ,
319
+ { cwd = pkg .dir },
320
+ vim .schedule_wrap (function (obj ) after (pkg , obj .code == 0 ) end )
319
321
)
320
- )
322
+ end
321
323
end
324
+
325
+ BuildQueue = failed
322
326
end
323
327
324
328
--- @param pkg pack.Package
325
- local function reclone (pkg , _ , build_queue )
329
+ local function reclone (pkg )
326
330
local ok = pcall (vim .fs .rm , pkg .dir , { recursive = true })
327
331
if not ok then
328
332
return
@@ -338,17 +342,17 @@ local function reclone(pkg, _, build_queue)
338
342
pkg .hash = get_git_hash (pkg .dir )
339
343
lock_write ()
340
344
if pkg .build then
341
- table.insert (build_queue , pkg )
345
+ table.insert (BuildQueue , pkg )
342
346
end
343
347
end
344
348
end )
345
349
end
346
350
347
- local function resolve (pkg , counter , build_queue )
351
+ local function resolve (pkg , counter )
348
352
if Filter .to_move (pkg ) then
349
353
move (pkg , Packages [pkg .name ])
350
354
elseif Filter .to_reclone (pkg ) then
351
- reclone (Packages [pkg .name ], counter , build_queue )
355
+ reclone (Packages [pkg .name ], counter )
352
356
end
353
357
end
354
358
@@ -409,27 +413,22 @@ end
409
413
--- @param op Operation
410
414
--- @param fn function
411
415
--- @param pkgs pack.Package[]
412
- --- @param silent boolean ?
413
- local function exe_op (op , fn , pkgs , silent )
416
+ local function exe_op (op , fn , pkgs )
414
417
if vim .tbl_isempty (pkgs ) then
415
- if not silent then
416
- vim .notify (' Pack: Nothing to ' .. op )
417
- end
418
+ vim .notify (' Pack: Nothing to ' .. op )
418
419
419
420
vim .api .nvim_exec_autocmds (' User' , {
420
421
pattern = ' PackDone' .. op :gsub (' ^%l' , string.upper ),
421
422
})
422
423
return
423
424
end
424
425
425
- local build_queue = {}
426
-
427
426
local function after (ok , err , nop )
428
427
local summary = ' Pack: %s complete. %d ok; %d errors;' .. (nop > 0 and ' %d no-ops' or ' ' )
429
428
vim .notify (string.format (summary , op , ok , err , nop ))
430
429
vim .cmd (' silent! helptags ALL' )
431
- if # build_queue ~= 0 then
432
- exe_op ( ' build ' , run_build , build_queue )
430
+ if # BuildQueue ~= 0 then
431
+ process_build_queue ( )
433
432
end
434
433
435
434
vim .api .nvim_exec_autocmds (' User' , {
@@ -443,7 +442,7 @@ local function exe_op(op, fn, pkgs, silent)
443
442
local counter = new_counter (# pkgs , after )
444
443
445
444
for _ , pkg in ipairs (pkgs ) do
446
- fn (pkg , counter , build_queue )
445
+ fn (pkg , counter )
447
446
end
448
447
end
449
448
@@ -505,7 +504,7 @@ function M.register(pkgs)
505
504
end
506
505
507
506
lock_load ()
508
- exe_op (' resolve' , resolve , calculate_diffs (), true )
507
+ exe_op (' resolve' , resolve , calculate_diffs ())
509
508
510
509
for _ , pkg in ipairs (find_unlisted ()) do
511
510
vim .opt .runtimepath :remove (pkg .dir )
@@ -567,17 +566,6 @@ for cmd_name, fn in pairs {
567
566
end
568
567
569
568
do
570
- vim .api .nvim_create_user_command (' PackBuild' , function (a ) run_build (Packages [a .args ]) end , {
571
- bar = true ,
572
- nargs = 1 ,
573
- complete = function ()
574
- return vim
575
- .iter (Packages )
576
- :map (function (name , pkg ) return pkg .build and name or nil end )
577
- :totable ()
578
- end ,
579
- })
580
-
581
569
vim .api .nvim_create_user_command (' PackList' , function ()
582
570
local installed = {}
583
571
local removed = {}
0 commit comments