buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

Add a buildifier warning to enforce rule load location

Open styurin opened this issue 1 year ago • 11 comments

Addresses https://github.com/bazelbuild/buildtools/issues/1231, but without auto fixing.

styurin avatar Dec 17 '24 01:12 styurin

@vladmos could you take a look, please?

styurin avatar Jan 10 '25 22:01 styurin

Is it actually recommended anywhere that genrule should be loaded from "//:genrule.bzl"? Imo it can be confusing for the users who have a different setup in their codebase.

Also, please fix the merge conflict.

vladmos avatar Jan 14 '25 12:01 vladmos

Is it actually recommended anywhere that genrule should be loaded from "//:genrule.bzl"? Imo it can be confusing for the users who have a different setup in their codebase.

Updated to use "//tools/bazel:genrule.bzl" instead. This should promote better practices to structure folders with Bazel libraries.

styurin avatar Jan 15 '25 21:01 styurin

@vladmos could you take another look, please?

styurin avatar Jan 30 '25 18:01 styurin

I'm sorry, I still don't understand where the recommendation come from. If that's been discussed e.g. in a mailing list, could you please attach a link? I can imagine that some smaller projects have their own code structure and enforcing a fixed load location without apparent upsides can be noisy. Besides, isn't "genrule" a built-in function that doesn't need to be loaded at all?

vladmos avatar Jan 31 '25 16:01 vladmos

There is no such recommendation and it wasn't discussed. There is an issue that describes the problem: https://github.com/bazelbuild/buildtools/issues/1231

The location of rules is organization-specific and depends on how source code is organized in a given organization. I don't want to provide any recommendations and this PR is not about that. However I'd like to avoid bad examples, so I changed the example location to avoid promoting a practice of keeping bazel rules at the root of a repository.

I'd rather avoid discussing recommendations of any kids in this PR. The purpose of this change it give users a way to enforce their custom rules.

styurin avatar Feb 04 '25 20:02 styurin

@vladmos any other questions? Can this be merged in?

styurin avatar Mar 11 '25 17:03 styurin

@pmbethe09 @oreflow could you take a look, please?

styurin avatar Mar 17 '25 17:03 styurin

@pmbethe09 @oreflow could you take a look, please?

@vladmos PTAL since you were on the thread/discussion already

oreflow avatar Mar 18 '25 07:03 oreflow

@oreflow it's been a while since @vladmos asked the questions and hasn't followed up since then. It doesn't seem the concerns were critical and were about recommendations, which this PR doesn't make - it only provides examples. At the same time this feature can be useful for many companies to enforce their own wrappers for build rules and it would be great to add it.

styurin avatar Mar 28 '25 03:03 styurin

@oreflow very gentle ping on this. I'd love to see this merged so I don't have to carry a patch for buildifier. Bazel users outside of Google often need a way to enforce the use of "blessed" load locations containing custom rules or macros. A configurable buildifier check is just what I would have needed a few times in the past.

malt3 avatar Aug 08 '25 14:08 malt3