Skip to content

go: install tools with their custom names #1984

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

Merged
merged 1 commit into from
Sep 21, 2018
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
28 changes: 21 additions & 7 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if
endif

" these packages are used by vim-go and can be automatically installed if
" needed by the user with GoInstallBinaries
" needed by the user with GoInstallBinaries.
let s:packages = {
\ 'asmfmt': ['github.com/klauspost/asmfmt/cmd/asmfmt'],
\ 'dlv': ['github.com/derekparker/delve/cmd/dlv'],
Expand Down Expand Up @@ -99,9 +99,9 @@ function! s:GoInstallBinaries(updateBinaries, ...)
set noshellslash
endif

let l:cmd = ['go', 'get', '-v']
let l:dl_cmd = ['go', 'get', '-v', '-d']
if get(g:, "go_get_update", 1) != 0
let l:cmd += ['-u']
let l:dl_cmd += ['-u']
endif

" Filter packages from arguments (if any).
Expand All @@ -127,16 +127,16 @@ function! s:GoInstallBinaries(updateBinaries, ...)
for [binary, pkg] in items(l:packages)
let l:importPath = pkg[0]

let l:run_cmd = copy(l:cmd)
let l:run_cmd = copy(l:dl_cmd)
if len(l:pkg) > 1 && get(l:pkg[1], l:platform, '') isnot ''
let l:run_cmd += get(l:pkg[1], l:platform, '')
endif

let binname = "go_" . binary . "_bin"
let bin_setting_name = "go_" . binary . "_bin"

let bin = binary
if exists("g:{binname}")
let bin = g:{binname}
if exists("g:{bin_setting_name}")
let bin = g:{bin_setting_name}
endif

if !executable(bin) || a:updateBinaries == 1
Expand All @@ -146,7 +146,15 @@ function! s:GoInstallBinaries(updateBinaries, ...)
echo "vim-go: ". binary ." not found. Installing ". importPath . " to folder " . go_bin_path
endif

" first download the binary
let [l:out, l:err] = go#util#Exec(l:run_cmd + [l:importPath])
if l:err
echom "Error downloading " . l:importPath . ": " . l:out
endif

" and then build and install it
let l:build_cmd = ['go', 'build', '-o', go_bin_path . go#util#PathSep() . bin, l:importPath]
let [l:out, l:err] = go#util#Exec(l:build_cmd + [l:importPath])
if l:err
echom "Error installing " . l:importPath . ": " . l:out
endif
Expand All @@ -158,6 +166,12 @@ function! s:GoInstallBinaries(updateBinaries, ...)
if resetshellslash
set shellslash
endif

if a:updateBinaries == 1
call go#util#EchoInfo('updating finished!')
else
call go#util#EchoInfo('installing finished!')
endif
endfunction

" CheckBinaries checks if the necessary binaries to install the Go tool
Expand Down