golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.26k stars 608 forks source link

Cannot run mockgen with build tags (similar to go build --tags/ginkgo --tags) #76

Closed monikakatiyar16 closed 7 years ago

monikakatiyar16 commented 7 years ago

We have a project which excludes some C dependencies by running go build as go build --tags "tag1 tag2 tag3". Running ginkgo with ginkgo --tags "tag1 tag2 tag3". However, we couldn't find such option with mockgen. Is there any way to achieve that with mockgen?

balshetzer commented 7 years ago

Hi,

Do you think you could help me better understand this issue with an example?

Thanks, Hesky

monikakatiyar16 commented 7 years ago

@balshetzer

I have a requirement to build without some C dependencies, which can be achieved by providing build tags.

During go build, by using: go build --tags "exclude_graphdriver_btrfs" For running ginkgo tests, by using: ginkgo --tags "exclude_graphdriver_btrfs"

These build tags avoid the compilation of the go files containing these tags as comments, by not passing it to the compiler. So, these commands work for my use case, without installing the C dependency.

Running mockgen without these C dependencies gives an error. So, though I can build the application without the dependencies, for running mockgen I have to install the dependencies for the app to build correctly via mockgen. In this case, I have to install the btrfs-tools package on ubuntu system for running mockgen.

I might be missing something. Please correct me, in that case.

balshetzer commented 7 years ago

When you run mockgen, do you use "source mode" (using the --source flag) or "reflect mode"?

monikakatiyar16 commented 7 years ago

We use the reflect mode. (just like: mockgen database/sql/driver Conn,Driver)

balshetzer commented 7 years ago

Please try #78 to see if it fixes this problem. You would need to add --build_flags='--tags=exclude_graphdriver_brtfs' to your mockgen command.

monikakatiyar16 commented 7 years ago

Yeah.. With #78 changes, it works like a charm.. Thanks..!