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.

Closes bazelbuild#23527.

PiperOrigin-RevId: 672480631
Change-Id: Ib2ef0edb6b6c90a7336085da20e2794a93763182
  • Loading branch information
fmeum authored and iancha1992 committed Sep 11, 2024
1 parent 9e3fa2a commit d80ae7e
Show file tree
Hide file tree
Showing 3 changed files with 741 additions and 687 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,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 @@ -2602,6 +2602,62 @@ def testLockFileVersionIsCorrectWithUsePlusFlag(self):
self.RunBazel(['clean', '--expunge'])
self.RunBazel(['mod', 'graph', '--incompatible_use_plus_in_repo_names',
'--lockfile_mode=error'])

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__':
Expand Down
Loading

0 comments on commit d80ae7e

Please sign in to comment.