Add check for executable in Ruby threads
Now whenever an update is called a check is made (not just on installation)
This commit is contained in:
parent
83ca8b0336
commit
58eadd8f76
127
plug.vim
127
plug.vim
|
@ -75,7 +75,7 @@ let s:mac_gui = has('gui_macvim') && has('gui_running')
|
||||||
let s:is_win = has('win32') || has('win64')
|
let s:is_win = has('win32') || has('win64')
|
||||||
let s:nvim = exists('##JobActivity') && !s:is_win
|
let s:nvim = exists('##JobActivity') && !s:is_win
|
||||||
let s:me = resolve(expand('<sfile>:p'))
|
let s:me = resolve(expand('<sfile>:p'))
|
||||||
let s:base_spec = { 'branch': 'master', 'frozen': 0 }
|
let s:base_spec = { 'branch': 'master', 'frozen': 0, 'needs': []}
|
||||||
let s:TYPE = {
|
let s:TYPE = {
|
||||||
\ 'string': type(''),
|
\ 'string': type(''),
|
||||||
\ 'list': type([]),
|
\ 'list': type([]),
|
||||||
|
@ -578,13 +578,6 @@ function! s:assign_name()
|
||||||
silent! execute 'f' fnameescape(name)
|
silent! execute 'f' fnameescape(name)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:all_executable(executables)
|
|
||||||
if len(a:executables) == 0
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
let are_executable = map(a:executables, 'executable(v:val)')
|
|
||||||
return index(are_executable, 0) == -1
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:do(pull, force, todo)
|
function! s:do(pull, force, todo)
|
||||||
for [name, spec] in items(a:todo)
|
for [name, spec] in items(a:todo)
|
||||||
|
@ -594,15 +587,7 @@ function! s:do(pull, force, todo)
|
||||||
let installed = has_key(s:update.new, name)
|
let installed = has_key(s:update.new, name)
|
||||||
let updated = installed ? 0 :
|
let updated = installed ? 0 :
|
||||||
\ (a:pull && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', spec.dir)))
|
\ (a:pull && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', spec.dir)))
|
||||||
" TODO(alexandre): use the function executable on all the parameters in
|
if a:force || installed || updated
|
||||||
" the 'needs' attribute - if not then don't update.
|
|
||||||
if has_key(spec, 'needs')
|
|
||||||
echom 'Has needs.'
|
|
||||||
let canbuild = s:all_executable(s:to_a(spec.needs))
|
|
||||||
else
|
|
||||||
let canbuild = 1
|
|
||||||
endif
|
|
||||||
if (a:force || installed || updated) && canbuild
|
|
||||||
execute 'cd' s:esc(spec.dir)
|
execute 'cd' s:esc(spec.dir)
|
||||||
call append(3, '- Post-update hook for '. name .' ... ')
|
call append(3, '- Post-update hook for '. name .' ... ')
|
||||||
let type = type(spec.do)
|
let type = type(spec.do)
|
||||||
|
@ -672,8 +657,6 @@ function! s:names(...)
|
||||||
return sort(filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)'))
|
return sort(filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" TODO (alexandre) - Maybe if you don't have the build commands,
|
|
||||||
" you don't pull it at all, (citing the reason).
|
|
||||||
function! s:update_impl(pull, force, args) abort
|
function! s:update_impl(pull, force, args) abort
|
||||||
let args = copy(a:args)
|
let args = copy(a:args)
|
||||||
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
||||||
|
@ -894,6 +877,10 @@ function! s:update_vim()
|
||||||
call s:tick()
|
call s:tick()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:missing_executables(executables)
|
||||||
|
return filter(copy(s:to_a(a:executables)), '!executable(v:val)')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:tick()
|
function! s:tick()
|
||||||
while 1 " Without TCO, Vim stack is bound to explode
|
while 1 " Without TCO, Vim stack is bound to explode
|
||||||
if empty(s:update.todo)
|
if empty(s:update.todo)
|
||||||
|
@ -910,27 +897,34 @@ while 1 " Without TCO, Vim stack is bound to explode
|
||||||
let new = !isdirectory(spec.dir)
|
let new = !isdirectory(spec.dir)
|
||||||
|
|
||||||
call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
|
call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
|
||||||
|
echom 'blah'
|
||||||
redraw
|
redraw
|
||||||
|
|
||||||
if !new
|
let executables = s:missing_executables(spec.needs)
|
||||||
let [valid, msg] = s:git_valid(spec, 0)
|
if !empty(executables)
|
||||||
if valid
|
let msg = 'Please install '. join(executables, ', ') . '.'
|
||||||
if pull
|
let s:jobs[name] = { 'running': 0, 'result': msg, 'error': 1 }
|
||||||
call s:spawn(name,
|
else
|
||||||
\ printf('git checkout -q %s 2>&1 && git pull --progress --no-rebase origin %s 2>&1 && git submodule update --init --recursive 2>&1',
|
if !new
|
||||||
\ s:shellesc(spec.branch), s:shellesc(spec.branch)), { 'dir': spec.dir })
|
let [valid, msg] = s:git_valid(spec, 0)
|
||||||
|
if valid
|
||||||
|
if pull
|
||||||
|
call s:spawn(name,
|
||||||
|
\ printf('git checkout -q %s 2>&1 && git pull --progress --no-rebase origin %s 2>&1 && git submodule update --init --recursive 2>&1',
|
||||||
|
\ s:shellesc(spec.branch), s:shellesc(spec.branch)), { 'dir': spec.dir })
|
||||||
|
else
|
||||||
|
let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 }
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 }
|
let s:jobs[name] = { 'running': 0, 'result': msg, 'error': 1 }
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let s:jobs[name] = { 'running': 0, 'result': msg, 'error': 1 }
|
call s:spawn(name,
|
||||||
|
\ printf('git clone --progress --recursive %s -b %s %s 2>&1',
|
||||||
|
\ s:shellesc(spec.uri),
|
||||||
|
\ s:shellesc(spec.branch),
|
||||||
|
\ s:shellesc(s:trim(spec.dir))), { 'new': 1 })
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
call s:spawn(name,
|
|
||||||
\ printf('git clone --progress --recursive %s -b %s %s 2>&1',
|
|
||||||
\ s:shellesc(spec.uri),
|
|
||||||
\ s:shellesc(spec.branch),
|
|
||||||
\ s:shellesc(s:trim(spec.dir))), { 'new': 1 })
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !s:jobs[name].running
|
if !s:jobs[name].running
|
||||||
|
@ -979,6 +973,17 @@ function! s:update_ruby()
|
||||||
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
|
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def which cmd
|
||||||
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
||||||
|
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
||||||
|
exts.each { |ext|
|
||||||
|
exe = File.join(path, "#{cmd}#{ext}")
|
||||||
|
return exe if File.executable?(exe) && !File.directory?(exe)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
require 'thread'
|
require 'thread'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
|
@ -1106,39 +1111,45 @@ function! s:update_ruby()
|
||||||
threads << Thread.new {
|
threads << Thread.new {
|
||||||
while pair = take1.call
|
while pair = take1.call
|
||||||
name = pair.first
|
name = pair.first
|
||||||
dir, uri, branch = pair.last.values_at *%w[dir uri branch]
|
dir, uri, branch, needs = pair.last.values_at *%w[dir uri branch needs]
|
||||||
branch = esc branch
|
branch = esc branch
|
||||||
subm = "git submodule update --init --recursive 2>&1"
|
subm = "git submodule update --init --recursive 2>&1"
|
||||||
exists = File.directory? dir
|
exists = File.directory? dir
|
||||||
|
needs = needs.kind_of?(Array) ? needs : [needs]
|
||||||
|
executables = needs.select{ |exe| !which exe }
|
||||||
ok, result =
|
ok, result =
|
||||||
if exists
|
if executables.empty?
|
||||||
dir = esc dir
|
if exists
|
||||||
ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil
|
dir = esc dir
|
||||||
current_uri = data.lines.to_a.last
|
ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil
|
||||||
if !ret
|
current_uri = data.lines.to_a.last
|
||||||
if data =~ /^Interrupted|^Timeout/
|
if !ret
|
||||||
[false, data]
|
if data =~ /^Interrupted|^Timeout/
|
||||||
|
[false, data]
|
||||||
|
else
|
||||||
|
[false, [data.chomp, "PlugClean required."].join($/)]
|
||||||
|
end
|
||||||
|
elsif current_uri.sub(/git::?@/, '') != uri.sub(/git::?@/, '')
|
||||||
|
[false, ["Invalid URI: #{current_uri}",
|
||||||
|
"Expected: #{uri}",
|
||||||
|
"PlugClean required."].join($/)]
|
||||||
else
|
else
|
||||||
[false, [data.chomp, "PlugClean required."].join($/)]
|
if pull
|
||||||
|
log.call name, 'Updating ...', :update
|
||||||
|
bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && (git pull --no-rebase origin #{branch} #{progress} 2>&1 && #{subm})", name, :update, nil
|
||||||
|
else
|
||||||
|
[true, skip]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elsif current_uri.sub(/git::?@/, '') != uri.sub(/git::?@/, '')
|
|
||||||
[false, ["Invalid URI: #{current_uri}",
|
|
||||||
"Expected: #{uri}",
|
|
||||||
"PlugClean required."].join($/)]
|
|
||||||
else
|
else
|
||||||
if pull
|
d = esc dir.sub(%r{[\\/]+$}, '')
|
||||||
log.call name, 'Updating ...', :update
|
log.call name, 'Installing ...', :install
|
||||||
bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && (git pull --no-rebase origin #{branch} #{progress} 2>&1 && #{subm})", name, :update, nil
|
bt.call "git clone #{progress} --recursive #{uri} -b #{branch} #{d} 2>&1", name, :install, proc {
|
||||||
else
|
FileUtils.rm_rf dir
|
||||||
[true, skip]
|
}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
d = esc dir.sub(%r{[\\/]+$}, '')
|
[false, "Please install " + executables.join(", ") + " first."]
|
||||||
log.call name, 'Installing ...', :install
|
|
||||||
bt.call "git clone #{progress} --recursive #{uri} -b #{branch} #{d} 2>&1", name, :install, proc {
|
|
||||||
FileUtils.rm_rf dir
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
mtx.synchronize { VIM::command("let s:update.new['#{name}'] = 1") } if !exists && ok
|
mtx.synchronize { VIM::command("let s:update.new['#{name}'] = 1") } if !exists && ok
|
||||||
log.call name, result, ok
|
log.call name, result, ok
|
||||||
|
|
Loading…
Reference in New Issue
Block a user