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 wrappers #18

Open
jayconrod opened this issue Dec 7, 2017 · 7 comments
Open

Allow wrappers #18

jayconrod opened this issue Dec 7, 2017 · 7 comments

Comments

@jayconrod
Copy link
Contributor

Migrated from bazel-contrib/rules_go#748

Allow people to mark rules as a wrapper for a go rule, so they can be managed by gazelle as if the were the underlying rule.
It would be even nicer if you could do this once for an entire rule type rather than per rule. The original example was bazelbuild/rules_docker#119 where go_image is a proxy for go_binary as far as gazelle should be concerned.

@achew22
Copy link
Member

achew22 commented Dec 7, 2017

This would also be useful for bazel-integration-testing's bazel_go_integration_test

@AFMiziara
Copy link

This would be very useful also to allow gazelle to generate predefined go_image and container_push targets from rules_docker together with go_binary, instead of having to manually write those.

Any ideas on how to do that? Where to start? I would love to help.

@achew22
Copy link
Member

achew22 commented Apr 22, 2021

Have you tried

# gazelle:map_kind go_binary go_image @io_bazel_rules_docker//go:image.bzl

I've been using this in my repo for a long time to great success. Where it would have generated a go_binary it generates a go_image imported from @io_bazel_rules_docker//go:image.bzl.

@AFMiziara
Copy link

@achew22 I didn't now about that. Worked here, thanks a lot.

About container_push, do you know if there is a similar approach or for that case we have to manually write on all targets?

@achew22
Copy link
Member

achew22 commented Apr 22, 2021

What would the container_push wrap? If you want one next to every go_image you could make a macro that has the rules_docker go_image in addition to a container_push and then you'd get it at the same time. That said, macros that silently create resources that you probably want to run are suboptimal from a usability standpoint. It's very nice to be able to see all the targets that you care about explicitly listed in a BUILD.

You could pretty easily put together a Gazelle plugin to create a container_push automatically for every *_image that it finds.

@AFMiziara
Copy link

Thanks. Yes, that was my goal: to have container_push next to each go_image. I will try to write a Gazelle plugin. If I succeed I will post here. It might be useful, because I didn't find anything similar to that atm.

@achew22
Copy link
Member

achew22 commented Apr 23, 2021

If you're looking for some inspiration, there are a couple of simple plugins that are pretty easy to work through. The easiest is one that makes a filegroup for every file in the repo[0]. A slightly more involved one is the xlang[1] that you can use as a sample as well.

[0] https://github.com/bazelbuild/bazel-gazelle/blob/master/internal/language/test_filegroup/lang.go
[1] https://github.com/bazelbuild/bazel-gazelle/blob/master/internal/gazellebinarytest/xlang.go

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

No branches or pull requests

3 participants