Created
May 30, 2024 12:09
-
-
Save ewhauser/65c867d9f7c1d7fb2cfe154524d91057 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") | |
load("@bazel_skylib//lib:paths.bzl", "paths") | |
load("@io_bazel_rules_go//go:def.bzl", "gomock") | |
_MOCKGEN_TOOL = Label("@org_uber_go_mock//mockgen") | |
_MOCKGEN_MODEL_LIB = Label("@org_uber_go_mock//mockgen/model") | |
def go_mock(name, deps, interfaces = [], **kwargs): | |
""" | |
Macro to create a Go mock of a given interface(s) and copy the file back | |
to the source tree using our copy conventions. | |
""" | |
kwargs["mockgen_model_library"] = "@org_uber_go_mock//mockgen/model" | |
gomock( | |
name = "mock_" + name, | |
out = "mock_" + name + ".go.tpl", | |
interfaces = interfaces, | |
library = deps, | |
mockgen_tool = _MOCKGEN_TOOL, | |
package = paths.basename(native.package_name()), | |
self_package = paths.join("github.com/cadencerpm/monorepo", native.package_name()), | |
**kwargs | |
) | |
write_source_files( | |
name = "mock_" + name + ".update", | |
files = { | |
name + ".generated.go": ":mock_" + name, | |
}, | |
suggested_update_target = "//tools:codegen", | |
visibility = ["//tools:__subpackages__"], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment