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

[6.2.0]Add native.module_{name,version} #17873

Closed

Conversation

ShreeM01
Copy link
Contributor

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

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 bazelbuild#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
@sgowroji sgowroji added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Mar 24, 2023
@ShreeM01 ShreeM01 closed this Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants