Skip to content

Commit 19c0c80

Browse files
SalmaSamycopybara-github
authored andcommitted
Ensure lockfile is updated after reset to pre-build state
The events that update the lockfile are important for incremental correctness and thus need to return `true` from `storeForReplay`. Before this change, if a build creates the lockfile because it didn't exist and the lockfile is then deleted, subsequent builds did not regenerate it as the relevant SkyFunctions wouldn't rerun and the events were not replayed. Closes #19343. PiperOrigin-RevId: 561287438 Change-Id: I549f99b896a0095e8ffc35b7bacc8a841a44219a
1 parent aa55c4d commit 19c0c80

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionEvent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ public static BazelModuleResolutionEvent create(
3636

3737
public abstract ImmutableTable<ModuleExtensionId, ModuleKey, ModuleExtensionUsage>
3838
getExtensionUsagesById();
39+
40+
@Override
41+
public boolean storeForReplay() {
42+
return true;
43+
}
3944
}

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionEvent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ public static ModuleExtensionResolutionEvent create(
3333
public abstract ModuleExtensionId getExtensionId();
3434

3535
public abstract LockFileModuleExtension getModuleExtension();
36+
37+
@Override
38+
public boolean storeForReplay() {
39+
return true;
40+
}
3641
}

src/test/py/bazel/bzlmod/bazel_lockfile_test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,48 @@ def testExtensionEvaluationDoesNotRerunOnChangedImports(self):
964964
stderr,
965965
)
966966

967+
def testLockfileRecreatedAfterDeletion(self):
968+
self.ScratchFile(
969+
'MODULE.bazel',
970+
[
971+
'lockfile_ext = use_extension("extension.bzl", "lockfile_ext")',
972+
'use_repo(lockfile_ext, "hello")',
973+
],
974+
)
975+
self.ScratchFile('BUILD.bazel')
976+
self.ScratchFile(
977+
'extension.bzl',
978+
[
979+
'def _repo_rule_impl(ctx):',
980+
' ctx.file("WORKSPACE")',
981+
' ctx.file("BUILD", "filegroup(name=\'lala\')")',
982+
'',
983+
'repo_rule = repository_rule(implementation=_repo_rule_impl)',
984+
'',
985+
'def _module_ext_impl(ctx):',
986+
' repo_rule(name="hello")',
987+
'',
988+
'lockfile_ext = module_extension(',
989+
' implementation=_module_ext_impl,',
990+
')',
991+
],
992+
)
993+
994+
self.RunBazel(['build', '@hello//:all'])
995+
996+
# Return the lockfile to the state it had before the
997+
# previous build: it didn't exist.
998+
with open('MODULE.bazel.lock', 'r') as lock_file:
999+
old_data = lock_file.read()
1000+
os.remove('MODULE.bazel.lock')
1001+
1002+
self.RunBazel(['build', '@hello//:all'])
1003+
1004+
with open('MODULE.bazel.lock', 'r') as lock_file:
1005+
new_data = lock_file.read()
1006+
1007+
self.assertEqual(old_data, new_data)
1008+
9671009

9681010
if __name__ == '__main__':
9691011
unittest.main()

0 commit comments

Comments
 (0)