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

Allow gomock to take Bazel common attributes #3207

Merged
merged 3 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/go/extras/extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ go_embed_data_dependencies()

<pre>
gomock(<a href="#gomock-name">name</a>, <a href="#gomock-library">library</a>, <a href="#gomock-out">out</a>, <a href="#gomock-source">source</a>, <a href="#gomock-interfaces">interfaces</a>, <a href="#gomock-package">package</a>, <a href="#gomock-self_package">self_package</a>, <a href="#gomock-aux_files">aux_files</a>, <a href="#gomock-mockgen_tool">mockgen_tool</a>,
<a href="#gomock-imports">imports</a>, <a href="#gomock-copyright_file">copyright_file</a>, <a href="#gomock-mock_names">mock_names</a>)
<a href="#gomock-imports">imports</a>, <a href="#gomock-copyright_file">copyright_file</a>, <a href="#gomock-mock_names">mock_names</a>, <a href="#gomock-kwargs">kwargs</a>)
</pre>

Calls [mockgen](https://github.com/golang/mock) to generates a Go file containing mocks from the given library.
Expand All @@ -102,5 +102,6 @@ If `source` is given, the mocks are generated in source mode; otherwise in refle
| <a id="gomock-imports"></a>imports | dictionary of name-path pairs of explicit imports to use. See [mockgen's -imports](https://github.com/golang/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-copyright_file"></a>copyright_file | optional file containing copyright to prepend to the generated contents. See [mockgen's -copyright_file](https://github.com/golang/mock#flags) for more information. | <code>None</code> |
| <a id="gomock-mock_names"></a>mock_names | dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See [mockgen's -mock_names](https://github.com/golang/mock#flags) for more information. | <code>{}</code> |
| <a id="gomock-kwargs"></a>kwargs | <p align="center"> - </p> | none |


5 changes: 4 additions & 1 deletion extras/gomock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ _gomock_source = rule(
toolchains = [GO_TOOLCHAIN],
)

def gomock(name, library, out, source = None, interfaces = [], package = "", self_package = "", aux_files = {}, mockgen_tool = _MOCKGEN_TOOL, imports = {}, copyright_file = None, mock_names = {}):
def gomock(name, library, out, source = None, interfaces = [], package = "", self_package = "", aux_files = {}, mockgen_tool = _MOCKGEN_TOOL, imports = {}, copyright_file = None, mock_names = {}, **kwargs):
"""Calls [mockgen](https://github.com/golang/mock) to generates a Go file containing mocks from the given library.

If `source` is given, the mocks are generated in source mode; otherwise in reflective mode.
Expand All @@ -168,6 +168,7 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel
imports: dictionary of name-path pairs of explicit imports to use. See [mockgen's -imports](https://github.com/golang/mock#flags) for more information.
copyright_file: optional file containing copyright to prepend to the generated contents. See [mockgen's -copyright_file](https://github.com/golang/mock#flags) for more information.
mock_names: dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See [mockgen's -mock_names](https://github.com/golang/mock#flags) for more information.
kwargs: common attributes](https://bazel.build/reference/be/common-definitions#common-attributes) to all Bazel rules.
"""
if source:
_gomock_source(
Expand All @@ -182,6 +183,7 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel
imports = imports,
copyright_file = copyright_file,
mock_names = mock_names,
**kwargs
)
else:
_gomock_reflect(
Expand All @@ -195,6 +197,7 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel
imports = imports,
copyright_file = copyright_file,
mock_names = mock_names,
**kwargs
)

def _gomock_reflect(name, library, out, mockgen_tool, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions tests/extras/gomock/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gomock(
library = ":client",
package = "client",
source = "client.go",
visibility = ["//visibility:public"],
)

go_test(
Expand Down