Skip to content

Commit

Permalink
[7.1.0] Fix vendor existing repo (bazelbuild#21487)
Browse files Browse the repository at this point in the history
If a repo is already vendored & up-to-date, we shouldn't vendor it
again. As it may not exist under the external cache and this causes
vendoring to fail.

PiperOrigin-RevId: 609728367
Change-Id: I5d0df83f254e860110a734270e25f8ce2193e437
  • Loading branch information
SalmaSamy committed Feb 23, 2024
1 parent 4ddd2ae commit 697baf4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ private BlazeCommandResult vendorRepos(
for (Entry<RepositoryName, RepositoryDirectoryValue> entry :
repositoryNamesAndValues.entrySet()) {
if (entry.getValue().repositoryExists()) {
reposToVendor.add(entry.getKey());
if (!entry.getValue().excludeFromVendoring()) {
reposToVendor.add(entry.getKey());
}
} else {
notFoundRepoErrors.add(entry.getValue().getErrorMsg());
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/py/bazel/bzlmod/bazel_vendor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,28 @@ def testVendorRepo(self):
self.assertIn('ccc~', repos_vendored)
self.assertNotIn('aaa~', repos_vendored)

def testVendorExistingRepo(self):
self.main_registry.createCcModule('aaa', '1.0')
self.ScratchFile(
'MODULE.bazel',
[
'bazel_dep(name = "aaa", version = "1.0", repo_name = "my_repo")',
'local_path_override(module_name="bazel_tools", path="tools_mock")',
'local_path_override(module_name="local_config_platform", ',
'path="platforms_mock")',
],
)
self.ScratchFile('BUILD')
# Test canonical/apparent repo names & multiple repos
self.RunBazel(['vendor', '--vendor_dir=vendor', '--repo=@my_repo'])
self.assertIn('aaa~', os.listdir(self._test_cwd + '/vendor'))

# Delete repo from external cache
self.RunBazel(['clean', '--expunge'])
# Vendoring again should find that it is already up-to-date and exclude it
# from vendoring not fail
self.RunBazel(['vendor', '--vendor_dir=vendor', '--repo=@my_repo'])

def testVendorInvalidRepo(self):
# Invalid repo name (not canonical or apparent)
exit_code, _, stderr = self.RunBazel(
Expand Down

0 comments on commit 697baf4

Please sign in to comment.