jmhodges / bazel_gomock

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

Gazelle deletes grpc dependencies if put mock in a go_library. Possible output mock file in directory instead of bazel-in? #57

Open toyokaku opened 3 years ago

toyokaku commented 3 years ago
go_library(
    name = "server",
    srcs = [
        "server.go",
        ":hello_go_mock",
    ],
    importpath = "depot/codelab/hello/server",
    visibility = ["//visibility:public"],
    deps = [
        "//codelab/proto/hello",
        "@com_github_golang_mock//gomock",
        "@org_golang_google_grpc//:go_default_library",
    ],
)

gomock(
    name = "hello_go_mock",
    out = "hello_mock.go",
    interfaces = [
        "HelloClient",
        "HelloServer",
    ],
    library = "//codelab/proto/hello",
    package = "server",
)

other package needs this mock so I put it in go_library However after bazel run //:gazelle

go_library(
    name = "server",
    srcs = [
        "server.go",
        ":hello_go_mock",
    ],
    importpath = "depot/codelab/hello/server",
    visibility = ["//visibility:public"],
    deps = ["//codelab/proto/hello"],
)

gomock(
...
)

deps are gone and tests will fail I have to put # gazelle: ignore in the BUILD file that contains gomock()

Any option to generate file in the directory instead of bazel-bin?

jmhodges commented 2 years ago

Hm, I wonder if there's a way for bazel_gomock to convince gazelle to leave this alone without special casing. Generating a file to go into source hasn't, in the past, been the Bazel Go Way.