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

Ensure lockfile is updated after reset to pre-build state #19343

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public static BazelModuleResolutionEvent create(

public abstract ImmutableTable<ModuleExtensionId, ModuleKey, ModuleExtensionUsage>
getExtensionUsagesById();

@Override
public boolean storeForReplay() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ public static ModuleExtensionResolutionEvent create(
public abstract ModuleExtensionId getExtensionId();

public abstract LockFileModuleExtension getModuleExtension();

@Override
public boolean storeForReplay() {
return true;
}
}
40 changes: 40 additions & 0 deletions src/test/py/bazel/bzlmod/bazel_lockfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,46 @@ def testExtensionEvaluationDoesNotRerunOnChangedImports(self):
stderr,
)

def testLockfileRecreatedAfterDeletion(self):
self.ScratchFile(
'MODULE.bazel',
[
'lockfile_ext = use_extension("extension.bzl", "lockfile_ext")',
'use_repo(lockfile_ext, "hello")',
],
)
self.ScratchFile('BUILD.bazel')
self.ScratchFile(
'extension.bzl',
[
'def _repo_rule_impl(ctx):',
' ctx.file("WORKSPACE")',
' ctx.file("BUILD", "filegroup(name=\'lala\')")',
'',
'repo_rule = repository_rule(implementation=_repo_rule_impl)',
'',
'def _module_ext_impl(ctx):',
' repo_rule(name="hello")',
'',
'lockfile_ext = module_extension(',
' implementation=_module_ext_impl,',
')',
],
)

_, _, _ = self.RunBazel(['build', '@hello//:all'])
Copy link
Contributor

@SalmaSamy SalmaSamy Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this part: _, _, _ =

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure whether this would trigger a linter. Feel free to remove on import (or let me know that I should drop it here).


# Return the lockfile to the state it had before the previous build: it didn't exist.
with open('MODULE.bazel.lock', 'r') as lock_file:
old_data = lock_file.read()
os.remove('MODULE.bazel.lock')

_, _, _ = self.RunBazel(['build', '@hello//:all'])

with open('MODULE.bazel.lock', 'r') as lock_file:
new_data = lock_file.read()

self.assertEqual(old_data, new_data)

if __name__ == '__main__':
unittest.main()
Loading