mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #21663 lua: "nvim -l" scriptname in _G.arg[0]
This commit is contained in:
commit
42afa0369a
@ -64,7 +64,7 @@ Third-party dependencies
|
|||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
These "bundled" dependencies can be updated by bumping their versions in `cmake.deps/CMakeLists.txt`.
|
These "bundled" dependencies can be updated by bumping their versions in `cmake.deps/CMakeLists.txt`.
|
||||||
Some can be auto-bumped by `scripts/bump-deps.sh`.
|
Some can be auto-bumped by `scripts/bump_deps.lua`.
|
||||||
|
|
||||||
* [LuaJIT](https://github.com/LuaJIT/LuaJIT)
|
* [LuaJIT](https://github.com/LuaJIT/LuaJIT)
|
||||||
* [Lua](https://www.lua.org/download.html)
|
* [Lua](https://www.lua.org/download.html)
|
||||||
|
@ -218,15 +218,13 @@ argument.
|
|||||||
-l {script} [args]
|
-l {script} [args]
|
||||||
Executes Lua {script} non-interactively (no UI) with optional
|
Executes Lua {script} non-interactively (no UI) with optional
|
||||||
[args] after processing any preceding Nvim |cli-arguments|,
|
[args] after processing any preceding Nvim |cli-arguments|,
|
||||||
then exits. See |-S| to run multiple Lua scripts without args,
|
then exits. Exits 1 on Lua error. See |-S| to run multiple Lua
|
||||||
or in an interactive session.
|
scripts without args, with a UI.
|
||||||
*lua-args*
|
*lua-args*
|
||||||
All [args] are treated as {script} arguments and passed
|
All [args] are treated as {script} arguments and stored in the
|
||||||
literally to Lua (in the conventional `_G.arg` global table),
|
Lua `_G.arg` global table, thus "-l" ends processing of Nvim
|
||||||
thus "-l" ends processing of Nvim arguments.
|
arguments. The {script} name is stored at `_G.arg[0]`.
|
||||||
|
|
||||||
Exits with code 1 on Lua error.
|
|
||||||
|
|
||||||
Sets 'verbose' to 1 (like "-V1"), so Lua `print()` writes to
|
Sets 'verbose' to 1 (like "-V1"), so Lua `print()` writes to
|
||||||
output.
|
output.
|
||||||
|
|
||||||
|
@ -1,108 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
set -u
|
|
||||||
# Use privileged mode, which e.g. skips using CDPATH.
|
|
||||||
set -p
|
|
||||||
|
|
||||||
# Ensure that the user has a bash that supports -A
|
|
||||||
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
|
|
||||||
echo >&2 "error: script requires bash 4+ (you have ${BASH_VERSION})."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
readonly NVIM_SOURCE_DIR="${NVIM_SOURCE_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
|
|
||||||
readonly VIM_SOURCE_DIR_DEFAULT="${NVIM_SOURCE_DIR}/.vim-src"
|
|
||||||
readonly VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}"
|
|
||||||
BASENAME="$(basename "${0}")"
|
|
||||||
readonly BASENAME
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "Bump Nvim dependencies"
|
|
||||||
echo
|
|
||||||
echo "Usage: ${BASENAME} [ -h | --pr | --branch=<dep> | --dep=<dependency> ]"
|
|
||||||
echo " Update a dependency:"
|
|
||||||
echo " ./scripts/bump-deps.sh --dep Luv --version 1.43.0-0"
|
|
||||||
echo " Create a PR:"
|
|
||||||
echo " ./scripts/bump-deps.sh --pr"
|
|
||||||
echo
|
|
||||||
echo "Options:"
|
|
||||||
echo " -h show this message and exit."
|
|
||||||
echo " --pr submit pr for bumping deps."
|
|
||||||
echo " --branch=<dep> create a branch bump-<dep> from current branch."
|
|
||||||
echo " --dep=<dependency> bump to a specific release or tag."
|
|
||||||
echo
|
|
||||||
echo "Dependency Options:"
|
|
||||||
echo " --version=<tag> bump to a specific release or tag."
|
|
||||||
echo " --commit=<hash> bump to a specific commit."
|
|
||||||
echo " --HEAD bump to a current head."
|
|
||||||
echo
|
|
||||||
echo " <dependency> is one of:"
|
|
||||||
echo " \"LuaJIT\", \"libuv\", \"Luv\", \"tree-sitter\""
|
|
||||||
}
|
|
||||||
|
|
||||||
# Checks if a program is in the user's PATH, and is executable.
|
|
||||||
check_executable() {
|
|
||||||
test -x "$(command -v "${1}")"
|
|
||||||
}
|
|
||||||
|
|
||||||
require_executable() {
|
|
||||||
if ! check_executable "${1}"; then
|
|
||||||
echo >&2 "${BASENAME}: '${1}' not found in PATH or not executable."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
require_executable "nvim"
|
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PARSED_ARGS=$(getopt -a -n "$BASENAME" -o h --long pr,branch:,dep:,version:,commit:,HEAD -- "$@")
|
|
||||||
|
|
||||||
DEPENDENCY=""
|
|
||||||
eval set -- "$PARSED_ARGS"
|
|
||||||
while :; do
|
|
||||||
case "$1" in
|
|
||||||
-h)
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
--pr)
|
|
||||||
nvim -es +"lua require('scripts.bump_deps').submit_pr()"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
--branch)
|
|
||||||
DEP=$2
|
|
||||||
nvim -es +"lua require('scripts.bump_deps').create_branch('$DEP')"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
--dep)
|
|
||||||
DEPENDENCY=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
--version)
|
|
||||||
VERSION=$2
|
|
||||||
nvim -es +"lua require('scripts.bump_deps').version('$DEPENDENCY', '$VERSION')"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
--commit)
|
|
||||||
COMMIT=$2
|
|
||||||
nvim -es +"lua require('scripts.bump_deps').commit('$DEPENDENCY', '$COMMIT')"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
--HEAD)
|
|
||||||
nvim -es +"lua require('scripts.bump_deps').head('$DEPENDENCY')"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
# vim: et sw=2
|
|
563
scripts/bump_deps.lua
Normal file → Executable file
563
scripts/bump_deps.lua
Normal file → Executable file
@ -1,35 +1,24 @@
|
|||||||
|
#!/usr/bin/env -S nvim -l
|
||||||
|
|
||||||
-- Usage:
|
-- Usage:
|
||||||
-- # bump to version
|
-- ./scripts/bump_deps.lua -h
|
||||||
-- nvim -es +"lua require('scripts.bump_deps').version(dependency, version_tag)"
|
|
||||||
--
|
|
||||||
-- # bump to commit
|
|
||||||
-- nvim -es +"lua require('scripts.bump_deps').commit(dependency, commit_hash)"
|
|
||||||
--
|
|
||||||
-- # bump to HEAD
|
|
||||||
-- nvim -es +"lua require('scripts.bump_deps').head(dependency)"
|
|
||||||
--
|
|
||||||
-- # submit PR
|
|
||||||
-- nvim -es +"lua require('scripts.bump_deps').submit_pr()"
|
|
||||||
--
|
|
||||||
-- # create branch
|
|
||||||
-- nvim -es +"lua require('scripts.bump_deps').create_branch()"
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local _trace = false
|
local _trace = false
|
||||||
local required_branch_prefix = "bump-"
|
local required_branch_prefix = 'bump-'
|
||||||
local commit_prefix = "build(deps): "
|
local commit_prefix = 'build(deps): '
|
||||||
|
|
||||||
-- Print message
|
-- Print message
|
||||||
local function p(s)
|
local function p(s)
|
||||||
vim.cmd("set verbose=1")
|
vim.cmd('set verbose=1')
|
||||||
vim.api.nvim_echo({ { s, "" } }, false, {})
|
vim.api.nvim_echo({ { s, '' } }, false, {})
|
||||||
vim.cmd("set verbose=0")
|
vim.cmd('set verbose=0')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function die()
|
local function die()
|
||||||
p("")
|
p('')
|
||||||
vim.cmd("cquit 1")
|
vim.cmd('cquit 1')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Executes and returns the output of `cmd`, or nil on failure.
|
-- Executes and returns the output of `cmd`, or nil on failure.
|
||||||
@ -37,307 +26,421 @@ end
|
|||||||
--
|
--
|
||||||
-- Prints `cmd` if `trace` is enabled.
|
-- Prints `cmd` if `trace` is enabled.
|
||||||
local function _run(cmd, die_on_fail, die_msg)
|
local function _run(cmd, die_on_fail, die_msg)
|
||||||
if _trace then
|
if _trace then
|
||||||
p("run: " .. vim.inspect(cmd))
|
p('run: ' .. vim.inspect(cmd))
|
||||||
end
|
end
|
||||||
local rv = vim.trim(vim.fn.system(cmd)) or ""
|
local rv = vim.trim(vim.fn.system(cmd)) or ''
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
if die_on_fail then
|
if die_on_fail then
|
||||||
if _trace then
|
if _trace then
|
||||||
p(rv)
|
p(rv)
|
||||||
end
|
end
|
||||||
p(die_msg)
|
p(die_msg)
|
||||||
die()
|
die()
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
return rv
|
return rv
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Run a command, return nil on failure
|
-- Run a command, return nil on failure
|
||||||
local function run(cmd)
|
local function run(cmd)
|
||||||
return _run(cmd, false, "")
|
return _run(cmd, false, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Run a command, die on failure with err_msg
|
-- Run a command, die on failure with err_msg
|
||||||
local function run_die(cmd, err_msg)
|
local function run_die(cmd, err_msg)
|
||||||
return _run(cmd, true, err_msg)
|
return _run(cmd, true, err_msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function require_executable(cmd)
|
local function require_executable(cmd)
|
||||||
local cmd_path = run_die({ "command", "-v", cmd }, cmd .. " not found!")
|
local cmd_path = run_die({ 'command', '-v', cmd }, cmd .. ' not found!')
|
||||||
run_die({ "test", "-x", cmd_path }, cmd .. " is not executable")
|
run_die({ 'test', '-x', cmd_path }, cmd .. ' is not executable')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function rm_file_if_present(path_to_file)
|
local function rm_file_if_present(path_to_file)
|
||||||
run({ "rm", "-f", path_to_file })
|
run({ 'rm', '-f', path_to_file })
|
||||||
end
|
end
|
||||||
|
|
||||||
local nvim_src_dir = vim.fn.getcwd()
|
local nvim_src_dir = vim.fn.getcwd()
|
||||||
local temp_dir = nvim_src_dir .. "/tmp"
|
local temp_dir = nvim_src_dir .. '/tmp'
|
||||||
run({ "mkdir", "-p", temp_dir })
|
run({ 'mkdir', '-p', temp_dir })
|
||||||
|
|
||||||
local function get_dependency(dependency_name)
|
local function get_dependency(dependency_name)
|
||||||
local dependency_table = {
|
local dependency_table = {
|
||||||
["LuaJIT"] = {
|
['LuaJIT'] = {
|
||||||
repo = "LuaJIT/LuaJIT",
|
repo = 'LuaJIT/LuaJIT',
|
||||||
symbol = "LUAJIT",
|
symbol = 'LUAJIT',
|
||||||
},
|
},
|
||||||
["libuv"] = {
|
['libuv'] = {
|
||||||
repo = "libuv/libuv",
|
repo = 'libuv/libuv',
|
||||||
symbol = "LIBUV",
|
symbol = 'LIBUV',
|
||||||
},
|
},
|
||||||
["Luv"] = {
|
['Luv'] = {
|
||||||
repo = "luvit/luv",
|
repo = 'luvit/luv',
|
||||||
symbol = "LUV",
|
symbol = 'LUV',
|
||||||
},
|
},
|
||||||
["tree-sitter"] = {
|
['tree-sitter'] = {
|
||||||
repo = "tree-sitter/tree-sitter",
|
repo = 'tree-sitter/tree-sitter',
|
||||||
symbol = "TREESITTER",
|
symbol = 'TREESITTER',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
local dependency = dependency_table[dependency_name]
|
local dependency = dependency_table[dependency_name]
|
||||||
if dependency == nil then
|
if dependency == nil then
|
||||||
p("Not a dependency: " .. dependency_name)
|
p('Not a dependency: ' .. dependency_name)
|
||||||
die()
|
die()
|
||||||
end
|
end
|
||||||
dependency.name = dependency_name
|
dependency.name = dependency_name
|
||||||
return dependency
|
return dependency
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_gh_commit_sha(repo, ref)
|
local function get_gh_commit_sha(repo, ref)
|
||||||
require_executable("gh")
|
require_executable('gh')
|
||||||
|
|
||||||
local sha = run_die(
|
local sha = run_die(
|
||||||
{ "gh", "api", "repos/" .. repo .. "/commits/" .. ref, "--jq", ".sha" },
|
{ 'gh', 'api', 'repos/' .. repo .. '/commits/' .. ref, '--jq', '.sha' },
|
||||||
"Failed to get commit hash from GitHub. Not a valid ref?"
|
'Failed to get commit hash from GitHub. Not a valid ref?'
|
||||||
)
|
)
|
||||||
return sha
|
return sha
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_archive_info(repo, ref)
|
local function get_archive_info(repo, ref)
|
||||||
require_executable("curl")
|
require_executable('curl')
|
||||||
|
|
||||||
local archive_name = ref .. ".tar.gz"
|
local archive_name = ref .. '.tar.gz'
|
||||||
local archive_path = temp_dir .. "/" .. archive_name
|
local archive_path = temp_dir .. '/' .. archive_name
|
||||||
local archive_url = "https://github.com/" .. repo .. "/archive/" .. archive_name
|
local archive_url = 'https://github.com/' .. repo .. '/archive/' .. archive_name
|
||||||
|
|
||||||
rm_file_if_present(archive_path)
|
rm_file_if_present(archive_path)
|
||||||
run_die({ "curl", "-sL", archive_url, "-o", archive_path }, "Failed to download archive from GitHub")
|
run_die(
|
||||||
|
{ 'curl', '-sL', archive_url, '-o', archive_path },
|
||||||
|
'Failed to download archive from GitHub'
|
||||||
|
)
|
||||||
|
|
||||||
local archive_sha = run({ "sha256sum", archive_path }):gmatch("%w+")()
|
local shacmd = (vim.fn.executable('sha256sum') == 1
|
||||||
return { url = archive_url, sha = archive_sha }
|
and{ 'sha256sum', archive_path }
|
||||||
|
or { 'shasum', '-a', '256', archive_path })
|
||||||
|
local archive_sha = run(shacmd):gmatch('%w+')()
|
||||||
|
return { url = archive_url, sha = archive_sha }
|
||||||
end
|
end
|
||||||
|
|
||||||
local function write_cmakelists_line(symbol, kind, value)
|
local function write_cmakelists_line(symbol, kind, value)
|
||||||
require_executable("sed")
|
require_executable('sed')
|
||||||
|
|
||||||
local cmakelists_path = nvim_src_dir .. "/" .. "cmake.deps/CMakeLists.txt"
|
local cmakelists_path = nvim_src_dir .. '/' .. 'cmake.deps/CMakeLists.txt'
|
||||||
run_die({
|
run_die({
|
||||||
"sed",
|
'sed',
|
||||||
"-i",
|
'-i',
|
||||||
"-e",
|
'-e',
|
||||||
"s/set(" .. symbol .. "_" .. kind .. ".*$" .. "/set(" .. symbol .. "_" .. kind .. " " .. value .. ")" .. "/",
|
's/set('
|
||||||
cmakelists_path,
|
.. symbol
|
||||||
}, "Failed to write " .. cmakelists_path)
|
.. '_'
|
||||||
|
.. kind
|
||||||
|
.. '.*$'
|
||||||
|
.. '/set('
|
||||||
|
.. symbol
|
||||||
|
.. '_'
|
||||||
|
.. kind
|
||||||
|
.. ' '
|
||||||
|
.. value
|
||||||
|
.. ')'
|
||||||
|
.. '/',
|
||||||
|
cmakelists_path,
|
||||||
|
}, 'Failed to write ' .. cmakelists_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function explicit_create_branch(dep)
|
local function explicit_create_branch(dep)
|
||||||
require_executable("git")
|
require_executable('git')
|
||||||
|
|
||||||
local checked_out_branch = run({ "git", "rev-parse", "--abbrev-ref", "HEAD" })
|
local checked_out_branch = run({ 'git', 'rev-parse', '--abbrev-ref', 'HEAD' })
|
||||||
if checked_out_branch ~= "master" then
|
if checked_out_branch ~= 'master' then
|
||||||
p("Not on master!")
|
p('Not on master!')
|
||||||
die()
|
die()
|
||||||
end
|
end
|
||||||
run_die({ "git", "checkout", "-b", "bump-" .. dep }, "git failed to create branch")
|
run_die({ 'git', 'checkout', '-b', 'bump-' .. dep }, 'git failed to create branch')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function verify_branch(new_branch_suffix)
|
local function verify_branch(new_branch_suffix)
|
||||||
require_executable("git")
|
require_executable('git')
|
||||||
|
|
||||||
local checked_out_branch = run({ "git", "rev-parse", "--abbrev-ref", "HEAD" })
|
local checked_out_branch = assert(run({ 'git', 'rev-parse', '--abbrev-ref', 'HEAD' }))
|
||||||
if not checked_out_branch:match("^" .. required_branch_prefix) then
|
if not checked_out_branch:match('^' .. required_branch_prefix) then
|
||||||
p("Current branch '" .. checked_out_branch .. "' doesn't seem to start with " .. required_branch_prefix)
|
p(
|
||||||
p("Checking out to bump-" .. new_branch_suffix)
|
"Current branch '"
|
||||||
explicit_create_branch(new_branch_suffix)
|
.. checked_out_branch
|
||||||
end
|
.. "' doesn't seem to start with "
|
||||||
|
.. required_branch_prefix
|
||||||
|
)
|
||||||
|
p('Checking out to bump-' .. new_branch_suffix)
|
||||||
|
explicit_create_branch(new_branch_suffix)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_cmakelists(dependency, archive, comment)
|
local function update_cmakelists(dependency, archive, comment)
|
||||||
require_executable("git")
|
require_executable('git')
|
||||||
|
|
||||||
verify_branch(dependency.name)
|
verify_branch(dependency.name)
|
||||||
|
|
||||||
local changed_file = nvim_src_dir .. "/" .. "cmake.deps/CMakeLists.txt"
|
local changed_file = nvim_src_dir .. '/' .. 'cmake.deps/CMakeLists.txt'
|
||||||
|
|
||||||
p("Updating " .. dependency.name .. " to " .. archive.url .. "\n")
|
p('Updating ' .. dependency.name .. ' to ' .. archive.url .. '\n')
|
||||||
write_cmakelists_line(dependency.symbol, "URL", archive.url:gsub("/", "\\/"))
|
write_cmakelists_line(dependency.symbol, 'URL', archive.url:gsub('/', '\\/'))
|
||||||
write_cmakelists_line(dependency.symbol, "SHA256", archive.sha)
|
write_cmakelists_line(dependency.symbol, 'SHA256', archive.sha)
|
||||||
run_die(
|
run_die(
|
||||||
{ "git", "commit", changed_file, "-m", commit_prefix .. "bump " .. dependency.name .. " to " .. comment },
|
{
|
||||||
"git failed to commit"
|
'git',
|
||||||
)
|
'commit',
|
||||||
|
changed_file,
|
||||||
|
'-m',
|
||||||
|
commit_prefix .. 'bump ' .. dependency.name .. ' to ' .. comment,
|
||||||
|
},
|
||||||
|
'git failed to commit'
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function verify_cmakelists_committed()
|
local function verify_cmakelists_committed()
|
||||||
require_executable("git")
|
require_executable('git')
|
||||||
|
|
||||||
local cmakelists_path = nvim_src_dir .. "/" .. "cmake.deps/CMakeLists.txt"
|
local cmakelists_path = nvim_src_dir .. '/' .. 'cmake.deps/CMakeLists.txt'
|
||||||
run_die({ "git", "diff", "--quiet", "HEAD", "--", cmakelists_path }, cmakelists_path .. " has uncommitted changes")
|
run_die(
|
||||||
|
{ 'git', 'diff', '--quiet', 'HEAD', '--', cmakelists_path },
|
||||||
|
cmakelists_path .. ' has uncommitted changes'
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function warn_luv_symbol()
|
local function warn_luv_symbol()
|
||||||
p("warning: " .. get_dependency("Luv").symbol .. "_VERSION will not be updated")
|
p('warning: ' .. get_dependency('Luv').symbol .. '_VERSION will not be updated')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- return first 9 chars of commit
|
-- return first 9 chars of commit
|
||||||
local function short_commit(commit)
|
local function short_commit(commit)
|
||||||
return string.sub(commit, 1, 9)
|
return string.sub(commit, 1, 9)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: remove hardcoded fork
|
-- TODO: remove hardcoded fork
|
||||||
local function gh_pr(pr_title, pr_body)
|
local function gh_pr(pr_title, pr_body)
|
||||||
require_executable("gh")
|
require_executable('gh')
|
||||||
|
|
||||||
local pr_url = run_die({
|
local pr_url = run_die({
|
||||||
"gh",
|
'gh',
|
||||||
"pr",
|
'pr',
|
||||||
"create",
|
'create',
|
||||||
"--title",
|
'--title',
|
||||||
pr_title,
|
pr_title,
|
||||||
"--body",
|
'--body',
|
||||||
pr_body,
|
pr_body,
|
||||||
}, "Failed to create PR")
|
}, 'Failed to create PR')
|
||||||
return pr_url
|
return pr_url
|
||||||
end
|
end
|
||||||
|
|
||||||
local function find_git_remote(fork)
|
local function find_git_remote(fork)
|
||||||
require_executable("git")
|
require_executable('git')
|
||||||
|
|
||||||
local remotes = run({ "git", "remote", "-v" })
|
local remotes = assert(run({ 'git', 'remote', '-v' }))
|
||||||
local git_remote = ""
|
local git_remote = ''
|
||||||
for remote in remotes:gmatch("[^\r\n]+") do
|
for remote in remotes:gmatch('[^\r\n]+') do
|
||||||
local words = {}
|
local words = {}
|
||||||
for word in remote:gmatch("%w+") do
|
for word in remote:gmatch('%w+') do
|
||||||
table.insert(words, word)
|
table.insert(words, word)
|
||||||
end
|
end
|
||||||
local match = words[1]:match("/github.com[:/]neovim/neovim/")
|
local match = words[1]:match('/github.com[:/]neovim/neovim/')
|
||||||
if fork == "fork" then
|
if fork == 'fork' then
|
||||||
match = not match
|
match = not match
|
||||||
end
|
end
|
||||||
if match and words[3] == "(fetch)" then
|
if match and words[3] == '(fetch)' then
|
||||||
git_remote = words[0]
|
git_remote = words[0]
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if git_remote == "" then
|
if git_remote == '' then
|
||||||
git_remote = "origin"
|
git_remote = 'origin'
|
||||||
end
|
end
|
||||||
return git_remote
|
return git_remote
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_pr(pr_title, pr_body)
|
local function create_pr(pr_title, pr_body)
|
||||||
require_executable("git")
|
require_executable('git')
|
||||||
|
|
||||||
local push_first = true
|
local push_first = true
|
||||||
|
|
||||||
local checked_out_branch = run({ "git", "rev-parse", "--abbrev-ref", "HEAD" })
|
local checked_out_branch = run({ 'git', 'rev-parse', '--abbrev-ref', 'HEAD' })
|
||||||
if push_first then
|
if push_first then
|
||||||
local push_remote = run({ "git", "config", "--get", "branch." .. checked_out_branch .. ".pushRemote" })
|
local push_remote =
|
||||||
if push_remote == nil then
|
run({ 'git', 'config', '--get', 'branch.' .. checked_out_branch .. '.pushRemote' })
|
||||||
push_remote = run({ "git", "config", "--get", "remote.pushDefault" })
|
if push_remote == nil then
|
||||||
if push_remote == nil then
|
push_remote = run({ 'git', 'config', '--get', 'remote.pushDefault' })
|
||||||
push_remote = run({ "git", "config", "--get", "branch." .. checked_out_branch .. ".remote" })
|
if push_remote == nil then
|
||||||
if push_remote == nil or push_remote == find_git_remote(nil) then
|
push_remote =
|
||||||
push_remote = find_git_remote("fork")
|
run({ 'git', 'config', '--get', 'branch.' .. checked_out_branch .. '.remote' })
|
||||||
end
|
if push_remote == nil or push_remote == find_git_remote(nil) then
|
||||||
end
|
push_remote = find_git_remote('fork')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
p("Pushing to " .. push_remote .. "/" .. checked_out_branch)
|
p('Pushing to ' .. push_remote .. '/' .. checked_out_branch)
|
||||||
run_die({ "git", "push", push_remote, checked_out_branch }, "Git failed to push")
|
run_die({ 'git', 'push', push_remote, checked_out_branch }, 'Git failed to push')
|
||||||
end
|
end
|
||||||
|
|
||||||
local pr_url = gh_pr(pr_title, pr_body)
|
local pr_url = gh_pr(pr_title, pr_body)
|
||||||
p("\nCreated PR: " .. pr_url .. "\n")
|
p('\nCreated PR: ' .. pr_url .. '\n')
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.commit(dependency_name, commit)
|
function M.commit(dependency_name, commit)
|
||||||
local dependency = get_dependency(dependency_name)
|
local dependency = assert(get_dependency(dependency_name))
|
||||||
verify_cmakelists_committed()
|
verify_cmakelists_committed()
|
||||||
local commit_sha = get_gh_commit_sha(dependency.repo, commit)
|
local commit_sha = get_gh_commit_sha(dependency.repo, commit)
|
||||||
if commit_sha ~= commit then
|
if commit_sha ~= commit then
|
||||||
p("Not a commit: " .. commit .. ". Did you mean version?")
|
p('Not a commit: ' .. commit .. '. Did you mean version?')
|
||||||
die()
|
die()
|
||||||
end
|
end
|
||||||
local archive = get_archive_info(dependency.repo, commit)
|
local archive = get_archive_info(dependency.repo, commit)
|
||||||
if dependency_name == "Luv" then
|
if dependency_name == 'Luv' then
|
||||||
warn_luv_symbol()
|
warn_luv_symbol()
|
||||||
end
|
end
|
||||||
update_cmakelists(dependency, archive, short_commit(commit))
|
update_cmakelists(dependency, archive, short_commit(commit))
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.version(dependency_name, version)
|
function M.version(dependency_name, version)
|
||||||
local dependency = get_dependency(dependency_name)
|
vim.validate{
|
||||||
verify_cmakelists_committed()
|
dependency_name={dependency_name,'s'},
|
||||||
local commit_sha = get_gh_commit_sha(dependency.repo, version)
|
version={version,'s'},
|
||||||
if commit_sha == version then
|
}
|
||||||
p("Not a version: " .. version .. ". Did you mean commit?")
|
local dependency = assert(get_dependency(dependency_name))
|
||||||
die()
|
verify_cmakelists_committed()
|
||||||
end
|
local commit_sha = get_gh_commit_sha(dependency.repo, version)
|
||||||
local archive = get_archive_info(dependency.repo, version)
|
if commit_sha == version then
|
||||||
if dependency_name == "Luv" then
|
p('Not a version: ' .. version .. '. Did you mean commit?')
|
||||||
write_cmakelists_line(dependency.symbol, "VERSION", version)
|
die()
|
||||||
end
|
end
|
||||||
update_cmakelists(dependency, archive, version)
|
local archive = get_archive_info(dependency.repo, version)
|
||||||
|
if dependency_name == 'Luv' then
|
||||||
|
write_cmakelists_line(dependency.symbol, 'VERSION', version)
|
||||||
|
end
|
||||||
|
update_cmakelists(dependency, archive, version)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.head(dependency_name)
|
function M.head(dependency_name)
|
||||||
local dependency = get_dependency(dependency_name)
|
local dependency = assert(get_dependency(dependency_name))
|
||||||
verify_cmakelists_committed()
|
verify_cmakelists_committed()
|
||||||
local commit_sha = get_gh_commit_sha(dependency.repo, "HEAD")
|
local commit_sha = get_gh_commit_sha(dependency.repo, 'HEAD')
|
||||||
local archive = get_archive_info(dependency.repo, commit_sha)
|
local archive = get_archive_info(dependency.repo, commit_sha)
|
||||||
if dependency_name == "Luv" then
|
if dependency_name == 'Luv' then
|
||||||
warn_luv_symbol()
|
warn_luv_symbol()
|
||||||
end
|
end
|
||||||
update_cmakelists(dependency, archive, "HEAD - " .. short_commit(commit_sha))
|
update_cmakelists(dependency, archive, 'HEAD - ' .. short_commit(commit_sha))
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_branch(dep)
|
function M.create_branch(dep)
|
||||||
explicit_create_branch(dep)
|
explicit_create_branch(dep)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.submit_pr()
|
function M.submit_pr()
|
||||||
require_executable("git")
|
require_executable('git')
|
||||||
|
|
||||||
verify_branch("deps")
|
verify_branch('deps')
|
||||||
|
|
||||||
local nvim_remote = find_git_remote(nil)
|
local nvim_remote = find_git_remote(nil)
|
||||||
local relevant_commit = run_die({
|
local relevant_commit = assert(run_die({
|
||||||
"git",
|
'git',
|
||||||
"log",
|
'log',
|
||||||
"--grep=" .. commit_prefix,
|
'--grep=' .. commit_prefix,
|
||||||
"--reverse",
|
'--reverse',
|
||||||
"--format='%s'",
|
"--format='%s'",
|
||||||
nvim_remote .. "/master..HEAD",
|
nvim_remote .. '/master..HEAD',
|
||||||
"-1",
|
'-1',
|
||||||
}, "Failed to fetch commits")
|
}, 'Failed to fetch commits'))
|
||||||
|
|
||||||
local pr_title
|
local pr_title
|
||||||
local pr_body
|
local pr_body
|
||||||
|
|
||||||
if relevant_commit == "" then
|
if relevant_commit == '' then
|
||||||
pr_title = commit_prefix .. "bump some dependencies"
|
pr_title = commit_prefix .. 'bump some dependencies'
|
||||||
pr_body = "bump some dependencies"
|
pr_body = 'bump some dependencies'
|
||||||
else
|
else
|
||||||
relevant_commit = relevant_commit:gsub("'", "")
|
relevant_commit = relevant_commit:gsub("'", '')
|
||||||
pr_title = relevant_commit
|
pr_title = relevant_commit
|
||||||
pr_body = relevant_commit:gsub(commit_prefix:gsub("%(", "%%("):gsub("%)", "%%)"), "")
|
pr_body = relevant_commit:gsub(commit_prefix:gsub('%(', '%%('):gsub('%)', '%%)'), '')
|
||||||
end
|
end
|
||||||
pr_body = pr_body .. "\n\n(add explanations if needed)"
|
pr_body = pr_body .. '\n\n(add explanations if needed)'
|
||||||
p(pr_title .. "\n" .. pr_body .. "\n")
|
p(pr_title .. '\n' .. pr_body .. '\n')
|
||||||
create_pr(pr_title, pr_body)
|
create_pr(pr_title, pr_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
local function usage()
|
||||||
|
local this_script = _G.arg[0]:match("[^/]*.lua$")
|
||||||
|
print(([=[
|
||||||
|
Bump Nvim dependencies
|
||||||
|
|
||||||
|
Usage: nvim -l %s [options]
|
||||||
|
Bump to HEAD, tagged version, commit, or branch:
|
||||||
|
nvim -l %s --dep Luv --head
|
||||||
|
nvim -l %s --dep Luv --version 1.43.0-0
|
||||||
|
nvim -l %s --dep Luv --commit abc123
|
||||||
|
nvim -l %s --dep Luv --branch
|
||||||
|
Create a PR:
|
||||||
|
nvim -l %s --pr
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h show this message and exit.
|
||||||
|
--pr submit pr for bumping deps.
|
||||||
|
--branch <dep> create a branch bump-<dep> from current branch.
|
||||||
|
--dep <dependency> bump to a specific release or tag.
|
||||||
|
|
||||||
|
Dependency Options:
|
||||||
|
--version <tag> bump to a specific release or tag.
|
||||||
|
--commit <hash> bump to a specific commit.
|
||||||
|
--HEAD bump to a current head.
|
||||||
|
|
||||||
|
<dependency> is one of:
|
||||||
|
"LuaJIT", "libuv", "Luv", "tree-sitter"
|
||||||
|
]=]):format(this_script, this_script, this_script, this_script, this_script, this_script))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function parseargs()
|
||||||
|
local args = {}
|
||||||
|
for i = 1, #_G.arg do
|
||||||
|
if _G.arg[i] == '-h' then
|
||||||
|
args.h = true
|
||||||
|
elseif _G.arg[i] == '--pr' then
|
||||||
|
args.pr = true
|
||||||
|
elseif _G.arg[i] == '--branch' then
|
||||||
|
args.branch = _G.arg[i+1]
|
||||||
|
elseif _G.arg[i] == '--dep' then
|
||||||
|
args.dep = _G.arg[i+1]
|
||||||
|
elseif _G.arg[i] == '--version' then
|
||||||
|
args.version = _G.arg[i+1]
|
||||||
|
elseif _G.arg[i] == '--commit' then
|
||||||
|
args.commit = _G.arg[i+1]
|
||||||
|
elseif _G.arg[i] == '--head' then
|
||||||
|
args.head = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return args
|
||||||
|
end
|
||||||
|
|
||||||
|
local is_main = _G.arg[0]:match('bump_deps.lua')
|
||||||
|
|
||||||
|
if is_main then
|
||||||
|
local args = parseargs()
|
||||||
|
if args.h then
|
||||||
|
usage()
|
||||||
|
elseif args.pr then
|
||||||
|
M.submit_pr()
|
||||||
|
elseif args.head then
|
||||||
|
M.head(args.dep)
|
||||||
|
elseif args.branch then
|
||||||
|
M.create_branch(args.dep)
|
||||||
|
elseif args.version then
|
||||||
|
M.version(args.dep, args.version)
|
||||||
|
elseif args.commit then
|
||||||
|
M.commit(args.dep, args.commit)
|
||||||
|
elseif args.pr then
|
||||||
|
M.submit_pr()
|
||||||
|
else
|
||||||
|
print('missing required arg\n')
|
||||||
|
os.exit(1)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return M
|
||||||
|
end
|
||||||
|
@ -323,13 +323,12 @@ static int nlua_thr_api_nvim__get_runtime(lua_State *lstate)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copies args starting at `lua_arg0` into the Lua `arg` global.
|
/// Copies args starting at `lua_arg0` to Lua `_G.arg`, and sets `_G.arg[0]` to the scriptname.
|
||||||
///
|
///
|
||||||
/// Example (`lua_arg0` points to "--arg1"):
|
/// Example (arg[0] => "foo.lua", arg[1] => "--arg1", …):
|
||||||
/// nvim -l foo.lua --arg1 --arg2
|
/// nvim -l foo.lua --arg1 --arg2
|
||||||
///
|
///
|
||||||
/// @note Lua CLI sets arguments upto "-e" as _negative_ `_G.arg` indices, but we currently don't
|
/// @note Lua CLI sets args before "-e" as _negative_ `_G.arg` indices, but we currently don't.
|
||||||
/// follow that convention.
|
|
||||||
///
|
///
|
||||||
/// @see https://www.lua.org/pil/1.4.html
|
/// @see https://www.lua.org/pil/1.4.html
|
||||||
/// @see https://github.com/premake/premake-core/blob/1c1304637f4f5e50ba8c57aae8d1d80ec3b7aaf2/src/host/premake.c#L563-L594
|
/// @see https://github.com/premake/premake-core/blob/1c1304637f4f5e50ba8c57aae8d1d80ec3b7aaf2/src/host/premake.c#L563-L594
|
||||||
@ -337,12 +336,19 @@ static int nlua_thr_api_nvim__get_runtime(lua_State *lstate)
|
|||||||
/// @returns number of args
|
/// @returns number of args
|
||||||
static int nlua_init_argv(lua_State *const L, char **argv, int argc, int lua_arg0)
|
static int nlua_init_argv(lua_State *const L, char **argv, int argc, int lua_arg0)
|
||||||
{
|
{
|
||||||
lua_newtable(L); // _G.arg
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; lua_arg0 >= 0 && i + lua_arg0 < argc; i++) {
|
lua_newtable(L); // _G.arg
|
||||||
lua_pushstring(L, argv[i + lua_arg0]);
|
|
||||||
lua_rawseti(L, -2, i + 1); // _G.arg[i+1] = "arg1"
|
if (lua_arg0 > 0) {
|
||||||
|
lua_pushstring(L, argv[lua_arg0 - 1]);
|
||||||
|
lua_rawseti(L, -2, 0); // _G.arg[0] = "foo.lua"
|
||||||
|
|
||||||
|
for (; lua_arg0 >= 0 && i + lua_arg0 < argc; i++) {
|
||||||
|
lua_pushstring(L, argv[i + lua_arg0]);
|
||||||
|
lua_rawseti(L, -2, i + 1); // _G.arg[i+1] = "--foo"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_setglobal(L, "arg");
|
lua_setglobal(L, "arg");
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,9 @@ describe('startup', function()
|
|||||||
assert_l_out([[
|
assert_l_out([[
|
||||||
bufs:
|
bufs:
|
||||||
nvim args: 7
|
nvim args: 7
|
||||||
lua args: { "-arg1", "--exitcode", "73", "--arg2" }]],
|
lua args: { "-arg1", "--exitcode", "73", "--arg2",
|
||||||
|
[0] = "test/functional/fixtures/startup.lua"
|
||||||
|
}]],
|
||||||
{},
|
{},
|
||||||
{ '-arg1', "--exitcode", "73", '--arg2' }
|
{ '-arg1', "--exitcode", "73", '--arg2' }
|
||||||
)
|
)
|
||||||
@ -126,11 +128,11 @@ describe('startup', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('executes stdin "-"', function()
|
it('executes stdin "-"', function()
|
||||||
assert_l_out('args=2 whoa',
|
assert_l_out('arg0=- args=2 whoa',
|
||||||
nil,
|
nil,
|
||||||
{ 'arg1', 'arg 2' },
|
{ 'arg1', 'arg 2' },
|
||||||
'-',
|
'-',
|
||||||
"print(('args=%d %s'):format(#_G.arg, 'whoa'))")
|
"print(('arg0=%s args=%d %s'):format(_G.arg[0], #_G.arg, 'whoa'))")
|
||||||
assert_l_out('biiig input: 1000042',
|
assert_l_out('biiig input: 1000042',
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
@ -140,23 +142,15 @@ describe('startup', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('sets _G.arg', function()
|
it('sets _G.arg', function()
|
||||||
-- nvim -l foo.lua -arg1 -- a b c
|
-- nvim -l foo.lua [args]
|
||||||
assert_l_out([[
|
assert_l_out([[
|
||||||
bufs:
|
bufs:
|
||||||
nvim args: 6
|
nvim args: 7
|
||||||
lua args: { "-arg1", "--arg2", "arg3" }]],
|
lua args: { "-arg1", "--arg2", "--", "arg3",
|
||||||
|
[0] = "test/functional/fixtures/startup.lua"
|
||||||
|
}]],
|
||||||
{},
|
{},
|
||||||
{ '-arg1', '--arg2', 'arg3' }
|
{ '-arg1', '--arg2', '--', 'arg3' }
|
||||||
)
|
|
||||||
eq(0, eval('v:shell_error'))
|
|
||||||
|
|
||||||
-- nvim -l foo.lua --
|
|
||||||
assert_l_out([[
|
|
||||||
bufs:
|
|
||||||
nvim args: 4
|
|
||||||
lua args: { "--" }]],
|
|
||||||
{},
|
|
||||||
{ '--' }
|
|
||||||
)
|
)
|
||||||
eq(0, eval('v:shell_error'))
|
eq(0, eval('v:shell_error'))
|
||||||
|
|
||||||
@ -164,27 +158,21 @@ describe('startup', function()
|
|||||||
assert_l_out([[
|
assert_l_out([[
|
||||||
bufs: file1 file2
|
bufs: file1 file2
|
||||||
nvim args: 10
|
nvim args: 10
|
||||||
lua args: { "-arg1", "arg 2", "--", "file3", "file4" }]],
|
lua args: { "-arg1", "arg 2", "--", "file3", "file4",
|
||||||
|
[0] = "test/functional/fixtures/startup.lua"
|
||||||
|
}]],
|
||||||
{ 'file1', 'file2', },
|
{ 'file1', 'file2', },
|
||||||
{ '-arg1', 'arg 2', '--', 'file3', 'file4' }
|
{ '-arg1', 'arg 2', '--', 'file3', 'file4' }
|
||||||
)
|
)
|
||||||
eq(0, eval('v:shell_error'))
|
eq(0, eval('v:shell_error'))
|
||||||
|
|
||||||
-- nvim file1 file2 -l foo.lua -arg1 --
|
|
||||||
assert_l_out([[
|
|
||||||
bufs: file1 file2
|
|
||||||
nvim args: 7
|
|
||||||
lua args: { "-arg1", "--" }]],
|
|
||||||
{ 'file1', 'file2', },
|
|
||||||
{ '-arg1', '--' }
|
|
||||||
)
|
|
||||||
eq(0, eval('v:shell_error'))
|
|
||||||
|
|
||||||
-- nvim -l foo.lua <vim args>
|
-- nvim -l foo.lua <vim args>
|
||||||
assert_l_out([[
|
assert_l_out([[
|
||||||
bufs:
|
bufs:
|
||||||
nvim args: 5
|
nvim args: 5
|
||||||
lua args: { "-c", "set wrap?" }]],
|
lua args: { "-c", "set wrap?",
|
||||||
|
[0] = "test/functional/fixtures/startup.lua"
|
||||||
|
}]],
|
||||||
{},
|
{},
|
||||||
{ '-c', 'set wrap?' }
|
{ '-c', 'set wrap?' }
|
||||||
)
|
)
|
||||||
@ -198,7 +186,9 @@ describe('startup', function()
|
|||||||
|
|
||||||
bufs:
|
bufs:
|
||||||
nvim args: 7
|
nvim args: 7
|
||||||
lua args: { "-c", "set wrap?" }]],
|
lua args: { "-c", "set wrap?",
|
||||||
|
[0] = "test/functional/fixtures/startup.lua"
|
||||||
|
}]],
|
||||||
{ '-c', 'set wrap?' },
|
{ '-c', 'set wrap?' },
|
||||||
{ '-c', 'set wrap?' }
|
{ '-c', 'set wrap?' }
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user