Skip to content

Commit

Permalink
Rename to source_importpath
Browse files Browse the repository at this point in the history
  • Loading branch information
ramenjosh committed Nov 16, 2022
1 parent b4b03ae commit 6e67e3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions docs/go/extras/extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ go_embed_data_dependencies()
## gomock

<pre>
gomock(<a href="#gomock-name">name</a>, <a href="#gomock-out">out</a>, <a href="#gomock-library">library</a>, <a href="#gomock-importpath">importpath</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>,
gomock(<a href="#gomock-name">name</a>, <a href="#gomock-out">out</a>, <a href="#gomock-library">library</a>, <a href="#gomock-source_importpath">source_importpath</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-kwargs">kwargs</a>)
</pre>

Expand All @@ -92,8 +92,8 @@ If `source` is given, the mocks are generated in source mode; otherwise in refle
| :------------- | :------------- | :------------- |
| <a id="gomock-name"></a>name | the target name. | none |
| <a id="gomock-out"></a>out | the output Go file name. | none |
| <a id="gomock-library"></a>library | the Go library to look into for the interfaces (reflective mode) or source (source mode). If running in source mode, you can specify importpath instead of this parameter. | <code>None</code> |
| <a id="gomock-importpath"></a>importpath | the importpath for the source file. Alternative to passing library, which can lead to circular dependencies between mock and library targets. Only valid for source mode. | <code>""</code> |
| <a id="gomock-library"></a>library | the Go library to look into for the interfaces (reflective mode) or source (source mode). If running in source mode, you can specify source_importpath instead of this parameter. | <code>None</code> |
| <a id="gomock-source_importpath"></a>source_importpath | the importpath for the source file. Alternative to passing library, which can lead to circular dependencies between mock and library targets. Only valid for source mode. | <code>""</code> |
| <a id="gomock-source"></a>source | a Go file in the given <code>library</code>. If this is given, <code>gomock</code> will call mockgen in source mode to mock all interfaces in the file. | <code>None</code> |
| <a id="gomock-interfaces"></a>interfaces | a list of interfaces in the given <code>library</code> to be mocked in reflective mode. | <code>[]</code> |
| <a id="gomock-package"></a>package | the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See [mockgen's -package](https://github.com/golang/mock#flags) for more information. | <code>""</code> |
Expand Down
12 changes: 6 additions & 6 deletions extras/gomock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _gomock_source_impl(ctx):
# be included as part of that same library, as it results in a dependency loop (GoMock -> GoLibrary -> GoMock).
# Allowing users to pass an importpath directly bypasses this issue.
# See the test case in //tests/extras/gomock/source_with_importpath for an example.
importpath = ctx.attr.importpath if ctx.attr.importpath else ctx.attr.library[GoLibrary].importmap
importpath = ctx.attr.source_importpath if ctx.attr.source_importpath else ctx.attr.library[GoLibrary].importmap

# create GOPATH and copy source into GOPATH
source_relative_path = paths.join("src", importpath, ctx.file.source.basename)
Expand Down Expand Up @@ -110,7 +110,7 @@ _gomock_source = rule(
providers = [GoLibrary],
mandatory = False,
),
"importpath": attr.string(
"source_importpath": attr.string(
doc = "The importpath for the source file. Alternative to passing library, which can lead to circular dependencies between mock and library targets.",
mandatory = False,
),
Expand Down Expand Up @@ -161,16 +161,16 @@ _gomock_source = rule(
toolchains = [GO_TOOLCHAIN],
)

def gomock(name, out, library = None, importpath = "", source = None, interfaces = [], package = "", self_package = "", aux_files = {}, mockgen_tool = _MOCKGEN_TOOL, imports = {}, copyright_file = None, mock_names = {}, **kwargs):
def gomock(name, out, library = None, source_importpath = "", 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.
Args:
name: the target name.
out: the output Go file name.
library: the Go library to look into for the interfaces (reflective mode) or source (source mode). If running in source mode, you can specify importpath instead of this parameter.
importpath: the importpath for the source file. Alternative to passing library, which can lead to circular dependencies between mock and library targets. Only valid for source mode.
library: the Go library to look into for the interfaces (reflective mode) or source (source mode). If running in source mode, you can specify source_importpath instead of this parameter.
source_importpath: the importpath for the source file. Alternative to passing library, which can lead to circular dependencies between mock and library targets. Only valid for source mode.
source: a Go file in the given `library`. If this is given, `gomock` will call mockgen in source mode to mock all interfaces in the file.
interfaces: a list of interfaces in the given `library` to be mocked in reflective mode.
package: the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See [mockgen's -package](https://github.com/golang/mock#flags) for more information.
Expand All @@ -187,7 +187,7 @@ def gomock(name, out, library = None, importpath = "", source = None, interfaces
name = name,
out = out,
library = library,
importpath = importpath,
source_importpath = source_importpath,
source = source,
package = package,
self_package = self_package,
Expand Down
2 changes: 1 addition & 1 deletion tests/extras/gomock/source_with_importpath/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go_library(
gomock(
name = "mocks",
out = "client_mock.go",
importpath = "github.com/bazelbuild/rules_go/gomock/client",
source_importpath = "github.com/bazelbuild/rules_go/gomock/client",
package = "client",
source = "client.go",
visibility = ["//visibility:public"],
Expand Down

0 comments on commit 6e67e3f

Please sign in to comment.