healtcheck: use g:perl_host_prog if its set instead

using just 'perl' isn't correct as it may not be the version requested.
ditto for 'cpanm', rather go through 'App::cpanminus' to find the latest
perl version
This commit is contained in:
Jacques Germishuys 2020-09-02 12:57:01 +01:00
parent 98dea93ba0
commit 8705fbf77c
3 changed files with 33 additions and 25 deletions

View File

@ -689,29 +689,31 @@ function! s:check_perl() abort
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
let [perl_exec, perl_errors] = provider#perl#Detect()
if empty(perl_exec)
if !empty(perl_errors)
call health#report_error('perl provider error:', perl_errors)
else
call health#report_warn('No usable perl executable found')
endif
return
endif
call s:system(['perl', '-e', 'use v5.22'])
call health#report_info('perl executable: '. perl_exec)
" we cannot use cpanm that is on the path, as it may not be for the perl
" set with g:perl_host_prog
call s:system([perl_exec, '-W', '-MApp::cpanminus', '-e', ''])
if s:shell_error
call health#report_warn('Perl version is too old, 5.22+ required')
" Skip further checks, they are nonsense if perl is too old.
return
return [perl_exec, '"App::cpanminus" module is not installed']
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('Nvim perl host: '. host)
let latest_cpan_cmd = [perl_exec,
\ '-MApp::cpanminus::fatscript', '-e',
\ 'my $app = App::cpanminus::script->new;
\ $app->parse_options ("--info", "-q", "Neovim::Ext");
\ exit $app->doit']
let latest_cpan_cmd = 'cpanm --info -q 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,
@ -735,7 +737,7 @@ function! s:check_perl() abort
return
endif
let current_cpan_cmd = [host, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION']
let current_cpan_cmd = [perl_exec, '-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),

View File

@ -5,21 +5,25 @@ 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
" use g:perl_host_prog if set or check if perl is on the path
let prog = exepath(get(g:, 'perl_host_prog', 'perl'))
if empty(prog)
return ''
return ['', '']
endif
" if perl is available, make sure we have 5.22+
call system([prog, '-e', 'use v5.22'])
if v:shell_error
return ''
return ['', 'Perl version is too old, 5.22+ required']
endif
" if perl is available, make sure the required module is available
call system([prog, '-W', '-MNeovim::Ext', '-e', ''])
return v:shell_error ? '' : prog
if v:shell_error
return ['', '"Neovim::Ext" cpan module is not installed']
endif
return [prog, '']
endfunction
function! provider#perl#Prog() abort
@ -64,8 +68,7 @@ function! provider#perl#Call(method, args) abort
return call('rpcrequest', insert(insert(a:args, 'perl_'.a:method), s:host))
endfunction
let s:err = ''
let s:prog = provider#perl#Detect()
let [s:prog, s:err] = provider#perl#Detect()
let g:loaded_perl_provider = empty(s:prog) ? 1 : 2
if g:loaded_perl_provider != 2

View File

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