bazel_gomock
bazel_gomock copied to clipboard
setting default output file name
When the mocks are in they own package, the gomock
rule can be feeded into a go_library
rule like this:
gomock(
name = "rosetta_mock",
interfaces = ["Client"],
library = ":go_default_library",
package = "rosettamock",
out = "mocks.go",
)
go_library(
name = "go_mock_library",
srcs = [":rosetta_mock"],
importpath = "mock/go-rosetta/rosetta",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_mock//gomock:go_default_library",
],
)
In this case, the out
parameter is not necessary. Furthermore, it will cause Gazelle to add mocks.go
into go_default_library
unless we exclude it using # gazelle:exclude
explicitly. This PR sets a default value to the out
parameter, so we don't need to specify it when we don't use it directly.
Hm, I'm worried about this one because there's no way for folks to know what to include in their other targets to use this one.
Do you have any ideas on how to solve that?
The gomock rule can be feeded into a go_library rule like this:
gomock(
name = "rosetta_mock",
interfaces = ["Client"],
library = ":go_default_library",
package = "rosettamock",
)
go_library(
name = "go_mock_library",
srcs = [":rosetta_mock"],
importpath = "mock/go-rosetta/rosetta",
visibility = ["//visibility:public"],
deps = [
"@com_github_golang_mock//gomock:go_default_library",
],
)
Right! If we can get a README update in this patch, that'd be cool!
@jmhodges I updated the README. Can you take another look?