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

use last gopath element when installing tools #1988

Conversation

jrwren
Copy link
Contributor

@jrwren jrwren commented Oct 11, 2018

@AlexRouSg
Copy link

Why use last? The go get behavior is to use the first.

@jrwren
Copy link
Contributor Author

jrwren commented Oct 11, 2018

Why use last? The go get behavior is to use the first.

I thought so too, but that is not what I observed. Can you double check that you observe it installing to first?

@AlexRouSg
Copy link

Yes, that is how I observe it to work on Linux and Windows. This is even documented behavior.

https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies

When checking out a new package, get creates the target directory GOPATH/src/. If the GOPATH contains multiple entries, get uses the first one. For more details see: 'go help gopath'.

@jrwren
Copy link
Contributor Author

jrwren commented Oct 12, 2018

That is pretty definite documentation. I wonder why I think I observed what I observed. I'll change this.

I also had a question re: calling go install? Why use -o rather than calling go install with GOPATH set?

@AlexRouSg
Copy link

I find that weird too. go install will install to the same gopath that the package is in. And if you're changing gopath to be a single path then that shouldn't even cause problems even if you have the same package in multiple gopaths.

@jrwren
Copy link
Contributor Author

jrwren commented Oct 12, 2018

I realize now that the same code paths in vscode-go are made to install the tools even when there is no GOPATH, e.g. the GOPATH is infered per project or the go project uses go modules. I'm going to change the index to 0 and hopefully that is acceptable.

@jrwren jrwren force-pushed the 002-use-last-gopath-element-on-tools-install branch from b3993ff to e16e0aa Compare October 12, 2018 22:17
@ramya-rao-a
Copy link
Contributor

I also had a question re: calling go install? Why use -o rather than calling go install with GOPATH set?

To support Go modules, we use forks of gocode and godef. But we do not want these forks to replace the original binaries. This is because the forks are slower than the originals, and we dont want to use the forks when you are not using Go modules.

In order to do this, we use go get -d so that the tool is not installed and then use go build -o so that we are free to rename the binary as gocode-gomod/godef-gomod.

Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @jrwren

Multiple gopath was not an issue previously when installing tools, as we didnt use it directly for anything. It was only set as an environment variable.

Now that we use it directly to build the forks of gocode and godef, this fix is necessary

@ramya-rao-a ramya-rao-a merged commit b6306a5 into microsoft:master Oct 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants