bazel_gomock icon indicating copy to clipboard operation
bazel_gomock copied to clipboard

setting default output file name

Open linzhp opened this issue 4 years ago • 5 comments

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.

linzhp avatar Sep 22 '19 16:09 linzhp

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.

jmhodges avatar Nov 01 '19 04:11 jmhodges

Do you have any ideas on how to solve that?

jmhodges avatar Nov 01 '19 04:11 jmhodges

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",
    ],
)

linzhp avatar Nov 01 '19 05:11 linzhp

Right! If we can get a README update in this patch, that'd be cool!

jmhodges avatar Nov 01 '19 09:11 jmhodges

@jmhodges I updated the README. Can you take another look?

linzhp avatar Jan 07 '20 22:01 linzhp