diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionEvent.java index 81a0dbaa144b9c..b2e0f6f3a5b40f 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionEvent.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionEvent.java @@ -36,4 +36,9 @@ public static BazelModuleResolutionEvent create( public abstract ImmutableTable getExtensionUsagesById(); + + @Override + public boolean storeForReplay() { + return true; + } } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionEvent.java index 4013e7bb4c5965..cb82ae039f08fe 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionEvent.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionEvent.java @@ -33,4 +33,9 @@ public static ModuleExtensionResolutionEvent create( public abstract ModuleExtensionId getExtensionId(); public abstract LockFileModuleExtension getModuleExtension(); + + @Override + public boolean storeForReplay() { + return true; + } } diff --git a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py index 102ad544f397a0..b90283e387a48d 100644 --- a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py +++ b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py @@ -964,6 +964,48 @@ 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']) + + # 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()