Skip to content

Commit

Permalink
Ensure lockfile is updated after reset to pre-build state
Browse files Browse the repository at this point in the history
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 bazelbuild#19343.

PiperOrigin-RevId: 561287438
Change-Id: I549f99b896a0095e8ffc35b7bacc8a841a44219a
  • Loading branch information
SalmaSamy authored and copybara-github committed Aug 30, 2023
1 parent aa55c4d commit 19c0c80
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
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;
}
}
42 changes: 42 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,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()

0 comments on commit 19c0c80

Please sign in to comment.