From ab9dd5b0e28957ded2d29f1a5254b0acdda902aa Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Sat, 18 Jun 2022 08:18:13 -0700 Subject: [PATCH 1/3] saving gomock patch Extract common arguments of gomock as kwargs --- extras/gomock.bzl | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/extras/gomock.bzl b/extras/gomock.bzl index e1fc93fda9..a918d85337 100644 --- a/extras/gomock.bzl +++ b/extras/gomock.bzl @@ -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 = [], aux_files = {}, **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. @@ -175,13 +175,8 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel library = library, out = out, source = source, - package = package, - self_package = self_package, aux_files = aux_files, - mockgen_tool = mockgen_tool, - imports = imports, - copyright_file = copyright_file, - mock_names = mock_names, + **kwargs ) else: _gomock_reflect( @@ -189,12 +184,7 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel library = library, out = out, interfaces = interfaces, - package = package, - self_package = self_package, - mockgen_tool = mockgen_tool, - imports = imports, - copyright_file = copyright_file, - mock_names = mock_names, + **kwargs ) def _gomock_reflect(name, library, out, mockgen_tool, **kwargs): From b5ed19df37a7fad071598e56c77fd97b404a55d2 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Sat, 18 Jun 2022 12:36:53 -0700 Subject: [PATCH 2/3] move gomock attributes out of kwargs --- docs/go/extras/extras.md | 3 ++- extras/gomock.bzl | 19 ++++++++++++++++--- tests/extras/gomock/BUILD.bazel | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/go/extras/extras.md b/docs/go/extras/extras.md index 35a6ec30b2..f0fafc4946 100644 --- a/docs/go/extras/extras.md +++ b/docs/go/extras/extras.md @@ -77,7 +77,7 @@ go_embed_data_dependencies()
 gomock(name, library, out, source, interfaces, package, self_package, aux_files, mockgen_tool,
-       imports, copyright_file, mock_names)
+       imports, copyright_file, mock_names, kwargs)
 
Calls [mockgen](https://github.com/golang/mock) to generates a Go file containing mocks from the given library. @@ -102,5 +102,6 @@ If `source` is given, the mocks are generated in source mode; otherwise in refle | 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. | None | | 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 |

-

| none | diff --git a/extras/gomock.bzl b/extras/gomock.bzl index a918d85337..ff80593374 100644 --- a/extras/gomock.bzl +++ b/extras/gomock.bzl @@ -150,7 +150,7 @@ _gomock_source = rule( toolchains = [GO_TOOLCHAIN], ) -def gomock(name, library, out, source = None, interfaces = [], aux_files = {}, **kwargs): +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. @@ -168,6 +168,7 @@ def gomock(name, library, out, source = None, interfaces = [], aux_files = {}, * 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( @@ -175,8 +176,14 @@ def gomock(name, library, out, source = None, interfaces = [], aux_files = {}, * library = library, out = out, source = source, + package = package, + self_package = self_package, aux_files = aux_files, - **kwargs + mockgen_tool = mockgen_tool, + imports = imports, + copyright_file = copyright_file, + mock_names = mock_names, + **kwargs, ) else: _gomock_reflect( @@ -184,7 +191,13 @@ def gomock(name, library, out, source = None, interfaces = [], aux_files = {}, * library = library, out = out, interfaces = interfaces, - **kwargs + package = package, + self_package = self_package, + mockgen_tool = mockgen_tool, + imports = imports, + copyright_file = copyright_file, + mock_names = mock_names, + **kwargs, ) def _gomock_reflect(name, library, out, mockgen_tool, **kwargs): diff --git a/tests/extras/gomock/BUILD.bazel b/tests/extras/gomock/BUILD.bazel index 5d807565cf..5b04496f7e 100644 --- a/tests/extras/gomock/BUILD.bazel +++ b/tests/extras/gomock/BUILD.bazel @@ -19,6 +19,7 @@ gomock( library = ":client", package = "client", source = "client.go", + visibility = ["//visibility:public"], ) go_test( From 02c967470f01cd6d726911578ec6983d5236bf82 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Sat, 18 Jun 2022 14:55:07 -0700 Subject: [PATCH 3/3] buildifier --- extras/gomock.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras/gomock.bzl b/extras/gomock.bzl index ff80593374..047171e2a6 100644 --- a/extras/gomock.bzl +++ b/extras/gomock.bzl @@ -183,7 +183,7 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel imports = imports, copyright_file = copyright_file, mock_names = mock_names, - **kwargs, + **kwargs ) else: _gomock_reflect( @@ -197,7 +197,7 @@ def gomock(name, library, out, source = None, interfaces = [], package = "", sel imports = imports, copyright_file = copyright_file, mock_names = mock_names, - **kwargs, + **kwargs ) def _gomock_reflect(name, library, out, mockgen_tool, **kwargs):