jmhodges / bazel_gomock

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

Propagate self_package argument in source mode #28

Closed josmad closed 4 years ago

josmad commented 4 years ago

Some of my packages generates mocks from unexported interfaces (requires source mode) and use the mocks for tests. Propagating self_package is necessary to avoid errors like

compilepkg: missing strict dependencies:
    /private/var/tmp/_bazel_jonasmadsen/b6feb8b4f869c974f13ffe3a805e2c01/sandbox/darwin-sandbox/75/execroot/__main__/bazel-out/darwin-fastbuild/bin/src/github.com/josmad/go_samples/mock_test/mocks.
go: import of "github.com/josmad/go_samples/mock_test"
No dependencies were provided.
jmhodges commented 4 years ago

Could you post the build target you're using this in? I'm trying to figure out how this and #26 are operating differently

josmad commented 4 years ago

As far as I can tell, the other PR extracts the package name of the mock from the fully qualified package name provided in the self_package option. This PR propagates the self_package option in source mode. The Bazel plugin already propagated the self_package option in reflect mode, I guess the author of the original PR forgot to add it for source mode.

Bazel gomock stanza:

gomock(
    name = "private_mocks",
    out = "mocks.go",
    interfaces = [
        "test",
    ],
    library = ":go_default_library",
    package = "mock_test",
    self_package = "github.com/josmad/go_samples/mock_test",
    source = "sample.go",
)