-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[6.2.0] Add native.module_{name,version} #17883
Conversation
Extension authors often want to write some macro and change its behavior depending on which module is using it. For example, for rules_go, they want to look at the `go_deps` tags in a certain module and only allow access to repos generated from those tags. We do this by introducing two new methods on `native`, callable only during the loading phase. They return the name and version of the module associated with the current repo. If the repo is from WORKSPACE, they return `None`. If the repo is generated by an extension, they return info about the module hosting the extension. The implementation works by storing the "associated module" information in `RepositoryMappingValue`. I had attempted to store them in `BzlmodRepoRuleValue` or even `RepositoryDirectoryValue`, but those are not the right places since they might happen before we even evaluate the MODULE.bazel file (i.e. for non-registry overrides). Fixes #17652. RELNOTES: Added `native.module_name()` and `native.module_version()` to allow BUILD macro authors to acquire information about which Bazel module the current repo is associated with. PiperOrigin-RevId: 518849334 Change-Id: I06b4bc95b5a57de2412ee02544240b054c708165
Hi @Wyverald could you help with this cherrypick please? Unless I'm completely off, it seems like there's another commit that should have been cherrypicked into 6.2 before this one? There are a lot of issues in RepositoryMappingFunction ( I attempted a bunch of stuff to play around and fix the failures, but please feel free to just create a new one at this point. :) |
Sorry, there are indeed a couple of previous commits that also need to be cherry-picked. I sent #17893 instead |
Extension authors often want to write some macro and change its behavior depending on which module is using it. For example, for rules_go, they want to look at the
go_deps
tags in a certain module and only allow access to repos generated from those tags.We do this by introducing two new methods on
native
, callable only during the loading phase. They return the name and version of the module associated with the current repo. If the repo is from WORKSPACE, they returnNone
. If the repo is generated by an extension, they return info about the module hosting the extension.The implementation works by storing the "associated module" information in
RepositoryMappingValue
. I had attempted to store them inBzlmodRepoRuleValue
or evenRepositoryDirectoryValue
, but those are not the right places since they might happen before we even evaluate the MODULE.bazel file (i.e. for non-registry overrides).Commit: bcf309b
RELNOTES: Added
native.module_name()
andnative.module_version()
to allow BUILD macro authors to acquire information about which Bazel module the current repo is associated with.PiperOrigin-RevId: 518849334
Change-Id: I06b4bc95b5a57de2412ee02544240b054c708165