-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
312 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
-- | ||
-- License: GPLv3 | ||
-- Created: 05 Jul 2023 | ||
-- Updated: 15 May 2024 | ||
-- Updated: 11 Jun 2024 | ||
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim | ||
-- Maintainers: NTBBloodbath <[email protected]>, Vhyrro <[email protected]>, mrcjkb <[email protected]> | ||
-- | ||
|
@@ -42,8 +42,9 @@ local default_config = { | |
---@type string Local path in your filesystem to install rocks | ||
rocks_path = default_rocks_path, | ||
---@type string Rocks declaration file path | ||
---@diagnostic disable-next-line: param-type-mismatch | ||
config_path = vim.fs.joinpath(vim.fn.stdpath("config"), "rocks.toml"), | ||
config_path = vim.fs.joinpath(vim.fn.stdpath("config") --[[@as string]], "rocks.toml"), | ||
---@type string Rocks lockfile path | ||
lockfile_path = vim.fs.joinpath(vim.fn.stdpath("config") --[[@as string]], "rocks.lock"), | ||
---@type string Luarocks binary path | ||
luarocks_binary = get_default_luarocks_binary(default_rocks_path), | ||
---@type boolean Whether to query luarocks.org lazily | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
-- | ||
-- License: GPLv3 | ||
-- Created: 07 Mar 2024 | ||
-- Updated: 19 Apr 2024 | ||
-- Updated: 11 Jun 2024 | ||
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim | ||
-- Maintainers: NTBBloodbath <[email protected]>, Vhyrro <[email protected]>, mrcjkb <[email protected]> | ||
-- | ||
|
@@ -16,6 +16,7 @@ | |
---@brief ]] | ||
|
||
local luarocks = require("rocks.luarocks") | ||
local lock = require("rocks.operations.lock") | ||
local constants = require("rocks.constants") | ||
local config = require("rocks.config.internal") | ||
local runtime = require("rocks.runtime") | ||
|
@@ -27,18 +28,18 @@ local nio = require("nio") | |
|
||
local helpers = {} | ||
|
||
---@class InstallOpts | ||
---@field use_lockfile boolean | ||
|
||
---@param rock_spec RockSpec | ||
---@param progress_handle? ProgressHandle | ||
---@param opts? InstallOpts | ||
---@return nio.control.Future | ||
helpers.install = function(rock_spec, progress_handle) | ||
helpers.install = function(rock_spec, opts) | ||
cache.invalidate_removable_rocks() | ||
local name = rock_spec.name:lower() | ||
local version = rock_spec.version | ||
local message = version and ("Installing: %s -> %s"):format(name, version) or ("Installing: %s"):format(name) | ||
log.info(message) | ||
if progress_handle then | ||
progress_handle:report({ message = message }) | ||
end | ||
-- TODO(vhyrro): Input checking on name and version | ||
local future = nio.control.future() | ||
local install_cmd = { | ||
|
@@ -62,14 +63,24 @@ helpers.install = function(rock_spec, progress_handle) | |
end | ||
end | ||
table.insert(install_cmd, 2, "--force") | ||
local install_opts = { | ||
servers = servers, | ||
} | ||
if opts and opts.use_lockfile then | ||
-- luarocks locks dependencies when there is a lockfile in the cwd | ||
local lockfile = lock.create_luarocks_lock(rock_spec.name) | ||
if lockfile and vim.uv.fs_stat(lockfile) then | ||
install_opts.cwd = vim.fs.dirname(lockfile) | ||
end | ||
end | ||
-- We always want to insert --pin so that the luarocks.lock is created in the | ||
-- install directory on the rtp | ||
table.insert(install_cmd, "--pin") | ||
luarocks.cli(install_cmd, function(sc) | ||
---@cast sc vim.SystemCompleted | ||
if sc.code ~= 0 then | ||
message = ("Failed to install %s"):format(name) | ||
log.error(message) | ||
if progress_handle then | ||
progress_handle:report({ message = message }) | ||
end | ||
future.set_error(sc.stderr) | ||
else | ||
---@type Rock | ||
|
@@ -82,22 +93,20 @@ helpers.install = function(rock_spec, progress_handle) | |
} | ||
message = ("Installed: %s -> %s"):format(installed_rock.name, installed_rock.version) | ||
log.info(message) | ||
if progress_handle then | ||
progress_handle:report({ message = message }) | ||
end | ||
|
||
nio.run(function() | ||
adapter.init_site_symlinks() | ||
if config.dynamic_rtp and not rock_spec.opt then | ||
nio.scheduler() | ||
runtime.packadd(name) | ||
else | ||
-- Add rock to the rtp, but don't source any scripts | ||
runtime.packadd(name, { bang = true }) | ||
end | ||
future.set(installed_rock) | ||
end) | ||
end | ||
end, { | ||
servers = servers, | ||
}) | ||
end, install_opts) | ||
return future | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
-- Version: 0.1.0 | ||
-- License: GPLv3 | ||
-- Created: 05 Jul 2023 | ||
-- Updated: 07 Mar 2024 | ||
-- Updated: 11 Jun 2024 | ||
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim | ||
-- Maintainers: NTBBloodbath <[email protected]>, Vhyrro <[email protected]>, mrcjkb <[email protected]> | ||
-- | ||
|
@@ -27,6 +27,7 @@ local handlers = require("rocks.operations.handlers") | |
local parser = require("rocks.operations.parser") | ||
local nio = require("nio") | ||
local progress = require("fidget.progress") | ||
local lock = require("rocks.operations.lock") | ||
|
||
local operations = {} | ||
|
||
|
@@ -200,7 +201,7 @@ operations.sync = function(user_rocks, on_complete) | |
if vim.startswith(user_rocks[key].version, "scm-") then | ||
user_rocks[key].version = "dev" | ||
end | ||
local future = helpers.install(user_rocks[key]) | ||
local future = helpers.install(user_rocks[key], { use_lockfile = true }) | ||
local success = pcall(future.wait) | ||
|
||
ct = ct + 1 | ||
|
@@ -245,7 +246,7 @@ operations.sync = function(user_rocks, on_complete) | |
message = is_downgrading and ("Downgrading: %s"):format(key) or ("Updating: %s"):format(key), | ||
}) | ||
|
||
local future = helpers.install(user_rocks[key]) | ||
local future = helpers.install(user_rocks[key], { use_lockfile = true }) | ||
local success = pcall(future.wait) | ||
|
||
ct = ct + 1 | ||
|
@@ -451,6 +452,7 @@ operations.update = function(on_complete) | |
progress_handle:report({ message = "Nothing to update!", percentage = 100 }) | ||
else | ||
fs.write_file_await(config.config_path, "w", tostring(user_rocks)) | ||
lock.update_lockfile() | ||
end | ||
nio.scheduler() | ||
if not vim.tbl_isempty(error_handles) then | ||
|
@@ -630,6 +632,7 @@ operations.add = function(arg_list, callback) | |
user_rocks.plugins[rock_name] = installed_rock.version | ||
end | ||
fs.write_file_await(config.config_path, "w", tostring(user_rocks)) | ||
lock.update_lockfile(installed_rock.name) | ||
cache.populate_removable_rock_cache() | ||
vim.schedule(function() | ||
-- Re-generate help tags | ||
|
@@ -670,6 +673,7 @@ operations.prune = function(rock_name) | |
nio.fn.keys(vim.tbl_deep_extend("force", user_config.rocks or {}, user_config.plugins or {})) | ||
local success = helpers.remove_recursive(rock_name, user_rock_names, progress_handle) | ||
fs.write_file_await(config.config_path, "w", tostring(user_config)) | ||
lock.update_lockfile() | ||
cache.populate_removable_rock_cache() | ||
vim.schedule(function() | ||
if success then | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
---@mod rocks.operations.lock | ||
-- | ||
-- Copyright (C) 2024 Neorocks Org. | ||
-- | ||
-- License: GPLv3 | ||
-- Created: 11 Jun 2024 | ||
-- Updated: 11 Jun 2024 | ||
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim | ||
-- Maintainers: NTBBloodbath <[email protected]>, Vhyrro <[email protected]>, mrcjkb <[email protected]> | ||
-- | ||
---@brief [[ | ||
-- | ||
-- Lockfile management. | ||
-- | ||
---@brief ]] | ||
|
||
local config = require("rocks.config.internal") | ||
local fs = require("rocks.fs") | ||
local nio = require("nio") | ||
|
||
local lock = {} | ||
|
||
---@param reset boolean | ||
local function parse_rocks_lock(reset) | ||
local lockfile = reset and "" or fs.read_or_create(config.lockfile_path, "") | ||
return require("toml_edit").parse(lockfile) | ||
end | ||
|
||
---@param rock_name? rock_name | ||
lock.update_lockfile = nio.create(function(rock_name) | ||
local luarocks_lockfiles = vim.iter(vim.api.nvim_get_runtime_file("luarocks.lock", true)) | ||
:filter(function(path) | ||
return not rock_name or path:find(rock_name .. "/[^%/]+/luarocks.lock$") ~= nil | ||
end) | ||
:totable() | ||
local reset = rock_name == nil | ||
local rocks_lock = parse_rocks_lock(reset) | ||
for _, luarocks_lockfile in ipairs(luarocks_lockfiles) do | ||
local rock_key = rock_name or luarocks_lockfile:match("/([^%/]+)/[^%/]+/luarocks.lock$") | ||
if rock_key then | ||
local ok, loader = pcall(loadfile, luarocks_lockfile) | ||
if not ok or not loader then | ||
return | ||
end | ||
local success, luarocks_lock_tbl = pcall(loader) | ||
if not success or not luarocks_lock_tbl or not luarocks_lock_tbl.dependencies then | ||
return | ||
end | ||
rocks_lock[rock_key] = {} | ||
local has_deps = false | ||
for dep, version in pairs(luarocks_lock_tbl.dependencies) do | ||
local is_semver = pcall(vim.version.parse, version:match("([^-]+)") or version) | ||
if is_semver and dep ~= "lua" then | ||
rocks_lock[rock_key][dep] = version | ||
has_deps = true | ||
end | ||
end | ||
if not has_deps then | ||
rocks_lock[rock_key] = nil | ||
end | ||
end | ||
end | ||
fs.write_file_await(config.lockfile_path, "w", tostring(rocks_lock)) | ||
end, 1) | ||
|
||
---@param rock_name rock_name | ||
---@return string | nil luarocks_lock | ||
lock.create_luarocks_lock = nio.create(function(rock_name) | ||
local lockfile = require("toml_edit").parse_as_tbl(fs.read_or_create(config.lockfile_path, "")) | ||
local dependencies = lockfile[rock_name] | ||
if not dependencies then | ||
return | ||
end | ||
local temp_dir = | ||
vim.fs.joinpath(vim.fn.stdpath("run") --[[@as string]], ("luarocks-lock-%X"):format(math.random(256 ^ 7))) | ||
fs.mkdir_p(temp_dir) | ||
local luarocks_lock = vim.fs.joinpath(temp_dir, "luarocks.lock") | ||
local content = ([[ | ||
return { | ||
dependencies = %s, | ||
} | ||
]]):format(vim.inspect(dependencies)) | ||
fs.write_file_await(luarocks_lock, "w", content) | ||
return luarocks_lock | ||
end, 1) | ||
|
||
return lock |
Oops, something went wrong.