Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make it possible to extend default_visibility for targets in a macro instead of override it #25314

Open
dgoldstein0 opened this issue Feb 18, 2025 · 0 comments
Labels
team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob type: feature request untriaged

Comments

@dgoldstein0
Copy link

Description of the feature request:

Today, if you want targets within a macro to always be visible to certain other targets, you can't also inherit default visibility.

Which category does this issue belong to?

Loading API

What underlying problem are you trying to solve with this feature?

E.g. consider a macro like

def foo(name, visibility = None, **kw):
  _foo(name=name, visibility=visibility, **kw)

now suppose I want the targets created by foo() to always be visible to "//bar:__subpackages__" - regardless of default_visibility. I can write

def foo(name, visibility = None, **kw):
  _foo(name=name, visibility=(visibility if visibility else []) + ["//bar:__subpackages__"], **kw)

but this means that the following:

package(default_visibility = ["//baz:__pkg__"])
load(...)

foo(name="my_target")

:my_target won't be visible to //baz:__pkg__ anymore, as the added visibility means we can't pass visibility=None and the default_visibility will then be ignored.

Today this has to be manually handled by BUILD file authors or by BUILD file generators.

If bazel included a builtin function that could return the default visibility, e.g. native.package_default_visibility(), the macro could call that and use that:

def foo(name, visibility = None, **kw):
  _foo(name=name, visibility=(visibility if visibility else native.package_default_visibility()) + ["//bar:__subpackages__"], **kw)

which would get us the best of both worlds - macros could opt in to mutate visibility while also honoring default_visibility, without pushing the problem onto BUILD file authors or generators.

Which operating system are you running Bazel on?

linux

What is the output of bazel info release?

release 6.5.0-b940786cac09f826f5b96eaba2ff36784ad4869d

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?


Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@sgowroji sgowroji added the team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob label Feb 19, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
team-Loading-API BUILD file and macro processing: labels, package(), visibility, glob type: feature request untriaged
Projects
None yet
Development

No branches or pull requests

4 participants