Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: install tools with go install instead of go get #3317

Merged
merged 3 commits into from
Nov 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 27 additions & 32 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function! s:GoInstallBinaries(updateBinaries, ...)
let Restore_goos = go#util#SetEnv('GOOS', l:goos)
let Restore_goarch = go#util#SetEnv('GOARCH', l:goarch)

" change $GOBIN so go get can automatically install to it
" change $GOBIN so go can automatically install to it
let Restore_gobin = go#util#SetEnv('GOBIN', go_bin_path)

" vim's executable path is looking in PATH so add our go_bin path to it
Expand All @@ -108,7 +108,7 @@ function! s:GoInstallBinaries(updateBinaries, ...)
set noshellslash
endif

let l:get_base_cmd = ['go', 'get', '-v']
let l:get_base_cmd = ['go', 'install', '-v']

" Filter packages from arguments (if any).
let l:packages = {}
Expand Down Expand Up @@ -142,45 +142,40 @@ function! s:GoInstallBinaries(updateBinaries, ...)
" mode and then do the legacy method.
let bin_setting_name = "go_" . l:binary . "_bin"

if exists("g:{bin_setting_name}")
let bin = g:{bin_setting_name}
else
if go#util#IsWin()
let bin = l:binary . '.exe'
else
let bin = l:binary
endif
let l:extension = ''
if go#util#IsWin()
let l:extension = '.exe'
endif

let bin = get(g:, bin_setting_name, l:binary . l:extension)

if !executable(bin) || a:updateBinaries == 1
if a:updateBinaries == 1
echo "vim-go: Updating " . l:binary . ". Reinstalling ". importPath . " to folder " . go_bin_path
else
echo "vim-go: ". l:binary ." not found. Installing ". importPath . " to folder " . go_bin_path
endif

if l:importPath =~ "@"
let l:tmpdir = go#util#tempdir('vim-go')
try
let l:dir = go#util#Chdir(l:tmpdir)
let l:get_cmd = copy(l:get_base_cmd)

if len(l:pkg) > 1 && get(l:pkg[1], l:platform, []) isnot []
let l:get_cmd += get(l:pkg[1], l:platform, [])
endif

" TODO(bc): how to install the bin to a different name than the
" binary path? go get does not support -o
" let l:get_cmd += ['-o', printf('%s%s%s', go_bin_path, go#util#PathSep(), bin)]

let [l:out, l:err] = go#util#Exec(l:get_cmd + [l:importPath])
if l:err
call go#util#EchoError(printf('Error installing %s: %s', l:importPath, l:out))
endif
finally
call go#util#Chdir(l:dir)
endtry
endif
let l:tmpdir = go#util#tempdir('vim-go')
try
let l:dir = go#util#Chdir(l:tmpdir)
let l:get_cmd = copy(l:get_base_cmd)

if len(l:pkg) > 1 && get(l:pkg[1], l:platform, []) isnot []
let l:get_cmd += get(l:pkg[1], l:platform, [])
endif

" TODO(bc): how to install the bin to a different name than the binary
" path? go install does not support -o
"let l:get_cmd += ['-o', printf('%s%s%s', go_bin_path, go#util#PathSep(), bin)]

let [l:out, l:err] = go#util#Exec(l:get_cmd + [l:importPath])
if l:err
call go#util#EchoError(printf('Error installing %s: %s', l:importPath, l:out))
endif
finally
call go#util#Chdir(l:dir)
endtry

if len(l:pkg) > 2
call call(get(l:pkg[2], 'after', function('s:noop', [])), [])
Expand Down