Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
add self_package option (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
tony84727 authored and jmhodges committed Mar 23, 2019
1 parent 9199dba commit 08cc809
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gomock.bzl
Expand Up @@ -43,6 +43,9 @@ _gomock_source = go_rule(
"package": attr.string(
doc = "The name of the package the generated mocks should be in. If not specified, uses mockgen's default.",
),
"self_package": attr.string(
doc = "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.",
),
"gopath_dep": attr.label(
doc = "The go_path label to use to create the GOPATH for the given library. Will be set correctly by the gomock macro, so you don't need to set it.",
providers = [GoPath],
Expand Down Expand Up @@ -116,6 +119,7 @@ def _gomock_reflect(name, library, out, mockgen_tool, **kwargs):
out = out,
prog_bin = prog_bin,
mockgen_tool = mockgen_tool,
self_package = kwargs.get("self_package", None),
)

def _gomock_prog_gen_impl(ctx):
Expand Down Expand Up @@ -175,6 +179,9 @@ def _gomock_prog_exec_impl(ctx):
if ctx.attr.package != "":
args += ["-package", ctx.attr.package]

if ctx.attr.self_package != "":
args += ["-self_package", ctx.attr.self_package]

args += [ctx.attr.library[GoLibrary].importpath]
args += [",".join(ctx.attr.interfaces)]

Expand Down Expand Up @@ -209,6 +216,9 @@ _gomock_prog_exec = go_rule(
"package": attr.string(
doc = "The name of the package the generated mocks should be in. If not specified, uses mockgen's default.",
),
"self_package": attr.string(
doc = "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.",
),
"prog_bin": attr.label(
doc = "The program binary generated by mockgen's -prog_only and compiled by bazel.",
allow_single_file = True,
Expand Down

0 comments on commit 08cc809

Please sign in to comment.