Skip to content

Commit

Permalink
feat: spec.rocks is no longer needed & added support for installing a…
Browse files Browse the repository at this point in the history
…ny luarock
  • Loading branch information
folke committed Jun 24, 2024
1 parent b3ee5b9 commit fcfd548
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 236 deletions.
14 changes: 0 additions & 14 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ M.mapleader = nil
---@type string
M.maplocalleader = nil

---@type {specs:string, tree:string, path:string, cpath:string}
M.rocks = {}

function M.headless()
return #vim.api.nvim_list_uis() == 0
end
Expand Down Expand Up @@ -279,17 +276,6 @@ function M.setup(opts)
M.mapleader = vim.g.mapleader
M.maplocalleader = vim.g.maplocalleader

M.rocks = {
specs = M.options.rocks.root .. "/specs",
tree = M.options.rocks.root .. "/tree",
path = M.options.rocks.root .. "/tree/share/lua/5.1",
cpath = M.options.rocks.root .. "/tree/lib/lua/5.1",
}
vim.fn.mkdir(M.rocks.specs, "p")
vim.fn.mkdir(M.rocks.tree, "p")
package.path = package.path .. ";" .. M.rocks.path .. "/?.lua;" .. M.rocks.path .. "/?/init.lua;"
package.cpath = package.cpath .. ";" .. M.rocks.cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"

if M.headless() then
require("lazy.view.commands").setup()
end
Expand Down
16 changes: 14 additions & 2 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ function M.install_missing()
for _, plugin in pairs(Config.plugins) do
local installed = plugin._.installed
local has_errors = Plugin.has_errors(plugin)
local rocks_installed = plugin._.rocks_installed ~= false

if not has_errors and not (installed and rocks_installed) then
if not has_errors and not (installed and not plugin._.build) then
for _, colorscheme in ipairs(Config.options.install.colorscheme) do
if colorscheme == "default" then
break
Expand Down Expand Up @@ -344,6 +343,10 @@ function M._load(plugin, reason, opts)

M.add_to_rtp(plugin)

if plugin._.pkg and plugin._.pkg.source == "rockspec" then
M.add_to_luapath(plugin)
end

if plugin.dependencies then
Util.try(function()
M.load(plugin.dependencies, {})
Expand Down Expand Up @@ -487,6 +490,15 @@ function M.add_to_rtp(plugin)
vim.opt.rtp = rtp
end

---@param plugin LazyPlugin
function M.add_to_luapath(plugin)
local root = Config.options.rocks.root .. "/" .. plugin.name
local path = root .. "/share/lua/5.1"
local cpath = root .. "/lib/lua/5.1"
package.path = package.path .. ";" .. path .. "/?.lua;" .. path .. "/?/init.lua;"
package.cpath = package.cpath .. ";" .. cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
end

function M.source(path)
Util.track({ runtime = path })
Util.try(function()
Expand Down
34 changes: 20 additions & 14 deletions lua/lazy/core/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ function M:load_pkgs()
if not Config.options.pkg.enabled then
return
end
local specs = Pkg.spec()
for dir, spec in pairs(specs) do
local meta, fragment = self:add(spec)
local specs = Pkg.get()
for dir, pkg in pairs(specs) do
local meta, fragment = self:add(pkg.spec)
if meta and fragment then
meta._.pkg = pkg
-- tag all package fragments as optional
for _, fid in ipairs(meta._.frags) do
local frag = self.fragments:get(fid)
Expand Down Expand Up @@ -165,18 +166,23 @@ function M:_rebuild(name)

assert(#plugin._.frags > 0, "no fragments found for plugin " .. name)

---@type table<number, boolean>
local done = {}
for _, fid in ipairs(plugin._.frags) do
local fragment = self.fragments:get(fid)
assert(fragment, "fragment " .. fid .. " not found, for plugin " .. name)
---@diagnostic disable-next-line: no-unknown
super = setmetatable(fragment.spec, super and { __index = super } or nil)
plugin._.dep = plugin._.dep and fragment.dep
plugin.optional = plugin.optional and (rawget(fragment.spec, "optional") == true)
plugin.url = fragment.url or plugin.url

-- dependencies
for _, dep in ipairs(fragment.deps or {}) do
table.insert(plugin.dependencies, self.fragments:get(dep).name)
if not done[fid] then
done[fid] = true
local fragment = self.fragments:get(fid)
assert(fragment, "fragment " .. fid .. " not found, for plugin " .. name)
---@diagnostic disable-next-line: no-unknown
super = setmetatable(fragment.spec, super and { __index = super } or nil)
plugin._.dep = plugin._.dep and fragment.dep
plugin.optional = plugin.optional and (rawget(fragment.spec, "optional") == true)
plugin.url = fragment.url or plugin.url

-- dependencies
for _, dep in ipairs(fragment.deps or {}) do
table.insert(plugin.dependencies, self.fragments:get(dep).name)
end
end
end

Expand Down
27 changes: 22 additions & 5 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function M.update_state()
installed[name] = nil
end

require("lazy.manage.rocks").update_state()
M.update_rocks_state()

Config.to_clean = {}
for pack, dir_type in pairs(installed) do
Expand All @@ -253,6 +253,23 @@ function M.update_state()
end
end

function M.update_rocks_state()
local root = Config.options.rocks.root
---@type table<string,string>
local installed = {}
Util.ls(root, function(_, name, type)
if type == "directory" then
installed[name] = name
end
end)

for _, plugin in pairs(Config.plugins) do
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
plugin._.build = not installed[plugin.name]
end
end
end

---@param path string
function M.local_spec(path)
local file = vim.secure.read(path)
Expand Down Expand Up @@ -321,11 +338,11 @@ function M.load()
-- copy state. This wont do anything during startup
for name, plugin in pairs(existing) do
if Config.plugins[name] then
local dep = Config.plugins[name]._.dep
local frags = Config.plugins[name]._.frags
local new_state = Config.plugins[name]._
Config.plugins[name]._ = plugin._
Config.plugins[name]._.dep = dep
Config.plugins[name]._.frags = frags
Config.plugins[name]._.dep = new_state.dep
Config.plugins[name]._.frags = new_state.frags
-- Config.plugins[name]._.tasks = new_state.tasks
end
end
Util.track()
Expand Down
6 changes: 2 additions & 4 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ function M.install(opts)
pipeline = {
"git.clone",
{ "git.checkout", lockfile = opts.lockfile },
"rocks.install",
"plugin.docs",
"wait",
"plugin.build",
},
plugins = function(plugin)
return plugin.url and not (plugin._.installed and plugin._.rocks_installed ~= false)
return plugin.url and not (plugin._.installed and not plugin._.build)
end,
}, opts):wait(function()
require("lazy.manage.lock").update()
Expand All @@ -107,7 +106,6 @@ function M.update(opts)
"git.fetch",
"git.status",
{ "git.checkout", lockfile = opts.lockfile },
"rocks.install",
"plugin.docs",
"wait",
"plugin.build",
Expand Down Expand Up @@ -224,7 +222,7 @@ function M.clear(plugins)
if plugin._.tasks then
---@param task LazyTask
plugin._.tasks = vim.tbl_filter(function(task)
return task:is_running()
return task:is_running() or task.error
end, plugin._.tasks)
end
end
Expand Down
90 changes: 0 additions & 90 deletions lua/lazy/manage/rocks.lua

This file was deleted.

57 changes: 0 additions & 57 deletions lua/lazy/manage/task/rocks.lua

This file was deleted.

Loading

0 comments on commit fcfd548

Please sign in to comment.