Skip to content
Merged
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
59 changes: 59 additions & 0 deletions src/test/py/bazel/bzlmod/repo_contents_cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,65 @@ def testGc_multipleServers(self):
_, _, stderr = self.RunBazel(['build', '@my_repo//:haha'], cwd=dir_b)
self.assertIn('JUST FETCHED', '\n'.join(stderr))

def testReverseDependencyDirection(self):
# Set up two repos that retain their predeclared input hashes across two
# builds but still reverse their dependency direction. Depending on how
# repo cache candidates are checked, this could lead to a Skyframe cycle.
self.ScratchFile(
'MODULE.bazel',
[
'repo = use_repo_rule("//:repo.bzl", "repo")',
'repo(',
' name = "foo",',
' deps_file = "//:foo_deps.txt",',
')',
'repo(',
' name = "bar",',
' deps_file = "//:bar_deps.txt",',
')',
],
)
self.ScratchFile('BUILD.bazel')
self.ScratchFile(
'repo.bzl',
[
'def _repo_impl(rctx):',
' deps = rctx.read(rctx.attr.deps_file).splitlines()',
' output = ""',
' for dep in deps:',
' if dep:',
' output += "{}: {}\\n".format(dep, rctx.read(Label(dep)))',
' rctx.file("output.txt", output)',
' rctx.file("BUILD", "exports_files([\'output.txt\'])")',
' print("JUST FETCHED: %s" % rctx.original_name)',
' return rctx.repo_metadata(reproducible=True)',
'repo = repository_rule(',
' implementation = _repo_impl,',
' attrs = {',
' "deps_file": attr.label(), }',
')',
],
)

self.ScratchFile('foo_deps.txt', ['@bar//:output.txt'])
self.ScratchFile('bar_deps.txt', [''])

# First fetch: not cached
_, _, stderr = self.RunBazel(['build', '@foo//:output.txt'])
self.assertIn('JUST FETCHED: bar', '\n'.join(stderr))
self.assertIn('JUST FETCHED: foo', '\n'.join(stderr))

# After expunging and reversing the dependency direction: not cached
self.RunBazel(['clean', '--expunge'])
self.ScratchFile('foo_deps.txt', [''])
self.ScratchFile('bar_deps.txt', ['@foo//:output.txt'])
exit_code, stdout, stderr = self.RunBazel(
['build', '@foo//:output.txt'], allow_failure=True
)
# TODO: b/xxxxxxx - This is NOT the intended behavior.
self.AssertNotExitCode(exit_code, 0, stderr, stdout)
self.assertIn('possible dependency cycle detected', '\n'.join(stderr))


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