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: spurious error about import comments with vendoring #13531

Closed
s8sg opened this issue Dec 8, 2015 · 6 comments
Closed

cmd/go: spurious error about import comments with vendoring #13531

s8sg opened this issue Dec 8, 2015 · 6 comments
Milestone

Comments

@s8sg
Copy link

s8sg commented Dec 8, 2015

In a golang project I was using govendoring in golang 1.5.2.

I have to use a 3rd party library called : github.com/Shopify/sarama

It uses another 3rd party library called: github.com/golang/snappy

Now both of the 3rd party library was present in the : <<project_dir>>/vendor/

Now due to a comment describing the import in snappy:

package snappy // import "github.com/golang/snappy"

the following error is coming:

can't load package: package <<project_path>>/vendor/github.com/golang/snappy: code in directory <project_absolute_path>/vendor/github.com/golang/snappy expects import "github.com/golang/snappy"

I checked by creating the situation manually and the error is the same.
src ---> <<project_package>> ----> <<somefile>>.go || import "github.com/example/a"
|
|--------> vendor ----> github.com ---> example -----> a || import "github.com/example/b"
|--------> vendor ----> github.com ---> example -----> b || package b // import "github.com/example/b"

So the Below statement about Custom Import Path Checking:
The go command will refuse to install a package if the default install path does not match the documented import path.

Probably the reason behind the error is the vendor path and Import Path checking.

@s8sg s8sg changed the title Go list (can't load) issue for commented import statement in package Go list (can't load) issue for Custom Import Path Checking while using GoVendoring Dec 8, 2015
@ianlancetaylor ianlancetaylor changed the title Go list (can't load) issue for Custom Import Path Checking while using GoVendoring cmd/go: Go list (can't load) issue for Custom Import Path Checking while using GoVendoring Dec 8, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Dec 8, 2015
@rsc
Copy link
Contributor

rsc commented Dec 17, 2015

I can't reproduce this using either current development branch or Go 1.5. Can you post a file tree and exact command?

This is what I tried:

$ cd $GOPATH; for i in $(find zzz -type f); do echo '### '$i; cat $i; echo; done
### zzz/top.go
package zzz
import _ "yyy/example/a"

### zzz/vendor/yyy/example/a/a.go
package a
import _ "yyy/example/b"

### zzz/vendor/yyy/example/b/b.go
package b // import "yyy/example/b"

$ GO15VENDOREXPERIMENT=1 go1.5 build -a zzz
$ go build -a zzz
$ 

Thanks.

@rsc
Copy link
Contributor

rsc commented Dec 17, 2015

I should add that import comments are supposed to be ignored in vendor directories, per golang.org/s/go15vendor.

@rsc rsc changed the title cmd/go: Go list (can't load) issue for Custom Import Path Checking while using GoVendoring cmd/go: spurious error about import comments with vendoring Dec 17, 2015
@s8sg
Copy link
Author

s8sg commented Dec 17, 2015

I'm using the govendoring in :
https://github.com/OpenAppStack/singularity

/goprojects/src/org.openappstack/singularity $ go list ./...
can't load package: package org.openappstack/singularity/vendor/github.com/shurcooL/sanitized_
anchor_name: code in directory /home/swarvanu/goprojects/src/org.openappstack/singularity/vend
or/github.com/shurcooL/sanitized_anchor_name expects import "github.com/shurcooL/sanitized_anc
hor_name"
org.openappstack/singularity
org.openappstack/singularity/agent
org.openappstack/singularity/api
org.openappstack/singularity/commands
org.openappstack/singularity/pluginlib
org.openappstack/singularity/pluginlib/utils
org.openappstack/singularity/pluginmanager
org.openappstack/singularity/pluginmanager/pluginconn
org.openappstack/singularity/store
org.openappstack/singularity/vendor/github.com/boltdb/bolt
org.openappstack/singularity/vendor/github.com/boltdb/bolt/cmd/bolt
org.openappstack/singularity/vendor/github.com/cpuguy83/go-md2man/md2man
org.openappstack/singularity/vendor/github.com/inconshreveable/mousetrap
org.openappstack/singularity/vendor/github.com/russross/blackfriday
org.openappstack/singularity/vendor/github.com/spf13/cobra
org.openappstack/singularity/vendor/github.com/spf13/cobra/cobra
org.openappstack/singularity/vendor/github.com/spf13/cobra/cobra/cmd
org.openappstack/singularity/vendor/github.com/spf13/jwalterweatherman
org.openappstack/singularity/vendor/github.com/spf13/pflag

Please let me know in case I'm doing any mistake

@s8sg
Copy link
Author

s8sg commented Dec 17, 2015

Hi @rsc

My Bad : Missed to export GO15VENDOREXPERIMENT=1 before go list in MAKEFILE
The issue is closed.

@s8sg s8sg closed this as completed Dec 17, 2015
@rsc rsc reopened this Dec 17, 2015
@rsc
Copy link
Contributor

rsc commented Dec 17, 2015

Reopening issue: if the problem is that the vendor experiment was turned off, then I would expect a clearer error. Reading the message, I don't understand what is doing the "importing". (Perhaps nothing, which is the problem with the message.)

@rsc
Copy link
Contributor

rsc commented Jan 14, 2016

I looked at this some more and I don't have a clear way to give a better error without second-guessing pre-existing uses of the word "vendor".

The problem of forgetting to turn GO15VENDOREXPERIMENT on is gone in Go 1.6, since it's on by default. So I think it's safe to do nothing here after all.

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