Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Use dependencies in vendor/ instead of downloading them #296

Closed
amuttsch opened this issue May 20, 2019 · 13 comments
Closed

Use dependencies in vendor/ instead of downloading them #296

amuttsch opened this issue May 20, 2019 · 13 comments
Assignees
Labels
modules status: needs more info This issue need more information from the author. type: feature request
Milestone

Comments

@amuttsch
Copy link

I have a Go project that uses modules and stores its dependencies in the vendor/ folder. In our CI pipeline, we install gomock and run it via //go:generate mockgen -source ./foo/service.go -destination gen/foo/mocks.go -package foo.

gomock then tries to download all dependencies from its source repositories instead of using the vendor folder. This is problematic for us as we have some dependencies in a private repo that uses self signed certificates. Thats why we want to use the vendor/ folder.

We execute go generate -mod vendor to trigger the generation, we tried prefixing it with GOFLAGS=-mod=vendor and using -build_flags "-mod vendor" , but gomock always downloads all dependencies.

How can we tell gomock to look for dependencies in the vendor folder first before downloading them? Thanks!

@soniah
Copy link

soniah commented Jun 12, 2019

The standard suggestion is to use retool however retool isn't module aware 🤣 There's a blog post retooling retool about using mage to download build tool dependencies, I'm following up on that.

A possible solution to this issue/bug would to make mockgen it's own module, so it could be easily vendored using the go mod mechanisms.

@matyat
Copy link

matyat commented Aug 14, 2019

I got this working by putting in my go:generate line -build_flags=-mod=vendor, no quotes. Must be something funny going on with how go generate escapes quotes maybe?

@soniah
Copy link

soniah commented Aug 14, 2019

Thanks @Logibox. gomock is painful to use with modules, they've been going to fix it for a while, hopefully this is a working temporary fix.

@minicuts minicuts self-assigned this Dec 19, 2019
minicuts pushed a commit to minicuts/mock that referenced this issue Dec 19, 2019
Value of -build_flags was passed to 'go' as a single argument.
For example when passing -build_flags "-mod vendor", the invoked
commandline was `go -mod\ vendor` and the go command errored out because
there is no such arg.

That has caused confusion, e.g. in golang#296

Solve this by splitting the argument by a space.
@minicuts
Copy link
Contributor

minicuts commented Dec 19, 2019

@Logibox I made a small fix #357 to address the -build_flags behavior.

@amuttsch has the workaround with -build_flags=-mod=vendor worked in your case? If yes I will consider to add automatic fallback to run module download mode vendor if default download mode fails.

@soniah It would be great if you provided some more details about issues you are running into with gomock and modules. I can try to think about how to improve that.

codyoss pushed a commit that referenced this issue Dec 20, 2019
Value of -build_flags was passed to 'go' as a single argument.
For example when passing -build_flags "-mod vendor", the invoked
commandline was `go -mod\ vendor` and the go command errored out because
there is no such arg.

That has caused confusion, e.g. in #296

Solve this by splitting the argument by a space.
@codyoss codyoss added the status: needs more info This issue need more information from the author. label Feb 28, 2020
@codyoss
Copy link
Member

codyoss commented Feb 28, 2020

@amuttsch @Logibox @soniah Any updates?

@soniah
Copy link

soniah commented Feb 29, 2020

Hi @nguyenfilip @codyoss I haven't looked at this for ages, I'll have to think through the issues and implications. @nguyenfilip I can't remember the issues I was having.

I'm sure you've looked the HEAD of master; FYI mocks are now built into the mocks folder and the build command is described in the README. But this seems is a different issue.

@Logibox made the following comment earlier in the thread:

I got this working by putting in my go:generate line -build_flags=-mod=vendor, no quotes

What results did you get from this @codyoss ? I feel your pain about self signed certs. Have you tried setting up a go mod proxy using Athens?

@codyoss codyoss added this to the v1.5.0 milestone Mar 4, 2020
@minicuts
Copy link
Contributor

@codyoss @amuttsch @soniah I think this has been fixed by #390 in mockgen 1.4.1. There was a similar problem described in another bug #347 and the OP in that bug confirmed the issue has been fixed for them. In the discussion of the bug I also provided some sample reproducer that shows correct behavior of mockgen+vendoring with mockgen 1.4.1

@orian
Copy link

orian commented Mar 18, 2020

The problem is still there, I'm running mockgen:

mockgen -source external.go -destination mocks/mock.go -build_flags=-mod=vendor and it persistently trying to fetch the packages (and fails cause some are private).

@codyoss
Copy link
Member

codyoss commented Mar 18, 2020

@orian What version are you using? mockgen -version

@orian
Copy link

orian commented Mar 18, 2020

v1.4.3

@codyoss
Copy link
Member

codyoss commented Mar 18, 2020

@orian Could you open up a new issue and detail a small example of how to reproduce.

@thynquest
Copy link

Hello
Any updates on this issue?
Thank you

@codyoss
Copy link
Member

codyoss commented Apr 13, 2020

@thynquest can you provide a small example showing this not working for you. This is a closed issue, so it is not being actively looked at. The original issue has been fixed. Please open a new issue with details to get better traction.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
modules status: needs more info This issue need more information from the author. type: feature request
Projects
None yet
Development

No branches or pull requests

7 participants