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

proposal: cmd/go: force vendor directory only #19234

Closed
azr opened this issue Feb 22, 2017 · 8 comments
Closed

proposal: cmd/go: force vendor directory only #19234

azr opened this issue Feb 22, 2017 · 8 comments

Comments

@azr
Copy link
Contributor

azr commented Feb 22, 2017

Hello there,

TLDR: it would be nice to be able to go build --using-vendors-only or something similar.

More thought:
I like a revision of a go project to be buildable.
Often when I update the vendors of a project, the ci tools tell me there is a missing dep or something is wrong with this or that dep, because that other pkg is outdated, because the system are different or other various reasons.
But it always works locally and then I find myself having a lot commits that contain fix godeps

So I'd like to have a pre commit hook that checks if the project builds in my ci.

that hook would do something like this: GOOS=linux go build --using-vendors-only

Tried GOOS=linux go build -pkgdir ./vendor but nope

@mvdan
Copy link
Member

mvdan commented Feb 22, 2017

What about setting GOPATH to an empty directory?

@azr
Copy link
Contributor Author

azr commented Feb 22, 2017

@mvdan empty default to $HOME and "/tmp" failed:

GOPATH=/tmp GOOS=linux go build ./cmd/runner
output:

 cannot find package "github.com/stvp/rollbar" in any of:
	/usr/local/opt/go/libexec/src/github.com/stvp/rollbar (from $GOROOT)
	/tmp/src/github.com/stvp/rollbar (from $GOPATH)

It doesn't look for the vendor dir, may be it should ?

And I can't use go build "project name/repo" because GOPATH is wrong.

Edit: same output for GOPATH=/tmp GOOS=linux go build -pkgdir ./vendor ./cmd/runner

@mvdan
Copy link
Member

mvdan commented Feb 22, 2017

Ah right, it can't find any of the packages then. I guess you could set up a new GOPATH and link src/your/pkg to the right place, which should work as a script or shell alias. But that's not as simple.

Alternatively, I've seen discussions around "building Go packages outside of GOPATH". That might be a solution for this if you unset GOPATH, but it would probably be in the long term. I think that's #17271.

@vcabbage
Copy link
Member

I agree that it would be useful to do this.

For the time being you could try https://github.com/cloudflare/hellogopher. The Makefile creates a .GOPATH directory within your project and uses that for tests, building, etc.

@azr
Copy link
Contributor Author

azr commented Feb 23, 2017

@vcabbage works like a charm, thanks

@quentinmit quentinmit changed the title go build using vendor directory only cmd/go: force vendor directory only Feb 27, 2017
@quentinmit quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Feb 27, 2017
@quentinmit quentinmit added this to the Go1.9Maybe milestone Feb 27, 2017
@rtuin
Copy link

rtuin commented Apr 10, 2017

I think this is a great idea. Being able to build (dependencies) in an isolated environment reduces frustration and increases software stability. 👍

@rsc
Copy link
Contributor

rsc commented Jun 12, 2017

On hold for package management. We'll get there but vendor may or may not be the answer.

@rsc rsc changed the title cmd/go: force vendor directory only proposal: cmd/go: force vendor directory only Jun 12, 2017
@rsc rsc modified the milestones: Proposal, Go1.9Maybe Jun 12, 2017
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 16, 2019
@bcmills
Copy link
Contributor

bcmills commented Sep 28, 2022

I think this is -mod=vendor in module mode.
(Can this proposal be closed as completed?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants