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

Why _go_proto_link rule is not executable? #12

Open
idlebot opened this issue Jul 18, 2023 · 0 comments
Open

Why _go_proto_link rule is not executable? #12

idlebot opened this issue Jul 18, 2023 · 0 comments

Comments

@idlebot
Copy link

idlebot commented Jul 18, 2023

Instead of calling native.sh_binary in def go_proto_link why not just add executable = True to _go_proto_link?

We currently have a rule that is a rule runner, in other words, is capable of aggregating multiple rules in a single bazel run //:copy_protos target, that in turn invokes all go_proto_link rules in the repo.

Something like:

rule_runner(
    name = "copy_proto",
    targets = [
        "//common/v1:commonv1_go_proto_link_copy_gen",
        "//api/v1alpha:apiv1alpha_go_proto_link_copy_gen",
    ],
)

Because of this extra level of indirection using native.sh_binary, I have to create the targets in my rule by appending _copy_gen, for my rule to work.

proto.bzl could be just:

load("//:golink.bzl", "gen_copy_files_script")

def go_proto_link_impl(ctx, **kwargs):
    return gen_copy_files_script(ctx, ctx.attr.dep[OutputGroupInfo].go_generated_srcs.to_list())

_go_proto_link = rule(
    implementation = go_proto_link_impl,
    attrs = {
        "dir": attr.string(),
        "dep": attr.label(),
        "_template": attr.label(
            default = "//:copy_into_workspace.sh",
            allow_single_file = True,
        ),
        # It is not used, just used for versioning since this is experimental
        "version": attr.string(),
    },
    executable = True,
)

def go_proto_link(**kwargs):
    if not "dir" in kwargs:
        dir = native.package_name()
        kwargs["dir"] = dir

    _go_proto_link(**kwargs)
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

No branches or pull requests

1 participant