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

cmd/go: invalid vendoredImportPath error #14054

Closed
bashtian opened this issue Jan 21, 2016 · 12 comments
Closed

cmd/go: invalid vendoredImportPath error #14054

bashtian opened this issue Jan 21, 2016 · 12 comments

Comments

@bashtian
Copy link

Go 1.6beta2

go run fails when the cwd is a symlink to a folder in $GOPATH

ln -s $GOPATH/src/golang.org/x/mobile/example/basic/ basic
cd basic
go run main.go

$ invalid vendoredImportPath: ...

It works when I disable the vendor experiment

export GO15VENDOREXPERIMENT=0
@bradfitz
Copy link
Contributor

What is main.go?

I think this is fixed, now that we stopped using vendor for std.

@bradfitz
Copy link
Contributor

Please try with tip. I'm pretty sure this is fixed now.

@bashtian
Copy link
Author

The problem still exits in go1.6rc1

edit: The problem is only with go run, go build and go install work fine

@bradfitz
Copy link
Contributor

You still didn't answer my original question, so I'm going to leave this closed.

Please provide enough information for us to reproduce the problem.

@bashtian
Copy link
Author

Sorry for that. It's the example from the mobile repo
https://github.com/golang/mobile/blob/master/example/basic/main.go
But it happens for me with all main packages when you try to run them in a symlink outside of the gopath.

@bradfitz
Copy link
Contributor

Where are you when you try to symlink?

@bashtian
Copy link
Author

This is my setup:

$GOPATH=/home/me/gopath
CWD=/home/me/

I think it happens anywhere outside of gopath, but works with a symlink inside the gopath.

@bradfitz
Copy link
Contributor

I see. Maybe this should work. Go generally isn't too friendly towards symlinks. @rsc?

@bradfitz bradfitz reopened this Jan 28, 2016
@bradfitz bradfitz added this to the Go1.6Maybe milestone Jan 28, 2016
@rsc
Copy link
Contributor

rsc commented Jan 29, 2016

Please try applying this diff to cmd/go and rebuild cmd/go:

diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 5ecfcb8..85f2a50 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -406,8 +406,20 @@ func vendoredImportPath(parent *Package, path string) (found string) {
    if parent == nil || parent.Root == "" {
        return path
    }
+   // go/build decided that hasSubdir(parent.Root, parent.Dir) is true,
+   // and that computation applies EvalSymlinks to both before
+   // doing the string comparison.
+   // Do the same here so that the strings match up below.
+   // See golang.org/issue/14054.
    dir := filepath.Clean(parent.Dir)
-   root := filepath.Join(parent.Root, "src")
+   if p, err := filepath.EvalSymlinks(dir); err == nil {
+       dir = p
+   }
+   root := parent.Root
+   if p, err := filepath.EvalSymlinks(root); err == nil {
+       root = p
+   }
+   root = filepath.Join(root, "src")
    if !hasFilePathPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator {
        fatalf("invalid vendoredImportPath: dir=%q root=%q separator=%q", dir, root, string(filepath.Separator))
    }

If it fixes your problem (it seems to on my machine) I will work up a test case and try to get it into the final release. Thanks.

@bashtian
Copy link
Author

@rsc Thanks, this patch fixed the problem

@rsc
Copy link
Contributor

rsc commented Jan 29, 2016

Sorry, testing discovered a few problems with that patch. New approach at https://go-review.googlesource.com/19102. If you can try that, it'd be great, but I've verified that it fixes the mobile example above.

@bashtian
Copy link
Author

@rsc works for me as well, thanks for the quick fix

@golang golang locked and limited conversation to collaborators Feb 3, 2017
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

4 participants