'Limit visibility for targets of a subpackage to only that subpackage

In our mono-repo we have a directory called wild_west, were people are allowed to submit any code they want without code review. It's great for one-off tests and experimentatal code that is still worth keeping checked into git.

Developers are not allowed to depend on anything from wild_west in the rest of the code-base.

Is there a way to enforce that with bazel?

The only way I can think of currently is to require that all targets under //wild_west must add visibility = ["//wild_west:__subpackages__"]. However, this would not prevent people from simply making targets public. I would ideally like to be able to apply some sort of "maximum visibility scope" for all targets under wild_west so they can't be visible outside of wild_west.

Is this possible?

Alternatively, maybe there is a robust way to add a check in our CI for this?

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source