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: vendoring does not work for main package directly in $GOPATH/src #19899

Closed
sparkthu opened this issue Apr 9, 2017 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@sparkthu
Copy link

sparkthu commented Apr 9, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.8

What operating system and processor architecture are you using (go env)?

amd64

What did you do?

I have a main.go just in $GOPATH/src/,any other works well for this project. But if I import something in this main.go and put the packages in vendor directory, go build will report an error.

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

vendoring should work for the main package in $GOPATH/src

What did you see instead?

@bradfitz bradfitz changed the title vendoring does not work for main package directly in $GOPATH/src cmd/go: vendoring does not work for main package directly in $GOPATH/src Apr 9, 2017
@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 9, 2017
@davecheney
Copy link
Contributor

davecheney commented Apr 9, 2017 via email

@rsc
Copy link
Contributor

rsc commented Apr 10, 2017

You can put Go source code in $GOPATH/src, but only because you can put Go source code in any directory, even outside $GOPATH. For the purposes of the Go command, code in $GOPATH/src is considered not part of the usual $GOPATH processing - only subdirectories of $GOPATH/src are subject to that. (As Dave says, a distinguishing characteristic is that in $GOPATH/src there is no clear import path, just like anywhere else outside $GOPATH.)

That's why vendor doesn't work, and why vendor isn't going to work.

If you do drop a source file in $GOPATH/src and run 'go build', the resulting binary is named 'src', because the heuristic to use the name of the containing directory still applies. Unless you are actually building a program named 'src', you have to create a subdirectory to set the name properly. You also have to create a subdirectory to pick up vendored code.

Sorry.

@rsc rsc closed this as completed Apr 10, 2017
@golang golang locked and limited conversation to collaborators Apr 10, 2018
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants