Merge #11703 'CI: install perl provider'

This commit is contained in:
Justin M. Keyes 2020-01-20 17:27:28 -08:00 committed by GitHub
commit 99aec38259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 276 additions and 16 deletions

View File

@ -71,6 +71,7 @@ addons:
- build-essential
- clang
- cmake
- cpanminus
- cscope
- gcc-multilib
- gdb
@ -90,7 +91,9 @@ addons:
- powershell
packages:
- ccache
- cpanminus
- ninja
- perl
jobs:
include:

View File

@ -22,9 +22,6 @@ init:
#- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
matrix:
fast_finish: true
install: []
before_build:
- ps: Install-Product node 10
build_script:
- powershell ci\build.ps1
after_build:

View File

@ -44,7 +44,6 @@ fi
source ~/.nvm/nvm.sh
nvm install 10
nvm use 10
if [[ -n "$CMAKE_URL" ]]; then
echo "Installing custom CMake: $CMAKE_URL"

View File

@ -29,6 +29,30 @@ function exitIfFailed() {
}
}
# https://github.com/lukesampson/scoop#installation
$scoop = (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
& {
Set-StrictMode -Off
Invoke-Expression $scoop
}
scoop install diffutils perl
diff3 --version
perl --version
cpanm.bat --version
if (-not $NoTests) {
scoop install nodejs-lts
node --version
npm.cmd --version
cpanm.bat -n Neovim::Ext
if ($LastExitCode -ne 0) {
Get-Content -Path "$env:USERPROFILE\.cpanm\build.log"
}
perl -W -e 'use Neovim::Ext; print $Neovim::Ext::VERSION'; exitIfFailed
}
if (-Not (Test-Path -PathType container $env:DEPS_BUILD_DIR)) {
write-host "cache dir not found: $($env:DEPS_BUILD_DIR)"
mkdir $env:DEPS_BUILD_DIR
@ -57,7 +81,7 @@ if ($compiler -eq 'MINGW') {
# in MSYS2, but we cannot build inside the MSYS2 shell.
$cmakeGenerator = 'Ninja'
$cmakeGeneratorArgs = '-v'
$mingwPackages = @('ninja', 'cmake', 'perl', 'diffutils').ForEach({
$mingwPackages = @('ninja', 'cmake').ForEach({
"mingw-w64-$arch-$_"
})
@ -115,7 +139,6 @@ if (-not $NoTests) {
if (-Not (Test-Path -PathType Leaf "$env:TREE_SITTER_DIR\bin\c.dll")) {
exit 1
}
}
if ($compiler -eq 'MSVC') {

View File

@ -50,3 +50,6 @@ else
gcc -m32 -o "$TREE_SITTER_DIR/bin/c.so" -shared parser.c -I.
fi
test -f "$TREE_SITTER_DIR/bin/c.so"
sudo cpanm -n Neovim::Ext || cat "$HOME/.cpanm/build.log"
perl -W -e 'use Neovim::Ext; print $Neovim::Ext::VERSION'

View File

@ -566,7 +566,7 @@ function! s:check_node() abort
endif
let node_v = get(split(s:system('node -v'), "\n"), 0, '')
call health#report_info('Node.js: '. node_v)
if !s:shell_error && s:version_cmp(node_v[1:], '6.0.0') < 0
if s:shell_error || s:version_cmp(node_v[1:], '6.0.0') < 0
call health#report_warn('Neovim node.js host does not support '.node_v)
" Skip further checks, they are nonsense if nodejs is too old.
return
@ -595,14 +595,12 @@ function! s:check_node() abort
\ 'Are you behind a firewall or proxy?'])
return
endif
if !empty(latest_npm)
try
let pkg_data = json_decode(latest_npm)
catch /E474/
return 'error: '.latest_npm
endtry
let latest_npm = get(get(pkg_data, 'dist-tags', {}), 'latest', 'unable to parse')
endif
try
let pkg_data = json_decode(latest_npm)
catch /E474/
return 'error: '.latest_npm
endtry
let latest_npm = get(get(pkg_data, 'dist-tags', {}), 'latest', 'unable to parse')
let current_npm_cmd = ['node', host, '--version']
let current_npm = s:system(current_npm_cmd)
@ -623,10 +621,68 @@ function! s:check_node() abort
endif
endfunction
function! s:check_perl() abort
call health#report_start('Perl provider (optional)')
if s:disabled_via_loaded_var('perl')
return
endif
if !executable('perl') || !executable('cpanm')
call health#report_warn(
\ '`perl` and `cpanm` must be in $PATH.',
\ ['Install Perl and cpanminus and verify that `perl` and `cpanm` commands work.'])
return
endif
let perl_v = get(split(s:system(['perl', '-W', '-e', 'print $^V']), "\n"), 0, '')
call health#report_info('Perl: '. perl_v)
if s:shell_error
call health#report_warn('Neovim perl host does not support '.perl_v)
" Skip further checks, they are nonsense if perl is too old.
return
endif
let host = provider#perl#Detect()
if empty(host)
call health#report_warn('Missing "Neovim::Ext" cpan module.',
\ ['Run in shell: cpanm Neovim::Ext'])
return
endif
call health#report_info('Neovim perl host: '. host)
let latest_cpan_cmd = 'cpanm --info Neovim::Ext'
let latest_cpan = s:system(latest_cpan_cmd)
if s:shell_error || empty(latest_cpan)
call health#report_error('Failed to run: '. latest_cpan_cmd,
\ ["Make sure you're connected to the internet.",
\ 'Are you behind a firewall or proxy?'])
return
endif
let latest_cpan = matchstr(latest_cpan, '\(\.\?\d\)\+')
let current_cpan_cmd = [host, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION']
let current_cpan = s:system(current_cpan_cmd)
if s:shell_error
call health#report_error('Failed to run: '. string(current_cpan_cmd),
\ ['Report this issue with the output of: ', string(current_cpan_cmd)])
return
endif
if s:version_cmp(current_cpan, latest_cpan) == -1
call health#report_warn(
\ printf('Module "Neovim::Ext" is out-of-date. Installed: %s, latest: %s',
\ current_cpan, latest_cpan),
\ ['Run in shell: cpanm Neovim::Ext'])
else
call health#report_ok('Latest "Neovim::Ext" cpan module is installed: '. current_cpan)
endif
endfunction
function! health#provider#check() abort
call s:check_clipboard()
call s:check_python(2)
call s:check_python(3)
call s:check_ruby()
call s:check_node()
call s:check_perl()
endfunction

View File

@ -0,0 +1,69 @@
if exists('s:loaded_perl_provider')
finish
endif
let s:loaded_perl_provider = 1
function! provider#perl#Detect() abort
" use g:perl_host_prof if set or check if perl is on the path
let prog = exepath(get(g:, 'perl_host_prog', 'perl'))
if empty(prog)
return ''
endif
" if perl is available, make sure the required module is available
call system([prog, '-W', '-MNeovim::Ext', '-e', ''])
return v:shell_error ? '' : prog
endfunction
function! provider#perl#Prog() abort
return s:prog
endfunction
function! provider#perl#Require(host) abort
if s:err != ''
echoerr s:err
return
endif
let prog = provider#perl#Prog()
let args = [s:prog, '-e', 'use Neovim::Ext; start_host();']
" Collect registered perl plugins into args
let perl_plugins = remote#host#PluginsForHost(a:host.name)
for plugin in perl_plugins
call add(args, plugin.path)
endfor
return provider#Poll(args, a:host.orig_name, '$NVIM_PERL_LOG_FILE')
endfunction
function! provider#perl#Call(method, args) abort
if s:err != ''
echoerr s:err
return
endif
if !exists('s:host')
try
let s:host = remote#host#Require('perl')
catch
let s:err = v:exception
echohl WarningMsg
echomsg v:exception
echohl None
return
endtry
endif
return call('rpcrequest', insert(insert(a:args, 'perl_'.a:method), s:host))
endfunction
let s:err = ''
let s:prog = provider#perl#Detect()
let g:loaded_perl_provider = empty(s:prog) ? 1 : 2
if g:loaded_perl_provider != 2
let s:err = 'Cannot find perl or the required perl module'
endif
call remote#host#RegisterPlugin('perl-provider', 'perl', [])

View File

@ -203,3 +203,7 @@ call remote#host#Register('ruby', '*.rb',
" nodejs
call remote#host#Register('node', '*',
\ function('provider#node#Require'))
" perl
call remote#host#Register('perl', '*',
\ function('provider#perl#Require'))

View File

@ -126,6 +126,31 @@ To use an absolute path (e.g. to an rbenv installation): >
To use the RVM "system" Ruby installation: >
let g:ruby_host_prog = 'rvm system do neovim-ruby-host'
==============================================================================
Perl integration *provider-perl*
Nvim supports Perl |remote-plugin|s.
https://github.com/jacquesg/p5-Neovim-Ext
PERL QUICKSTART~
To use perl remote-plugins with Nvim, install the "Neovim::Ext" cpan package: >
cpanm -n Neovim::Ext
Run |:checkhealth| to see if your system is up-to-date.
PERL PROVIDER CONFIGURATION~
*g:loaded_perl_provider*
To disable Perl support: >
:let g:loaded_perl_provider = 0
<
*g:perl_host_prog*
Command to start the Perl executable. Must be set before any
check for has("perl"). >
let g:perl_host_prog = '/path/to/perl'
<
==============================================================================
Node.js integration *provider-nodejs*

View File

@ -24611,6 +24611,7 @@ bool eval_has_provider(const char *feat)
&& !strequal(feat, "python_dynamic")
&& !strequal(feat, "python3_compiled")
&& !strequal(feat, "python3_dynamic")
&& !strequal(feat, "perl")
&& !strequal(feat, "ruby")
&& !strequal(feat, "node")) {
// Avoid autoload for non-provider has() features.

View File

@ -768,7 +768,7 @@ function module.new_pipename()
end
function module.missing_provider(provider)
if provider == 'ruby' or provider == 'node' then
if provider == 'ruby' or provider == 'node' or provider == 'perl' then
local prog = module.funcs['provider#' .. provider .. '#Detect']()
return prog == '' and (provider .. ' not detected') or false
elseif provider == 'python' or provider == 'python3' then

View File

@ -0,0 +1,80 @@
local helpers = require('test.functional.helpers')(after_each)
local eq, clear = helpers.eq, helpers.clear
local missing_provider = helpers.missing_provider
local command = helpers.command
local write_file = helpers.write_file
local eval = helpers.eval
local retry = helpers.retry
do
clear()
local reason = missing_provider('perl')
if reason then
pending(string.format("Missing perl host, or perl version is too old (%s)", reason), function() end)
return
end
end
before_each(function()
clear()
end)
describe('perl host', function()
if helpers.pending_win32(pending) then return end
teardown(function ()
os.remove('Xtest-perl-hello.pl')
os.remove('Xtest-perl-hello-plugin.pl')
end)
it('works', function()
local fname = 'Xtest-perl-hello.pl'
write_file(fname, [[
package main;
use strict;
use warnings;
use Neovim::Ext;
use Neovim::Ext::MsgPack::RPC;
my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM_LISTEN_ADDRESS});
my $nvim = Neovim::Ext::from_session($session);
$nvim->command('let g:job_out = "hello"');
1;
]])
command('let g:job_id = jobstart(["perl", "'..fname..'"])')
retry(nil, 3000, function() eq('hello', eval('g:job_out')) end)
end)
it('plugin works', function()
local fname = 'Xtest-perl-hello-plugin.pl'
write_file(fname, [[
package TestPlugin;
use strict;
use warnings;
use parent qw(Neovim::Ext::Plugin);
__PACKAGE__->register;
@{TestPlugin::commands} = ();
@{TestPlugin::specs} = ();
sub test_command :nvim_command('TestCommand')
{
my ($this) = @_;
$this->nvim->command('let g:job_out = "hello-plugin"');
}
package main;
use strict;
use warnings;
use Neovim::Ext;
use Neovim::Ext::MsgPack::RPC;
my $session = Neovim::Ext::MsgPack::RPC::socket_session($ENV{NVIM_LISTEN_ADDRESS});
my $nvim = Neovim::Ext::from_session($session);
my $plugin = TestPlugin->new($nvim);
$plugin->test_command();
1;
]])
command('let g:job_id = jobstart(["perl", "'..fname..'"])')
retry(nil, 3000, function() eq('hello-plugin', eval('g:job_out')) end)
end)
end)