Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

go.toolsGopath is ignored when GOBIN is set #2339

Closed
elvizlai opened this issue Feb 18, 2019 · 11 comments
Closed

go.toolsGopath is ignored when GOBIN is set #2339

elvizlai opened this issue Feb 18, 2019 · 11 comments

Comments

@elvizlai
Copy link

Steps to Reproduce:

  1. Install go ext and set "go.toolsGopath": "~/.vscode" then reload.
  2. Using CMD Go: Install Tools

Result:

1、The Go Tools still installed in my $GOPATH/bin/ but except bin file gocode-gomod
2、All the Tools source code are placed in RIGHT place (dir go.toolsGopath which I set).

The Logs show tools will installed in toolsGopath:

Installing 17 tools at /Users/elvizlai/.vscode/bin
  gocode
  gopkgs
  go-outline
  go-symbols
  guru
  gorename
  dlv
  gocode-gomod
  godef
  goreturns
  revive
  gotype-live
  gotests
  gomodifytags
  impl
  fillstruct
  goplay

Installing github.com/mdempsky/gocode SUCCEEDED
Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED
Installing github.com/ramya-rao-a/go-outline SUCCEEDED
Installing github.com/acroca/go-symbols SUCCEEDED
Installing golang.org/x/tools/cmd/guru SUCCEEDED
Installing golang.org/x/tools/cmd/gorename SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED
Installing github.com/stamblerre/gocode SUCCEEDED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing github.com/sqs/goreturns SUCCEEDED
Installing github.com/mgechev/revive FAILED
Installing github.com/tylerb/gotype-live SUCCEEDED
Installing github.com/cweill/gotests/... SUCCEEDED
Installing github.com/fatih/gomodifytags SUCCEEDED
Installing github.com/josharian/impl SUCCEEDED
...
@ramya-rao-a
Copy link
Contributor

You probably have GOBIN set in which case the output of go install will always end up in the location set in GOBIN
We don't use go install for gocode-gomod, instead use go build -o, therefore you see it ending up in the right place

Can you run go env GOBIN and see what the result is?

@elvizlai
Copy link
Author

elvizlai commented Feb 22, 2019

@ramya-rao-a YES, I set export GOBIN=$GOPATH/bin in my zsh config

$ go env GOBIN
/Users/elvizlai/.godeps/bin

How about change all using go build instead of go install

I found vscode always repeat appending PATH, which is really annoying.

@ramya-rao-a
Copy link
Contributor

I found vscode always repeat appending PATH, which is really annoying.

I didn't understand this part, can you elaborate?

@elvizlai
Copy link
Author

@ramya-rao-a
Using CMD env in vscode terminal output:

PATH=/Applications/Julia.app/Contents/Resources/julia/bin:/Users/elvizlai/.cargo/bin:/Users/elvizlai/.godeps/bin:/Users/elvizlai/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Julia.app/Contents/Resources/julia/bin:/Users/elvizlai/.cargo/bin:/Users/elvizlai/.godeps/bin:/Users/elvizlai/Library/Flutter/bin:/Users/elvizlai/Library/Flutter/bin

The PATH is repeated. but I only set some of them in ~/.zshrc once.

@ramya-rao-a
Copy link
Contributor

The Go extension doesn't update the PATH env variable. So, I am not sure what is causing the repetition.

Concluding, what we can do in the Go extension is to ignore GOBIN when go.toolsGopath setting is set by the user.

PRs are welcome to fix this
Code Pointers:

  • See Build and Debug Extension to set up local dev environment
  • installTools is the function that installs the Go tools. Here is where we should unset the GOBIN (if go.toolsGopath is set) in the process that is spawned to install the tools

@ramya-rao-a ramya-rao-a changed the title go.toolsGopath not work go.toolsGopath is ignored when GOBIN is set Feb 26, 2019
@jamesgeorge007
Copy link
Contributor

@ramya-rao-a I shall take this up 👏

@jamesgeorge007
Copy link
Contributor

Is this the part where go.toolsGopath is being set 🤔
https://github.com/Microsoft/vscode-go/blob/f8ade313922852b4346c699f7212974fbe44278e/src/goInstallTools.ts#L306

@jamesgeorge007
Copy link
Contributor

@ramya-rao-a What I can find is a goRunTime variable which holds the path to go binary.

Here is where we should unset the GOBIN (if go.toolsGopath is set)

I'm not that sure on unsetting GOBIN as mentioned above. Am I required to work with the goRunTime variable within the if block where go.toolsGoPath is being set 🤔

@ramya-rao-a
Copy link
Contributor

There is no need to work with the goRunTime varaible or the go binary.
You can unset GOBIN by envForTools['GOBIN'] = "";
envForTools is the env used in the process that we spawn to install the tools.

@ramya-rao-a
Copy link
Contributor

The latest beta version of this extension will now ignore GOBIN if you have already set go.toolsGopath

@ramya-rao-a
Copy link
Contributor

The fix for this issue is out in the latest release(0.10.0) of the Go extension

@vscodebot vscodebot bot locked and limited conversation to collaborators May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants