Skip to content

Commit

Permalink
Invalidate lockfile entry when the extension name prefix changes
Browse files Browse the repository at this point in the history
This was missed in bazelbuild#19055.
  • Loading branch information
fmeum committed Sep 5, 2024
1 parent d0f4661 commit 0822f01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ SingleExtensionUsagesValue trimForEvaluation() {
return SingleExtensionUsagesValue.create(
ImmutableMap.copyOf(
Maps.transformValues(getExtensionUsages(), ModuleExtensionUsage::trimForEvaluation)),
// extensionUniqueName: Not accessible to the extension's implementation function.
// TODO: Reconsider this when resolving #19055.
"",
getExtensionUniqueName(),
getAbridgedModules(),
// repoMappings: The usage of repo mappings by the extension's implementation function is
// tracked on the level of individual entries and all label attributes are provided as
Expand Down
31 changes: 27 additions & 4 deletions src/test/py/bazel/bzlmod/bazel_lockfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2601,8 +2601,8 @@ def testModuleExtensionRerunsOnUniqueNameChange(self):
self.ScratchFile(
'MODULE.bazel',
[
'my_ext = use_extension("//:ext1.bzl","my_ext")',
'use_repo(my_ext, "foo")'
'my_ext_1 = use_extension("//:ext1.bzl","my_ext")',
'use_repo(my_ext_1, "foo")',
],
)
self.ScratchFile('BUILD.bazel')
Expand All @@ -2625,10 +2625,33 @@ def testModuleExtensionRerunsOnUniqueNameChange(self):
'my_ext = module_extension(implementation=_my_ext_impl)',
],
)
self.ScratchFile(
'ext2.bzl',
[
'load(":ext1.bzl", "my_repo")',
'def _my_ext_impl(ctx):',
' my_repo(name="foo")',
'my_ext = module_extension(implementation=_my_ext_impl)',
]
)

_, _, stderr = self.RunBazel(['build', '@foo//:all'])
stderr = ''.join(stderr)
self.assertIn('label: foobarbaz', stderr)
stderr = '\n'.join(stderr)
self.assertIn('label: @@+my_ext+bar//:bar\n', stderr)

self.ScratchFile(
'MODULE.bazel',
[
'my_ext_2 = use_extension("//:ext2.bzl","my_ext")',
'use_repo(my_ext_2, other_foo = "foo")',
'my_ext_1 = use_extension("//:ext1.bzl","my_ext")',
'use_repo(my_ext_1, "foo")',
],
)

_, _, stderr = self.RunBazel(['build', '@foo//:all'])
stderr = '\n'.join(stderr)
self.assertIn('label: @@+my_ext2+bar//:bar\n', stderr)


if __name__ == '__main__':
Expand Down

0 comments on commit 0822f01

Please sign in to comment.