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

vscode-go doesn't work well with symlinked directroy #846

Closed
bruceauyeung opened this issue Mar 7, 2017 · 7 comments
Closed

vscode-go doesn't work well with symlinked directroy #846

bruceauyeung opened this issue Mar 7, 2017 · 7 comments

Comments

@bruceauyeung
Copy link

reproduce steps:

  1. mkdir $HOME/heapster-build/src/k8s.io/ -p
  2. mkdir /tmp/heapster/ -p && cd /tmp/heapster/ && git clone https://github.com/kubernetes/heapster.git
  3. cd $HOME/heapster-build/src/k8s.io/ && ln -s mkdir /tmp/heapster/
  4. export GOPATH=$HOME/heapster-build && code $HOME/heapster-build
  5. open $HOME/heapster-build/src/k8s.io/heapster/metrics/heapster.go and vscode-go will complain packages such as k8s.io/apimachinery/pkg/fields can not be found, but actually they are in the vendor directory.
  6. cd $HOME/heapster-build/src/k8s.io/heapster/metrics , and then run go build heapster.go auth.go handlers.go , this can build successfully.

if i copy /tmp/heapster/ to $HOME/heapster-build/src/k8s.io` instead of making a symlink , vscode-go works well

vscode:1.10.1
vscode-go:0.6.55
os:Ubuntu 16.04.1 LTS

@bruceauyeung
Copy link
Author

@ramya-rao-a

@ramya-rao-a
Copy link
Contributor

I can repro! (finally)

Had to tweak some of your repro steps though.

  • Don't create the heapster in /tmp, because git clone will take care of that
  • when creating the symlink, ln -s /tmp/heapster/ . instead of ln -s mkdir /tmp/heapster/

I can see the errors in VS Code, but building in the terminal is successful.

Looks like the process that is spawned to run go build by the extension is not aware of the vendor folder, not sure why.

Anybody having any ideas is appreciated.

@ramya-rao-a
Copy link
Contributor

Can you try go list all | grep "glog" ? Or grep for any of the vendor packages. It doesn't show up for me.

@ramya-rao-a
Copy link
Contributor

Turns out command line and newly spawned process resolve . differently in case of symlinks.
Which is why go build . works from command line but not from the extension.
Solution is to not use ., but to use the import path.

Phew

This was a cool problem to figure out, thanks for reporting @bruceauyeung!

ramya-rao-a added a commit to ramya-rao-a/vscode-go that referenced this issue Mar 15, 2017
@ramya-rao-a
Copy link
Contributor

The latest update (0.6.56) to the Go extension has the fix to this issue.

@zhouhaibing089
Copy link
Contributor

zhouhaibing089 commented Aug 20, 2017

@ramya-rao-a I'm having a similar issue:

I am a kubernetes developer(and thanks to vs-code which makes debugging extremely convenient), when I navigate to ${GOPATH}/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime/scheme_test.go(which symlinks to ${GOPATH}/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go) and then click the run test, it complains:

Running tool: /usr/local/bin/go test -timeout 30s -tags  -run ^TestScheme$

can't load package: package k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime: code in directory /Users/haibzhou/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime expects import "k8s.io/apimachinery/pkg/runtime"
Error: Tests failed.

And when I check in console:

$ go test k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime
ok      k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime        0.049s
$ go test k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime
can't load package: package k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime: code in directory /Users/haibzhou/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime expects import "k8s.io/apimachinery/pkg/runtime"

I am using vscode-go at version 0.6.63 by the way.

Adding a customized config does not work either:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceRoot}/vendor/k8s.io/apimachinery/pkg/runtime/scheme_test.go",
            "env": {},
            "args": [
                "-test.run=TestScheme"
            ],
            "showLog": true
        }
    ]
}

@ramya-rao-a
Copy link
Contributor

@zhouhaibing089 In the latest update to the Go extension, you should be able to run and debug tests in symlinked environments. Thanks for the fix!

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 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

No branches or pull requests

3 participants