Skip to content

Commit

Permalink
[6.4.0] Ensure lockfile is updated after reset to pre-build state (#1…
Browse files Browse the repository at this point in the history
…9371)

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.

Commit
19c0c80

PiperOrigin-RevId: 561287438
Change-Id: I549f99b896a0095e8ffc35b7bacc8a841a44219a

Co-authored-by: Salma Samy <salmasamy@google.com>
  • Loading branch information
iancha1992 and SalmaSamy authored Aug 31, 2023
1 parent cac82a0 commit 038d973
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 @@ -861,5 +861,47 @@ 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 038d973

Please sign in to comment.