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

gocode-gomod is installed in a wrong directory when GOPATH has multiple elements #368

Closed
vbatoufflet opened this issue Jul 17, 2020 · 9 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. tools/installation
Milestone

Comments

@vbatoufflet
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.14.5 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.47.2
      17299e413d5590b14ab0340ea477cdd86ff13daf
      x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.15.0
  • Run go env to get the go development environment details
    • GO111MODULE="on"
      GOARCH="amd64"
      GOBIN=""
      GOCACHE="/Users/vincent/Library/Caches/go-build"
      GOENV="/Users/vincent/Library/Application Support/go/env"
      GOEXE=""
      GOFLAGS=""
      GOHOSTARCH="amd64"
      GOHOSTOS="darwin"
      GOINSECURE=""
      GONOPROXY=""
      GONOSUMDB=""
      GOOS="darwin"
      GOPATH="/Users/vincent/.opt/lib/go:/Users/vincent/Development/go"
      GOPRIVATE=""
      GOPROXY="https://proxy.golang.org,direct"
      GOROOT="/usr/local/Cellar/go/1.14.5/libexec"
      GOSUMDB="sum.golang.org"
      GOTMPDIR=""
      GOTOOLDIR="/usr/local/Cellar/go/1.14.5/libexec/pkg/tool/darwin_amd64"
      GCCGO="gccgo"
      AR="ar"
      CC="clang"
      CXX="clang++"
      CGO_ENABLED="1"
      GOMOD="/dev/null"
      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/_r/hqcn896x7jx91ckb9kxr5scm0000gn/T/go-build425580244=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

"go.formatTool": "goimports",
"go.lintTool": "golangci-lint",
"go.useLanguageServer": true,

Describe the bug

Beginning with v0.15.0, the extension is unable to install gocode, giving the following error:

Installing 1 tool at /Users/vincent/.opt/lib/go:/Users/vincent/Development/go/bin in module mode.
  gocode


1 tools failed to install.

gocode: Failed to close gocode process: Error: Command failed: /Users/vincent/.opt/lib/go/bin/gocode close
2020/07/17 17:12:54 dial unix /var/folders/_r/hqcn896x7jx91ckb9kxr5scm0000gn/T/gocode-daemon.vincent: connect: no such file or directory

It only seem to happen when GOPATH hold multiple entries, ignoring the : separator. The file being installed at /Users/vincent/.opt/lib/go:/Users/vincent/Development/go/bin/gocode-gomod instead of /Users/vincent/.opt/lib/go/bin/gocode-gomod.

ℹ️ The gocode install works on v0.14.4.

Steps to reproduce the behavior:

  1. Press Cmd+Shift+P (macOS)
  2. Select “Go: Install/Update tools” then try to install "gocode"
  3. See error in “Output” panel
@vbatoufflet vbatoufflet changed the title gocode fails to install while GOPATH holds multiple values gocode fails to install while GOPATH holds multiple paths Jul 17, 2020
@stamblerre
Copy link
Contributor

There is a bug in the gocode installation process, which will be corrected in the next release: #362.

However, if you are using the language server, you shouldn't need to have gocode installed at all.

@vbatoufflet
Copy link
Author

vbatoufflet commented Jul 17, 2020

Hi @stamblerre,

Thanks for your quick answer!

I just looked back at result I encountered, I think there might be 2 problems:

  • the one you linked (thanks, I missed this one)
  • the fact that the : separator is not taken into account in GOPATH during binary installation, resulting in a binary to be installed at /path1:/path2/bin instead of /path1/bin (which wasn't the case in v0.14.x versions).

But maybe I missed something and both are related.

@stamblerre stamblerre changed the title gocode fails to install while GOPATH holds multiple paths tools install to final element of GOPATH (rather than first) Jul 17, 2020
@stamblerre
Copy link
Contributor

  • the fact that the : separator is not taken into account in GOPATH during binary installation, resulting in a binary to be installed at /path1:/path2/bin instead of /path1/bin (which wasn't the case in v0.14.x versions).

Yep, I agree that there might be a general issue with tool installation - we'll take a look.

But I do want to reiterate my earlier point that, if you're using the language server (which you are, based on your settings), there's no need to have gocode installed on your machine at all.

@vbatoufflet
Copy link
Author

But I do want to reiterate my earlier point that, if you're using the language server (which you are, based on your settings), there's no need to have gocode installed on your machine at all.

Thanks again! Point duly noted 🙂

@hyangah
Copy link
Contributor

hyangah commented Jul 17, 2020

The message is misleading.

installingMsg += `${toolsGopath}${path.sep}bin`;

The actual installation is done by the go command that understands multiple entries in GOPATH. So, I don't think tools installation is using the last element.

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/243282 mentions this issue: goInstallTools: fix misleading message about installation location

gopherbot pushed a commit that referenced this issue Jul 17, 2020
If GOPATH has multiple elements, the current message that simply
appends 'bin' at the end is misleading.

Tested manually by providing go.toolsGopath with multiple elements.
`go get` installed the binaries in the bin directory of the first
element.

Update #368

Change-Id: I4dcc87b9fe22f024fcf3fe8c452243eb66d17a15
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/243282
Reviewed-by: Rebecca Stambler <[email protected]>
@vbatoufflet
Copy link
Author

The actual installation is done by the go command that understands multiple entries in GOPATH. So, I don't think tools installation is using the last element.

The thing is at some point it used the whole GOPATH value rather than the first/last element:

> echo $GOPATH
/Users/vincent/.opt/lib/go:/Users/vincent/Development/go

> tree $HOME/.opt/lib/go\:
/Users/vincent/.opt/lib/go:
└── Users
    └── vincent
        └── Development
            └── go
                └── bin
                    └── gocode-gomod

Other tools were installed at the right location /Users/vincent/.opt/lib/go/bin. Only gocode-gomod ended creating a folder name “go:” (: being part of its name), having GOPATH used at one full path.

@hyangah
Copy link
Contributor

hyangah commented Jul 18, 2020

@vbatoufflet Ah, right. For -gomod suffixed tools, the extension is installing the tool using go build -o and it uses $GOPATH/bin, which is a bug. (Instead of using the final element or first element, it puts under a new directory $GOPATH/bin (including the path delimiters). Fixing it.

@hyangah hyangah changed the title tools install to final element of GOPATH (rather than first) gocode-gomod is installed in a wrong directory when GOPATH has multiple elements Jul 18, 2020
@hyangah hyangah added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 18, 2020
@hyangah hyangah added this to the v0.16.0 milestone Jul 18, 2020
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/243417 mentions this issue: src/goInstallTools: install -gomod tools in the right directory

@golang golang locked and limited conversation to collaborators Jul 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. tools/installation
Projects
None yet
Development

No branches or pull requests

4 participants