-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
Extend gomock to allow passing an source_importpath
instead of library
when operating in source mode
#3350
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very reasonable to me - it's a very simple way to get by without a potentially annoying dependency edge.
extras/gomock.bzl
Outdated
mandatory = True, | ||
mandatory = False, | ||
), | ||
"importpath": attr.string( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid the attribute name importpath
would confuse Gazelle: now there are two targets with the same importpath
value. How about calling it source_package
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think calling it source_package
would cause confusion with package
, maybe source_importpath
would be a good middle ground?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's actually also self_package
, which has this description:
self_package: the full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. See [mockgen's -self_package](https://github.com/golang/mock#flags) for more information.
Perhaps we can avoid introducing a new parameter and just use this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, on second thought it's probably better to avoid overloading the parameter given it has special meaning to mockgen
itself. Have gone with source_importpath
for now.
@ramenjosh To be honest, I have no idea what is causing that failure. Could you amend and force-push your branch to trigger a new CI run? It may just be a flake. |
…rary` when operating in source mode. This enables a use case where mocks can be included as part of the source files in a go_library. Added additional test cases and documentation.
6e67e3f
to
37dddb3
Compare
importpath
instead of library
when operating in source modesource_importpath
instead of library
when operating in source mode
@fmeum Can we revive that change? The issue is still present. Thanks. |
Sure, I can review this if someone can resolve the conflicts. The flaky tests should be gone now. |
Thanks, created #3822. |
What type of PR is this?
Feature
What does this PR do? Why is it needed?
This PR adds a new parameter,
importpath
to thegomock
rule. This parameter is optional, and allows agomock
target running in source mode to avoid depending on ago_library
. As far as I can see, the only use for thego_library
in source mode is to extract animportpath
.I've also extended the test cases to test the different modes
gomock
can operate in, and made sure there's a link togomock
on the top level README.Which issues(s) does this PR fix?
Fixes #3349