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

installation: go get from temporary directory for tools installation can result in picking a different go version when using asdf #757

Closed
bmalehorn opened this issue Oct 8, 2020 · 9 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@bmalehorn
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.15.2 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
1.50.0
93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3
x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.17.2
  • Run go env to get the go development environment details
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/brianmalehorn/Library/Caches/go-build"
GOENV="/Users/brianmalehorn/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/brianmalehorn/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/brianmalehorn/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/brianmalehorn/.asdf/installs/golang/1.15.2/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/brianmalehorn/.asdf/installs/golang/1.15.2/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z_/kwdy65dd7p30j4_k3bv5qh_w0000gn/T/go-build124020973=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

  "go.useLanguageServer": true,
  "go.lintTool": "staticcheck",
  "[go]": {
    "editor.codeActionsOnSave": [
      "source.addMissingImports",
      "source.organizeImports"
    ]
  },

Describe the bug

When I open VSCode, it asks to update tools.
All the tool updates fail:

Tools environment: GOPATH=/Users/brianmalehorn/go
Installing 12 tools at /Users/brianmalehorn/go/bin in module mode.
  gocode
  gopkgs
  go-outline
...

Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
...

12 tools failed to install.

gocode: failed to install gocode(github.com/mdempsky/gocode): Error: Command failed: /Users/brianmalehorn/.asdf/shims/go get -v github.com/mdempsky/gocode
go get github.com/mdempsky/gocode: invalid $GOPROXY setting: cannot have comma
 undefined  
gopkgs: failed to install gopkgs(github.com/uudashr/gopkgs/v2/cmd/gopkgs): Error: Command failed: /Users/brianmalehorn/.asdf/shims/go get -v github.com/uudashr/gopkgs/v2/cmd/gopkgs
go get github.com/uudashr/gopkgs/v2/cmd/gopkgs: invalid $GOPROXY setting: cannot have comma
 undefined  
go-outline: failed to install go-outline(github.com/ramya-rao-a/go-outline): Error: Command failed: /Users/brianmalehorn/.asdf/shims/go get -v github.com/ramya-rao-a/go-outline
go get github.com/ramya-rao-a/go-outline: invalid $GOPROXY setting: cannot have comma
 undefined  
...

However, in a regular terminal I can run the same commands in a terminal and they work ok:

/Users/brianmalehorn/.asdf/shims/go get -v github.com/mdempsky/gocode
github.com/mdempsky/gocode/internal/lookdot
golang.org/x/tools/go/internal/gcimporter
net/rpc
github.com/mdempsky/gocode/internal/suggest
golang.org/x/tools/go/gcexportdata
github.com/mdempsky/gocode/internal/cache
github.com/mdempsky/gocode/internal/gbimporter
github.com/mdempsky/gocode

I suspect this extension is not running the same version of go / the same settings at the terminal.

@hyangah
Copy link
Contributor

hyangah commented Oct 8, 2020

@bmalehorn thanks for reporting the issue. Can you verify if the go command the extension is the same one you are seeing from your terminal? It looks like you're using asdf, and I wonder if the extension picked up an old version of go that doesn't understand the newer GOPROXY syntax.

Can you share the output of Go: Locate Configured Go Tools?

@bmalehorn
Copy link
Author

@bmalehorn thanks for reporting the issue. Can you verify if the go command the extension is the same one you are seeing from your terminal? It looks like you're using asdf, and I wonder if the extension picked up an old version of go that doesn't understand the newer GOPROXY syntax.

Ohh, I think I know what it is.

I'm using asdf. This installs a single executable, go. However, which version of go it executes depends on the current working directory.

So in the workspace root, it runs go 1.15.2:

> cd ~/go/src/github.com/opendoor-labs/code/go/services/laser
> which go
/Users/brianmalehorn/.asdf/shims/go
> go version
go version go1.15.2 darwin/amd64

...but in my home directory, it runs go 1.12:

> cd ~/
> which go
/Users/brianmalehorn/.asdf/shims/go
> go version
go version go1.12 darwin/amd64

So I think the correct fix here is to run go in the workspace root instead of some other directory.

Can you share the output of Go: Locate Configured Go Tools?

For completeness here's the output:

Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/brianmalehorn/go
GOROOT: /Users/brianmalehorn/.asdf/installs/golang/1.15.2/go
PATH: /Users/brianmalehorn/.asdf/shims:/Users/brianmalehorn/.asdf/bin:/Users/brianmalehorn/bin:/Users/brianmalehorn/.nix-profile/bin:/Users/brianmalehorn/.poetry/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/share/dotnet:~/.dotnet/tools:/usr/local/sbin

   gocode: /Users/brianmalehorn/go/bin/gocode installed
   gopkgs: /Users/brianmalehorn/go/bin/gopkgs installed
   go-outline: /Users/brianmalehorn/go/bin/go-outline installed
   go-symbols: /Users/brianmalehorn/go/bin/go-symbols installed
   guru: /Users/brianmalehorn/go/bin/guru installed
   gorename: /Users/brianmalehorn/go/bin/gorename installed
   gotests: gotests not installed
   gomodifytags: gomodifytags not installed
   impl: impl not installed
   fillstruct: fillstruct not installed
   goplay: goplay not installed
   godoctor: godoctor not installed
   dlv: /Users/brianmalehorn/go/bin/dlv installed
   gocode-gomod: /Users/brianmalehorn/go/bin/gocode-gomod installed
   godef: /Users/brianmalehorn/go/bin/godef installed
   goreturns: /Users/brianmalehorn/go/bin/goreturns installed
   staticcheck: /Users/brianmalehorn/go/bin/staticcheck installed
   gopls: /Users/brianmalehorn/go/bin/gopls installed

go env
Workspace Folder (laser): /Users/brianmalehorn/go/src/github.com/opendoor-labs/code/go/services/laser
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/Users/brianmalehorn/Library/Caches/go-build"
	GOENV="/Users/brianmalehorn/Library/Application Support/go/env"
	GOEXE=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="darwin"
	GOINSECURE=""
	GOMODCACHE="/Users/brianmalehorn/go/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="darwin"
	GOPATH="/Users/brianmalehorn/go"
	GOPRIVATE=""
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/Users/brianmalehorn/.asdf/installs/golang/1.15.2/go"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/Users/brianmalehorn/.asdf/installs/golang/1.15.2/go/pkg/tool/darwin_amd64"
	GCCGO="gccgo"
	AR="ar"
	CC="clang"
	CXX="clang++"
	CGO_ENABLED="1"
	GOMOD=""
	CGO_CFLAGS="-g -O2"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-g -O2"
	CGO_FFLAGS="-g -O2"
	CGO_LDFLAGS="-g -O2"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z_/kwdy65dd7p30j4_k3bv5qh_w0000gn/T/go-build053632652=/tmp/go-build -gno-record-gcc-switches -fno-common"
	

@hyangah
Copy link
Contributor

hyangah commented Oct 9, 2020

Yes, we've seen this issue. microsoft/vscode-go#3087

I think with go1.16, we will be in a better state with module aware tool installation.
Until then, we can try -modfile (along with -mod=mod) instead of switching to a temporary directory if the current go version is 1.14 or newer

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 9, 2020
@bmalehorn
Copy link
Author

Yup, that looks like my issue.

Anyway, I can work around this by installing 1.52.2 in my home directory (~/.tool-versions).

Is there any information you need from me? I'm not sure what you mean by -modfile.

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/261697 mentions this issue: src/goInstallTools: run tool installation from the workspace folder

@hyangah hyangah changed the title Failed to update tools because "invalid $GOPROXY setting: cannot have comma" installation: go get from temporary directory for tools installation can result in picking a different go version when using asdf Oct 13, 2020
@hyangah
Copy link
Contributor

hyangah commented Oct 16, 2020

Sadly, I found -modfile is tricker to use than I thought. It will fail if the current workspace doesn't have go.mod. :-(

Other slightly simpler approaches I can think of are

  1. to use the go binary in $GOROOT/bin/ directory. Is it a safe assumption to make?
  2. to create a temp directory in the workspace. I am reluctant to do that because it will interfere with gopls, or other file watchers.

cc @bmalehorn @suzmue @stamblerre

@bmalehorn
Copy link
Author

Sadly, I found -modfile is tricker to use than I thought. It will fail if the current workspace doesn't have go.mod. :-(

Other slightly simpler approaches I can think of are

  1. to use the go binary in $GOROOT/bin/ directory. Is it a safe assumption to make?
  2. to create a temp directory in the workspace. I am reluctant to do that because it will interfere with gopls, or other file watchers.

cc @bmalehorn @suzmue @stamblerre

1 would work for my use case:

go env | grep GOROOT
GOROOT="/Users/brianmalehorn/.asdf/installs/golang/1.15.2/go"

That's the correct version of go (1.15.2).

It sounds like the problem is that two different things care about current directory:

  1. the go binary itself, via asdf
  2. the actual build

Is it possible to fix 2 by building in another directory? Something like make -C /tmp/build.

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/263977 mentions this issue: src/goInstallTools: use the 'go' command from GOROOT/bin for tool install

@hyangah hyangah added this to the v0.18.0 milestone Oct 21, 2020
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/264318 mentions this issue: src/goInstallTools: use GOROOT/bin for gocode-gomod build too

gopherbot pushed a commit that referenced this issue Nov 19, 2020
This should've been done in cl/263977.

Update #757

Change-Id: I51afbc8a2534c1b3f304ba988b6bcec9c944a048
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/264318
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Reviewed-by: Suzy Mueller <[email protected]>
@golang golang locked and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants