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

Can gazelle generate go_tool_library? #747

Closed
prestonvanloon opened this issue Apr 3, 2020 · 5 comments
Closed

Can gazelle generate go_tool_library? #747

prestonvanloon opened this issue Apr 3, 2020 · 5 comments

Comments

@prestonvanloon
Copy link

What version of gazelle are you using?

0.22.0

What version of rules_go are you using?

0.22.2

What version of Bazel are you using?

2.1.1

Does this issue reproduce with the latest releases of all the above?

N/A

What operating system and processor architecture are you using?

linux amd64

What did you do?

I'm trying to use github.com/securego/gosec as a third_party dependency via workspace go_repository in a go_tool_library analyzer. The problem I have is that gazelle only generates the go_default_library's which cause a dependency loop on nogo.

My question is: is there a way to direct gazelle to generate go_tool_library in addition to go_default_library?

What did you expect to see?

N/A

What did you see instead?

N/A

@achew22
Copy link
Member

achew22 commented Apr 3, 2020

Can you use

# gazelle:map_kind from_kind to_kind to_kind_load

and map it to a go_tool_library directly? If you need both a go_tool_library and a go_library you could make a macro that creates both of those and map the to_kind to the macro.

@prestonvanloon
Copy link
Author

Where would I put that directive? I tried this

go_repository(
    name = "com_github_securego_gosec",
    importpath = "github.com/securego/gosec",
    sum = "h1:rq2/kILQnPtq5oL4+IAjgVOjh5e2yj2aaCYi7squEvI=",
    version = "v0.0.0-20200401082031-e946c8c39989",
    # gazelle:map_kind go_library go_tool_library @io_bazel_rules_go//go:def.bzl
)

But it seems the rules are still go_library.

bazel query @com_github_securego_gosec//... --output=label_kind
go_test rule @com_github_securego_gosec//rules:go_default_test
go_test rule @com_github_securego_gosec//output:go_default_test
go_binary rule @com_github_securego_gosec//cmd/tlsconfig:tlsconfig
go_library rule @com_github_securego_gosec//cmd/tlsconfig:go_default_library
go_binary rule @com_github_securego_gosec//cmd/gosecutil:gosecutil
go_library rule @com_github_securego_gosec//cmd/gosecutil:go_default_library
go_binary rule @com_github_securego_gosec//cmd/gosec:gosec
go_library rule @com_github_securego_gosec//cmd/gosec:go_default_library
go_library rule @com_github_securego_gosec//output:go_default_library
go_test rule @com_github_securego_gosec//:go_default_test
go_library rule @com_github_securego_gosec//testutils:go_default_library
go_library rule @com_github_securego_gosec//rules:go_default_library
go_library rule @com_github_securego_gosec//:go_default_library

@achew22
Copy link
Member

achew22 commented Apr 3, 2020

I'm terribly sorry, I didn't understand something about this. Let me revise.

In go_repository there is a parameter called build_extra_args. I was expecting you would be able to use a flag to include that directive, but now that I am reading the docs it doesn't look like that's possible.

@jayconrod do you have any idea on the next way direction to go here? Is the correct move to use patch to replace or to add a flag to gazelle allowing you to pass in directives?

@jayconrod
Copy link
Contributor

go_repository has an attribute build_directives that you can use to pass in a list of directives. Gazelle will act as if they were in the root build file when running. That's probably the way to go here.

Gazelle won't support go_tool_library though. I'd like to get rid of go_tool_library (bazel-contrib/rules_go#2374). nogo should be able to depend on regular go_library targets that are built in a configuration that doesn't use nogo. That would eliminate the circular dependency without needing the repetition we currently have.

Closing this issue just to say this won't be supported. Happy to continue discussion though.

@prestonvanloon
Copy link
Author

Thanks @jayconrod. Looking forward to your transitional rules rewrite!

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

3 participants