@@ -32,6 +32,7 @@ def setUp(self):
3232 self .main_registry = BazelRegistry (
3333 os .path .join (self .registries_work_dir , 'main' )
3434 )
35+ self .main_registry .start ()
3536 self .main_registry .createCcModule ('aaa' , '1.0' ).createCcModule (
3637 'aaa' , '1.1'
3738 ).createCcModule ('bbb' , '1.0' , {'aaa' : '1.0' }).createCcModule (
@@ -59,6 +60,10 @@ def setUp(self):
5960 # deterministic?
6061 os .remove (self .Path ('MODULE.bazel.lock' ))
6162
63+ def tearDown (self ):
64+ self .main_registry .stop ()
65+ test_base .TestBase .tearDown (self )
66+
6267 def testChangeModuleInRegistryWithoutLockfile (self ):
6368 # Add module 'sss' to the registry with dep on 'aaa'
6469 self .main_registry .createCcModule ('sss' , '1.3' , {'aaa' : '1.1' })
@@ -1276,66 +1281,70 @@ def testExtensionEvaluationOnlyRerunOnRelevantUsagesChanges(self):
12761281
12771282 def testLockfileWithNoUserSpecificPath (self ):
12781283 self .my_registry = BazelRegistry (os .path .join (self ._test_cwd , 'registry' ))
1279- self .my_registry .setModuleBasePath ('projects' )
1280- patch_file = self .ScratchFile (
1281- 'ss.patch' ,
1282- [
1283- '--- a/aaa.cc' ,
1284- '+++ b/aaa.cc' ,
1285- '@@ -1,6 +1,6 @@' ,
1286- ' #include <stdio.h>' ,
1287- ' #include "aaa.h"' ,
1288- ' void hello_aaa(const std::string& caller) {' ,
1289- '- std::string lib_name = "[email protected] ";' ,
1290- '+ std::string lib_name = "[email protected] (remotely patched)";' ,
1291- ' printf("%s => %s\\ n", caller.c_str(), lib_name.c_str());' ,
1292- ' }' ,
1293- ],
1294- )
1295- # Module with a local patch & extension
1296- self .my_registry .createCcModule (
1297- 'ss' ,
1298- '1.3-1' ,
1299- {'ext' : '1.0' },
1300- patches = [patch_file ],
1301- patch_strip = 1 ,
1302- extra_module_file_contents = [
1303- 'my_ext = use_extension("@ext//:ext.bzl", "ext")' ,
1304- 'use_repo(my_ext, "justRepo")' ,
1305- ],
1306- )
1307- ext_src = [
1308- 'def _repo_impl(ctx): ctx.file("BUILD")' ,
1309- 'repo = repository_rule(_repo_impl)' ,
1310- 'def _ext_impl(ctx): repo(name=justRepo)' ,
1311- 'ext=module_extension(_ext_impl)' ,
1312- ]
1313- self .my_registry .createLocalPathModule ('ext' , '1.0' , 'ext' )
1314- scratchFile (self .my_registry .projects .joinpath ('ext' , 'BUILD' ))
1315- scratchFile (self .my_registry .projects .joinpath ('ext' , 'ext.bzl' ), ext_src )
1316-
1317- self .ScratchFile (
1318- 'MODULE.bazel' ,
1319- [
1320- 'bazel_dep(name = "ss", version = "1.3-1")' ,
1321- ],
1322- )
1323- self .ScratchFile ('BUILD.bazel' , ['filegroup(name = "lala")' ])
1324- self .RunBazel (
1325- ['build' , '--registry=file:///%workspace%/registry' , '//:lala' ]
1326- )
1284+ self .my_registry .start ()
1285+ try :
1286+ self .my_registry .setModuleBasePath ('projects' )
1287+ patch_file = self .ScratchFile (
1288+ 'ss.patch' ,
1289+ [
1290+ '--- a/aaa.cc' ,
1291+ '+++ b/aaa.cc' ,
1292+ '@@ -1,6 +1,6 @@' ,
1293+ ' #include <stdio.h>' ,
1294+ ' #include "aaa.h"' ,
1295+ ' void hello_aaa(const std::string& caller) {' ,
1296+ '- std::string lib_name = "[email protected] ";' ,
1297+ '+ std::string lib_name = "[email protected] (remotely patched)";' ,
1298+ ' printf("%s => %s\\ n", caller.c_str(), lib_name.c_str());' ,
1299+ ' }' ,
1300+ ],
1301+ )
1302+ # Module with a local patch & extension
1303+ self .my_registry .createCcModule (
1304+ 'ss' ,
1305+ '1.3-1' ,
1306+ {'ext' : '1.0' },
1307+ patches = [patch_file ],
1308+ patch_strip = 1 ,
1309+ extra_module_file_contents = [
1310+ 'my_ext = use_extension("@ext//:ext.bzl", "ext")' ,
1311+ 'use_repo(my_ext, "justRepo")' ,
1312+ ],
1313+ )
1314+ ext_src = [
1315+ 'def _repo_impl(ctx): ctx.file("BUILD")' ,
1316+ 'repo = repository_rule(_repo_impl)' ,
1317+ 'def _ext_impl(ctx): repo(name=justRepo)' ,
1318+ 'ext=module_extension(_ext_impl)' ,
1319+ ]
1320+ self .my_registry .createLocalPathModule ('ext' , '1.0' , 'ext' )
1321+ scratchFile (self .my_registry .projects .joinpath ('ext' , 'BUILD' ))
1322+ scratchFile (self .my_registry .projects .joinpath ('ext' , 'ext.bzl' ), ext_src )
1323+
1324+ self .ScratchFile (
1325+ 'MODULE.bazel' ,
1326+ [
1327+ 'bazel_dep(name = "ss", version = "1.3-1")' ,
1328+ ],
1329+ )
1330+ self .ScratchFile ('BUILD.bazel' , ['filegroup(name = "lala")' ])
1331+ self .RunBazel (
1332+ ['build' , '--registry=file:///%workspace%/registry' , '//:lala' ]
1333+ )
13271334
1328- with open ('MODULE.bazel.lock' , 'r' ) as json_file :
1329- lockfile = json .load (json_file )
1330- ss_dep = lockfile [
'moduleDepGraph' ][
'[email protected] ' ]
1331- remote_patches = ss_dep ['repoSpec' ]['attributes' ]['remote_patches' ]
1332- ext_usage_location = ss_dep ['extensionUsages' ][0 ]['location' ]['file' ]
1333-
1334- self .assertNotIn (self .my_registry .getURL (), ext_usage_location )
1335- self .assertIn ('%workspace%' , ext_usage_location )
1336- for key in remote_patches .keys ():
1337- self .assertNotIn (self .my_registry .getURL (), key )
1338- self .assertIn ('%workspace%' , key )
1335+ with open ('MODULE.bazel.lock' , 'r' ) as json_file :
1336+ lockfile = json .load (json_file )
1337+ ss_dep = lockfile [
'moduleDepGraph' ][
'[email protected] ' ]
1338+ remote_patches = ss_dep ['repoSpec' ]['attributes' ]['remote_patches' ]
1339+ ext_usage_location = ss_dep ['extensionUsages' ][0 ]['location' ]['file' ]
1340+
1341+ self .assertNotIn (self .my_registry .getURL (), ext_usage_location )
1342+ self .assertIn ('%workspace%' , ext_usage_location )
1343+ for key in remote_patches .keys ():
1344+ self .assertNotIn (self .my_registry .getURL (), key )
1345+ self .assertIn ('%workspace%' , key )
1346+ finally :
1347+ self .my_registry .stop ()
13391348
13401349 def testExtensionEvaluationRerunsIfDepGraphOrderChanges (self ):
13411350 self .ScratchFile (
0 commit comments