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 56fc099 commit 83c87c3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 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
56 changes: 56 additions & 0 deletions src/test/py/bazel/bzlmod/bazel_lockfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,62 @@ def testModuleExtensionRerunsOnGetenvChanges(self):
stderr = '\n'.join(stderr)
self.assertIn('LAZYEVAL_KEY=None', stderr)

def testModuleExtensionRerunsOnUniqueNameChange(self):
self.ScratchFile(
'MODULE.bazel',
[
'my_ext_1 = use_extension("//:ext1.bzl","my_ext")',
'use_repo(my_ext_1, "foo")',
],
)
self.ScratchFile('BUILD.bazel')
self.ScratchFile(
'ext1.bzl',
[
'def _my_repo_impl(ctx):',
' ctx.file("REPO.bazel")',
' ctx.file("BUILD")',
' ctx.file("hi.txt", "hi")',
' if ctx.attr.label:',
' print("label: {}".format(ctx.attr.label))',
'my_repo = repository_rule(',
' implementation=_my_repo_impl,',
' attrs={"label": attr.label()}',
')',
'def _my_ext_impl(ctx):',
' my_repo(name="foo",label="@bar")',
' my_repo(name="bar")',
'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 = '\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__':
absltest.main()

0 comments on commit 83c87c3

Please sign in to comment.