Skip to content

Commit

Permalink
fix(runner): sync package specs after installing and before building
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 24, 2024
1 parent 656d3d1 commit 105d480
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
1 change: 1 addition & 0 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ function M.load()
Config.plugins[name]._ = plugin._
Config.plugins[name]._.dep = new_state.dep
Config.plugins[name]._.frags = new_state.frags
Config.plugins[name]._.pkg = new_state.pkg
end
end
Util.track()
Expand Down
18 changes: 14 additions & 4 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ function M.install(opts)
"git.clone",
{ "git.checkout", lockfile = opts.lockfile },
"plugin.docs",
"wait",
{
"wait",
sync = function()
require("lazy.pkg").update()
Plugin.load()
end,
},
"plugin.build",
},
plugins = function(plugin)
Expand All @@ -92,7 +98,6 @@ function M.install(opts)
}, opts):wait(function()
require("lazy.manage.lock").update()
require("lazy.help").update()
require("lazy.pkg").update()
end)
end

Expand All @@ -107,7 +112,13 @@ function M.update(opts)
"git.status",
{ "git.checkout", lockfile = opts.lockfile },
"plugin.docs",
"wait",
{
"wait",
sync = function()
require("lazy.pkg").update()
Plugin.load()
end,
},
"plugin.build",
{ "git.log", updated = true },
},
Expand All @@ -117,7 +128,6 @@ function M.update(opts)
}, opts):wait(function()
require("lazy.manage.lock").update()
require("lazy.help").update()
require("lazy.pkg").update()
end)
end
--
Expand Down
59 changes: 41 additions & 18 deletions lua/lazy/manage/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ local Util = require("lazy.util")
---@field concurrency? number

---@alias PipelineStep {task:string, opts?:TaskOptions}
---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: LazyPlugin}
---@alias LazyRunnerTask {co:thread, status: {task?:LazyTask, waiting?:boolean}, plugin: string}

---@class Runner
---@field _plugins LazyPlugin[]
---@field _plugins string[]
---@field _running LazyRunnerTask[]
---@field _pipeline PipelineStep[]
---@field _sync PipelineStep[]
---@field _on_done fun()[]
---@field _syncing boolean
---@field _opts RunnerOpts
local Runner = {}

Expand All @@ -24,13 +26,11 @@ function Runner.new(opts)
self._opts = opts or {}

local plugins = self._opts.plugins
if type(plugins) == "function" then
self._plugins = vim.tbl_filter(plugins, Config.plugins)
else
self._plugins = plugins or Config.plugins
end
self._plugins = vim.tbl_map(function(plugin)
return plugin.name
end, type(plugins) == "function" and vim.tbl_filter(plugins, Config.plugins) or plugins or Config.plugins)
table.sort(self._plugins, function(a, b)
return a.name < b.name
return a < b
end)
self._running = {}
self._on_done = {}
Expand All @@ -40,6 +40,10 @@ function Runner.new(opts)
return type(step) == "string" and { task = step } or { task = step[1], opts = step }
end, self._opts.pipeline)

self._sync = vim.tbl_filter(function(step)
return step.task == "wait"
end, self._pipeline)

return self
end

Expand All @@ -57,14 +61,31 @@ function Runner:_resume(entry)
end

function Runner:resume(waiting)
if self._syncing then
return true
end
if waiting then
for _, entry in ipairs(self._running) do
if entry.status then
if entry.status.waiting then
entry.status.waiting = false
entry.plugin._.working = true
local sync = self._sync[1]
table.remove(self._sync, 1)
if sync then
self._syncing = true
vim.schedule(function()
if sync.opts and type(sync.opts.sync) == "function" then
sync.opts.sync(self)
end
end
for _, entry in ipairs(self._running) do
if entry.status then
if entry.status.waiting then
entry.status.waiting = false
local plugin = Config.plugins[entry.plugin]
if plugin then
plugin._.working = true
end
end
end
end
self._syncing = false
end)
end
end
local running = 0
Expand All @@ -78,7 +99,7 @@ function Runner:resume(waiting)
end
end
end
return running > 0 or (not waiting and self:resume(true))
return self._syncing or running > 0 or (not waiting and self:resume(true))
end

function Runner:start()
Expand All @@ -88,7 +109,7 @@ function Runner:start()
if ok then
table.insert(self._running, { co = co, status = {}, plugin = plugin })
else
Util.error("Could not start tasks for " .. plugin.name .. "\n" .. err)
Util.error("Could not start tasks for " .. plugin .. "\n" .. err)
end
end

Expand All @@ -107,8 +128,9 @@ function Runner:start()
end

---@async
---@param plugin LazyPlugin
function Runner:run_pipeline(plugin)
---@param name string
function Runner:run_pipeline(name)
local plugin = Config.plugins[name]
plugin._.working = true
coroutine.yield()
for _, step in ipairs(self._pipeline) do
Expand All @@ -117,6 +139,7 @@ function Runner:run_pipeline(plugin)
coroutine.yield({ waiting = true })
plugin._.working = true
else
plugin = Config.plugins[name] or plugin
local task = self:queue(plugin, step.task, step.opts)
if task then
coroutine.yield({ task = task })
Expand Down
4 changes: 2 additions & 2 deletions lua/lazy/pkg/rockspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function M.deps(plugin)
local root = Config.options.rocks.root .. "/" .. plugin.name
local manifest_file = root .. "/lib/luarocks/rocks-5.1/manifest"
local manifest = {}
local ok = pcall(function()
pcall(function()
local load, err = loadfile(manifest_file, "t", manifest)
if not load then
error(err)
end
load()
end)
return manifest and vim.tbl_keys(manifest.repository or {})
return vim.tbl_keys(manifest.repository or {})
end

---@class RockSpec
Expand Down

0 comments on commit 105d480

Please sign in to comment.