jmhodges / bazel_gomock

Code to create Go mocks for bazel targets using mockgen
MIT License
59 stars 29 forks source link

setting default output file name #25

Open linzhp opened 5 years ago

linzhp commented 5 years ago

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.

jmhodges commented 4 years ago

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 commented 4 years ago

Do you have any ideas on how to solve that?

linzhp commented 4 years ago

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",
    ],
)
jmhodges commented 4 years ago

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

linzhp commented 4 years ago

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