forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an HTTP registry in Bzlmod tests
This is in preparation for tracking the hashes of remote (non-`file:` URL) files in the lockfile. If the tests use local registries, they wouldn't be representative of the default situation. Work towards bazelbuild#20369 Closes bazelbuild#21906. PiperOrigin-RevId: 622290283 Change-Id: Ibe825d2bede84c1b0672dbb699aaf3ee5168a813
- Loading branch information
Showing
11 changed files
with
146 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ def setUp(self): | |
self.main_registry = BazelRegistry( | ||
os.path.join(self.registries_work_dir, 'main') | ||
) | ||
self.main_registry.start() | ||
self.main_registry.createCcModule('aaa', '1.0').createCcModule( | ||
'aaa', '1.1' | ||
).createCcModule('bbb', '1.0', {'aaa': '1.0'}).createCcModule( | ||
|
@@ -59,6 +60,10 @@ def setUp(self): | |
# deterministic? | ||
os.remove(self.Path('MODULE.bazel.lock')) | ||
|
||
def tearDown(self): | ||
self.main_registry.stop() | ||
test_base.TestBase.tearDown(self) | ||
|
||
def testChangeModuleInRegistryWithoutLockfile(self): | ||
# Add module 'sss' to the registry with dep on 'aaa' | ||
self.main_registry.createCcModule('sss', '1.3', {'aaa': '1.1'}) | ||
|
@@ -1277,66 +1282,70 @@ def testExtensionEvaluationOnlyRerunOnRelevantUsagesChanges(self): | |
|
||
def testLockfileWithNoUserSpecificPath(self): | ||
self.my_registry = BazelRegistry(os.path.join(self._test_cwd, 'registry')) | ||
self.my_registry.setModuleBasePath('projects') | ||
patch_file = self.ScratchFile( | ||
'ss.patch', | ||
[ | ||
'--- a/aaa.cc', | ||
'+++ b/aaa.cc', | ||
'@@ -1,6 +1,6 @@', | ||
' #include <stdio.h>', | ||
' #include "aaa.h"', | ||
' void hello_aaa(const std::string& caller) {', | ||
'- std::string lib_name = "[email protected]";', | ||
'+ std::string lib_name = "[email protected] (remotely patched)";', | ||
' printf("%s => %s\\n", caller.c_str(), lib_name.c_str());', | ||
' }', | ||
], | ||
) | ||
# Module with a local patch & extension | ||
self.my_registry.createCcModule( | ||
'ss', | ||
'1.3-1', | ||
{'ext': '1.0'}, | ||
patches=[patch_file], | ||
patch_strip=1, | ||
extra_module_file_contents=[ | ||
'my_ext = use_extension("@ext//:ext.bzl", "ext")', | ||
'use_repo(my_ext, "justRepo")', | ||
], | ||
) | ||
ext_src = [ | ||
'def _repo_impl(ctx): ctx.file("BUILD")', | ||
'repo = repository_rule(_repo_impl)', | ||
'def _ext_impl(ctx): repo(name=justRepo)', | ||
'ext=module_extension(_ext_impl)', | ||
] | ||
self.my_registry.createLocalPathModule('ext', '1.0', 'ext') | ||
scratchFile(self.my_registry.projects.joinpath('ext', 'BUILD')) | ||
scratchFile(self.my_registry.projects.joinpath('ext', 'ext.bzl'), ext_src) | ||
|
||
self.ScratchFile( | ||
'MODULE.bazel', | ||
[ | ||
'bazel_dep(name = "ss", version = "1.3-1")', | ||
], | ||
) | ||
self.ScratchFile('BUILD.bazel', ['filegroup(name = "lala")']) | ||
self.RunBazel( | ||
['build', '--registry=file:///%workspace%/registry', '//:lala'] | ||
) | ||
self.my_registry.start() | ||
try: | ||
self.my_registry.setModuleBasePath('projects') | ||
patch_file = self.ScratchFile( | ||
'ss.patch', | ||
[ | ||
'--- a/aaa.cc', | ||
'+++ b/aaa.cc', | ||
'@@ -1,6 +1,6 @@', | ||
' #include <stdio.h>', | ||
' #include "aaa.h"', | ||
' void hello_aaa(const std::string& caller) {', | ||
'- std::string lib_name = "[email protected]";', | ||
'+ std::string lib_name = "[email protected] (remotely patched)";', | ||
' printf("%s => %s\\n", caller.c_str(), lib_name.c_str());', | ||
' }', | ||
], | ||
) | ||
# Module with a local patch & extension | ||
self.my_registry.createCcModule( | ||
'ss', | ||
'1.3-1', | ||
{'ext': '1.0'}, | ||
patches=[patch_file], | ||
patch_strip=1, | ||
extra_module_file_contents=[ | ||
'my_ext = use_extension("@ext//:ext.bzl", "ext")', | ||
'use_repo(my_ext, "justRepo")', | ||
], | ||
) | ||
ext_src = [ | ||
'def _repo_impl(ctx): ctx.file("BUILD")', | ||
'repo = repository_rule(_repo_impl)', | ||
'def _ext_impl(ctx): repo(name=justRepo)', | ||
'ext=module_extension(_ext_impl)', | ||
] | ||
self.my_registry.createLocalPathModule('ext', '1.0', 'ext') | ||
scratchFile(self.my_registry.projects.joinpath('ext', 'BUILD')) | ||
scratchFile(self.my_registry.projects.joinpath('ext', 'ext.bzl'), ext_src) | ||
|
||
self.ScratchFile( | ||
'MODULE.bazel', | ||
[ | ||
'bazel_dep(name = "ss", version = "1.3-1")', | ||
], | ||
) | ||
self.ScratchFile('BUILD.bazel', ['filegroup(name = "lala")']) | ||
self.RunBazel( | ||
['build', '--registry=file:///%workspace%/registry', '//:lala'] | ||
) | ||
|
||
with open('MODULE.bazel.lock', 'r') as json_file: | ||
lockfile = json.load(json_file) | ||
ss_dep = lockfile['moduleDepGraph']['[email protected]'] | ||
remote_patches = ss_dep['repoSpec']['attributes']['remote_patches'] | ||
ext_usage_location = ss_dep['extensionUsages'][0]['location']['file'] | ||
|
||
self.assertNotIn(self.my_registry.getURL(), ext_usage_location) | ||
self.assertIn('%workspace%', ext_usage_location) | ||
for key in remote_patches.keys(): | ||
self.assertNotIn(self.my_registry.getURL(), key) | ||
self.assertIn('%workspace%', key) | ||
with open('MODULE.bazel.lock', 'r') as json_file: | ||
lockfile = json.load(json_file) | ||
ss_dep = lockfile['moduleDepGraph']['[email protected]'] | ||
remote_patches = ss_dep['repoSpec']['attributes']['remote_patches'] | ||
ext_usage_location = ss_dep['extensionUsages'][0]['location']['file'] | ||
|
||
self.assertNotIn(self.my_registry.getURL(), ext_usage_location) | ||
self.assertIn('%workspace%', ext_usage_location) | ||
for key in remote_patches.keys(): | ||
self.assertNotIn(self.my_registry.getURL(), key) | ||
self.assertIn('%workspace%', key) | ||
finally: | ||
self.my_registry.stop() | ||
|
||
def testExtensionEvaluationRerunsIfDepGraphOrderChanges(self): | ||
self.ScratchFile( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ def setUp(self): | |
self.main_registry = BazelRegistry( | ||
os.path.join(self.registries_work_dir, 'main') | ||
) | ||
self.main_registry.start() | ||
self.main_registry.createCcModule('aaa', '1.0').createCcModule( | ||
'aaa', '1.1' | ||
).createCcModule('bbb', '1.0', {'aaa': '1.0'}).createCcModule( | ||
|
@@ -54,6 +55,10 @@ def setUp(self): | |
], | ||
) | ||
|
||
def tearDown(self): | ||
self.main_registry.stop() | ||
test_base.TestBase.tearDown(self) | ||
|
||
def writeMainProjectFiles(self): | ||
self.ScratchFile( | ||
'aaa.patch', | ||
|
@@ -122,22 +127,26 @@ def testRegistryOverride(self): | |
os.path.join(self.registries_work_dir, 'another'), | ||
' from another registry', | ||
) | ||
another_registry.createCcModule('aaa', '1.0') | ||
self.ScratchFile( | ||
'MODULE.bazel', | ||
[ | ||
'bazel_dep(name = "aaa", version = "1.0")', | ||
'bazel_dep(name = "bbb", version = "1.0")', | ||
'single_version_override(', | ||
' module_name = "aaa",', | ||
' registry = "%s",' % another_registry.getURL(), | ||
')', | ||
], | ||
) | ||
_, stdout, _ = self.RunBazel(['run', '//:main']) | ||
self.assertIn('main function => [email protected] from another registry', stdout) | ||
self.assertIn('main function => [email protected]', stdout) | ||
self.assertIn('[email protected] => [email protected] from another registry', stdout) | ||
another_registry.start() | ||
try: | ||
another_registry.createCcModule('aaa', '1.0') | ||
self.ScratchFile( | ||
'MODULE.bazel', | ||
[ | ||
'bazel_dep(name = "aaa", version = "1.0")', | ||
'bazel_dep(name = "bbb", version = "1.0")', | ||
'single_version_override(', | ||
' module_name = "aaa",', | ||
' registry = "%s",' % another_registry.getURL(), | ||
')', | ||
], | ||
) | ||
_, stdout, _ = self.RunBazel(['run', '//:main']) | ||
self.assertIn('main function => [email protected] from another registry', stdout) | ||
self.assertIn('main function => [email protected]', stdout) | ||
self.assertIn('[email protected] => [email protected] from another registry', stdout) | ||
finally: | ||
another_registry.stop() | ||
|
||
def testArchiveOverride(self): | ||
self.writeMainProjectFiles() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters