Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow us to override srcs in config using go tempate with the build rule #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

goddenrich
Copy link
Contributor

This is a potential approch to being able to deal with some more unusual build defs which generate go related targets. eg it allows us to define a srcs argument which the underlying build def uses when inputting to a known type. One example is

    mock_srcs_out = "%s.mock.go" % name
    mock_srcs = genrule(
        name = f"_{name}#mock_srcs",
        outs = [mock_srcs_out],
        cmd = f"$TOOLS_MOCKGEN -exec_only $TOOLS_REFLECT_PROGRAM -package {name} {package} {interfaces} > {mock_srcs_out}",
        labels = ["codegen"],
        test_only = True,
        tools = {
            "MOCKGEN": ["///third_party/go/go.uber.org_mock//mockgen"],
            "REFLECT_PROGRAM": [reflect_program],
        },
        deps = [
            reflect_program,
        ],
    )

    go_library(
        name = name,
        srcs = [mock_srcs],
        package = name,
        test_only = True,
        visibility = visibility,
        deps = [
            # Depend on the original lib since the mock files reference the original pkg.
            src_lib,
            "///third_party/go/go.uber.org_mock//gomock",
        ] + deps,
    )

and this allows us to define in config something which will make the srcs and therefore deps evaluate correctly

    "go_mock": {
      "providedDeps": ["///third_party/go/go.uber.org_mock//gomock"],
      "srcsRuleTemplate": "[\":_{{.Name}}#mock_srcs\"]"
    },

Copy link
Collaborator

@Tatskaari Tatskaari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM though we should update the example to explain how/when to use this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants