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} #17883

Closed
wants to merge 7 commits into from
Closed

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

wants to merge 7 commits into from

Conversation

keertk
Copy link
Member

@keertk keertk commented Mar 24, 2023

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).

Commit: bcf309b

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 #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
@keertk keertk requested a review from ShreeM01 as a code owner March 24, 2023 21:33
@keertk keertk removed the request for review from ShreeM01 March 24, 2023 21:33
@keertk
Copy link
Member Author

keertk commented Mar 24, 2023

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 (bazelModuleResolutionValue vs bazelDepGraphValue) and BzlmodRepoRuleFunctionTest even after resolving merge conflicts.

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. :)

@keertk keertk added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Mar 24, 2023
@keertk keertk added the awaiting-review PR is awaiting review from an assigned reviewer label Mar 25, 2023
@Wyverald
Copy link
Member

Sorry, there are indeed a couple of previous commits that also need to be cherry-picked. I sent #17893 instead

@Wyverald Wyverald closed this Mar 27, 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.

2 participants