simplify mockgen usage for private interfaces #3769
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I finally figured out a way to get rid of the horrible bash script currently used for mock generation: https://github.com/quic-go/quic-go/blob/af517bdef10a483bacd5eb96e67ebca4e4e151b2/mockgen_private.sh. libp2p/go-libp2p#2248 (comment) is what triggered this.
The trick is to export the type using a type alias, but to hide this behind a build flag:
mockgen
can then be called with the-build_flags="-tags=gomock"
option to set the required build tag. And to be able to have thego generate
command in the same file, thegenerate
build flag is added to the file as well (go generate
sets thegenerate
build flag automatically).