From f7379b1c9cb64e9fcb4028a1cef460b2ff27fefb Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 6 Feb 2024 20:52:08 +0100 Subject: [PATCH] Fix Python tests --- src/test/py/bazel/bzlmod/bazel_fetch_test.py | 14 +-- .../py/bazel/bzlmod/bazel_lockfile_test.py | 97 ++++++++++--------- src/test/py/bazel/bzlmod/bazel_module_test.py | 22 ++--- .../py/bazel/bzlmod/bazel_overrides_test.py | 6 +- .../bazel/bzlmod/bazel_repo_mapping_test.py | 19 ++-- src/test/py/bazel/bzlmod/bazel_vendor_test.py | 24 ++--- src/test/py/bazel/bzlmod/bzlmod_query_test.py | 20 ++-- .../bzlmod/external_repo_completion_test.py | 10 +- src/test/py/bazel/bzlmod/mod_command_test.py | 52 +++++----- src/test/shell/bazel/python_version_test.sh | 2 +- 10 files changed, 134 insertions(+), 132 deletions(-) diff --git a/src/test/py/bazel/bzlmod/bazel_fetch_test.py b/src/test/py/bazel/bzlmod/bazel_fetch_test.py index 506ddc2f262957..2981549af4bdad 100644 --- a/src/test/py/bazel/bzlmod/bazel_fetch_test.py +++ b/src/test/py/bazel/bzlmod/bazel_fetch_test.py @@ -101,8 +101,8 @@ def testFetchAll(self): self.RunBazel(['fetch', '--all']) _, stdout, _ = self.RunBazel(['info', 'output_base']) repos_fetched = os.listdir(stdout[0] + '/external') - self.assertIn('aaa~1.0', repos_fetched) - self.assertIn('bbb~1.0', repos_fetched) + self.assertIn('aaa~', repos_fetched) + self.assertIn('bbb~', repos_fetched) self.assertIn('_main~ext~hello', repos_fetched) def testFetchConfig(self): @@ -141,7 +141,7 @@ def testFetchConfig(self): self.RunBazel(['fetch', '--configure']) _, stdout, _ = self.RunBazel(['info', 'output_base']) repos_fetched = os.listdir(stdout[0] + '/external') - self.assertNotIn('aaa~1.0', repos_fetched) + self.assertNotIn('aaa~', repos_fetched) self.assertNotIn('_main~ext~notConfig', repos_fetched) self.assertIn('_main~ext~IamConfig', repos_fetched) @@ -179,12 +179,12 @@ def testFetchRepo(self): ) self.ScratchFile('BUILD') # Test canonical/apparent repo names & multiple repos - self.RunBazel(['fetch', '--repo=@@bbb~1.0', '--repo=@my_repo']) + self.RunBazel(['fetch', '--repo=@@bbb~', '--repo=@my_repo']) _, stdout, _ = self.RunBazel(['info', 'output_base']) repos_fetched = os.listdir(stdout[0] + '/external') - self.assertIn('bbb~1.0', repos_fetched) - self.assertIn('ccc~1.0', repos_fetched) - self.assertNotIn('aaa~1.0', repos_fetched) + self.assertIn('bbb~', repos_fetched) + self.assertIn('ccc~', repos_fetched) + self.assertNotIn('aaa~', repos_fetched) def testFetchInvalidRepo(self): # Invalid repo name (not canonical or apparent) diff --git a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py index c7df0c9f97f038..af873b8626e528 100644 --- a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py +++ b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py @@ -1519,13 +1519,11 @@ def testInnateModuleExtension(self): def testExtensionRepoMappingChange(self): # Regression test for #20721 self.main_registry.createCcModule('foo', '1.0') - self.main_registry.createCcModule('foo', '2.0') self.main_registry.createCcModule('bar', '1.0') - self.main_registry.createCcModule('bar', '2.0') self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="1.0")', + 'bazel_dep(name="foo",version="1.0",repo_name="repo_name")', 'bazel_dep(name="bar",version="1.0")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', @@ -1548,13 +1546,13 @@ def testExtensionRepoMappingChange(self): 'repo = repository_rule(_repo_impl,attrs={"value":attr.label()})', 'def _ext_impl(mctx):', ' print("ran the extension!")', - ' repo(name = "repo", value = Label("@foo//:lib_foo"))', + ' repo(name = "repo", value = Label("@repo_name//:lib_foo"))', 'ext = module_extension(_ext_impl)', ], ) _, _, stderr = self.RunBazel(['build', ':lol']) - self.assertIn('STR=@@foo~1.0//:lib_foo', '\n'.join(stderr)) + self.assertIn('STR=@@foo~//:lib_foo', '\n'.join(stderr)) # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) @@ -1563,30 +1561,33 @@ def testExtensionRepoMappingChange(self): # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) - # Now, for something spicy: upgrade foo to 2.0 and change nothing else. - # The extension should rerun despite the lockfile being present, and no - # usages or .bzl files having changed. + # Now, for something spicy: let repo_name point to bar and change nothing + # else. The extension should rerun despite the lockfile being present, and + # no usages or .bzl files having changed. self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="2.0")', - 'bazel_dep(name="bar",version="1.0")', + 'bazel_dep(name="foo",version="1.0")', + 'bazel_dep(name="bar",version="1.0",repo_name="repo_name")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', ], ) _, _, stderr = self.RunBazel(['build', ':lol']) - self.assertIn('STR=@@foo~2.0//:lib_foo', '\n'.join(stderr)) + stderr = '\n'.join(stderr) + self.assertIn('ran the extension!', stderr) + self.assertIn('STR=@@bar~//:lib_foo', stderr) # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) - # More spicy! upgrade bar to 2.0 and change nothing else. - # The extension should NOT rerun, since it never used the @bar repo mapping. + # More spicy! change the repo_name of foo, but nothing else. + # The extension should NOT rerun, since it never used the @other_name repo + # mapping. self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="2.0")', - 'bazel_dep(name="bar",version="2.0")', + 'bazel_dep(name="foo",version="1.0",repo_name="other_name")', + 'bazel_dep(name="bar",version="1.0",repo_name="repo_name")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', ], @@ -1594,19 +1595,17 @@ def testExtensionRepoMappingChange(self): _, _, stderr = self.RunBazel(['build', ':lol']) stderr = '\n'.join(stderr) self.assertNotIn('ran the extension!', stderr) - self.assertIn('STR=@@foo~2.0//:lib_foo', stderr) + self.assertIn('STR=@@bar~//:lib_foo', stderr) def testExtensionRepoMappingChange_BzlInit(self): # Regression test for #20721; same test as above, except that the call to # Label() in ext.bzl is now done at bzl load time. self.main_registry.createCcModule('foo', '1.0') - self.main_registry.createCcModule('foo', '2.0') self.main_registry.createCcModule('bar', '1.0') - self.main_registry.createCcModule('bar', '2.0') self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="1.0")', + 'bazel_dep(name="foo",version="1.0",repo_name="repo_name")', 'bazel_dep(name="bar",version="1.0")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', @@ -1623,7 +1622,7 @@ def testExtensionRepoMappingChange_BzlInit(self): self.ScratchFile( 'ext.bzl', [ - 'constant = Label("@foo//:lib_foo")', + 'constant = Label("@repo_name//:lib_foo")', 'def _repo_impl(rctx):', ' rctx.file("BUILD")', ' rctx.file("defs.bzl", "STR = " + repr(str(rctx.attr.value)))', @@ -1645,30 +1644,33 @@ def testExtensionRepoMappingChange_BzlInit(self): # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) - # Now, for something spicy: upgrade foo to 2.0 and change nothing else. - # The extension should rerun despite the lockfile being present, and no - # usages or .bzl files having changed. + # Now, for something spicy: let repo_name point to bar and change nothing + # else. The extension should rerun despite the lockfile being present, and + # no usages or .bzl files having changed. self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="2.0")', - 'bazel_dep(name="bar",version="1.0")', + 'bazel_dep(name="foo",version="1.0")', + 'bazel_dep(name="bar",version="1.0",repo_name="repo_name")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', ], ) _, _, stderr = self.RunBazel(['build', ':lol']) - self.assertIn('STR=@@foo~2.0//:lib_foo', '\n'.join(stderr)) + stderr = '\n'.join(stderr) + self.assertIn('ran the extension!', stderr) + self.assertIn('STR=@@bar~//:lib_foo', stderr) # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) - # More spicy! upgrade bar to 2.0 and change nothing else. - # The extension should NOT rerun, since it never used the @bar repo mapping. + # More spicy! change the repo_name of foo, but nothing else. + # The extension should NOT rerun, since it never used the @other_name repo + # mapping. self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="2.0")', - 'bazel_dep(name="bar",version="2.0")', + 'bazel_dep(name="foo",version="1.0",repo_name="other_name")', + 'bazel_dep(name="bar",version="1.0",repo_name="repo_name")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', ], @@ -1676,34 +1678,33 @@ def testExtensionRepoMappingChange_BzlInit(self): _, _, stderr = self.RunBazel(['build', ':lol']) stderr = '\n'.join(stderr) self.assertNotIn('ran the extension!', stderr) - self.assertIn('STR=@@foo~2.0//:lib_foo', stderr) + self.assertIn('STR=@@bar~//:lib_foo', stderr) def testExtensionRepoMappingChange_loadsAndRepoRelativeLabels(self): # Regression test for #20721; same test as above, except that the call to - # Label() in ext.bzl is now moved to @foo//:defs.bzl and doesn't itself - # use repo mapping (ie. is a repo-relative label). bar is removed as it's - # just a distraction. + # Label() in ext.bzl is now moved to @{foo,bar}//:defs.bzl and doesn't + # itself use repo mapping (ie. is a repo-relative label). self.main_registry.setModuleBasePath('projects') projects_dir = self.main_registry.projects - self.main_registry.createLocalPathModule('foo', '1.0', 'foo1') - scratchFile(projects_dir.joinpath('foo1', 'BUILD')) + self.main_registry.createLocalPathModule('foo', '1.0', 'foo') + scratchFile(projects_dir.joinpath('foo', 'BUILD')) scratchFile( - projects_dir.joinpath('foo1', 'defs.bzl'), + projects_dir.joinpath('foo', 'defs.bzl'), ['constant=Label("//:BUILD")'], ) - self.main_registry.createLocalPathModule('foo', '2.0', 'foo2') - scratchFile(projects_dir.joinpath('foo2', 'BUILD')) - # Exactly the same as foo1! + self.main_registry.createLocalPathModule('bar', '1.0', 'bar') + scratchFile(projects_dir.joinpath('bar', 'BUILD')) + # Exactly the same as foo! scratchFile( - projects_dir.joinpath('foo2', 'defs.bzl'), + projects_dir.joinpath('bar', 'defs.bzl'), ['constant=Label("//:BUILD")'], ) self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="1.0")', + 'bazel_dep(name="foo",version="1.0",repo_name="repo_name")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', ], @@ -1719,7 +1720,7 @@ def testExtensionRepoMappingChange_loadsAndRepoRelativeLabels(self): self.ScratchFile( 'ext.bzl', [ - 'load("@foo//:defs.bzl", "constant")', + 'load("@repo_name//:defs.bzl", "constant")', 'def _repo_impl(rctx):', ' rctx.file("BUILD")', ' rctx.file("defs.bzl", "STR = " + repr(str(rctx.attr.value)))', @@ -1732,7 +1733,7 @@ def testExtensionRepoMappingChange_loadsAndRepoRelativeLabels(self): ) _, _, stderr = self.RunBazel(['build', ':lol']) - self.assertIn('STR=@@foo~1.0//:BUILD', '\n'.join(stderr)) + self.assertIn('STR=@@foo~//:BUILD', '\n'.join(stderr)) # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) @@ -1741,19 +1742,19 @@ def testExtensionRepoMappingChange_loadsAndRepoRelativeLabels(self): # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) - # Now, for something spicy: upgrade foo to 2.0 and change nothing else. + # Now, for something spicy: change repo_name to point to bar. # The extension should rerun despite the lockfile being present, and no # usages or .bzl files having changed. self.ScratchFile( 'MODULE.bazel', [ - 'bazel_dep(name="foo",version="2.0")', + 'bazel_dep(name="bar",version="1.0",repo_name="repo_name")', 'ext = use_extension(":ext.bzl", "ext")', 'use_repo(ext, "repo")', ], ) _, _, stderr = self.RunBazel(['build', ':lol']) - self.assertIn('STR=@@foo~2.0//:BUILD', '\n'.join(stderr)) + self.assertIn('STR=@@bar~//:BUILD', '\n'.join(stderr)) def testExtensionRepoMappingChange_sourceRepoNoLongerExistent(self): # Regression test for #20721; a very convoluted setup to make sure that @@ -1892,7 +1893,7 @@ def testExtensionRepoMappingChange_mainRepoEvalCycleWithWorkspace(self): self.ScratchFile('WORKSPACE.bzlmod', ['load("@repo//:defs.bzl","STR")']) _, _, stderr = self.RunBazel(['build', '--enable_workspace', ':lol']) - self.assertIn('STR=@@foo~1.0//:lib_foo', '\n'.join(stderr)) + self.assertIn('STR=@@foo~//:lib_foo', '\n'.join(stderr)) # Shutdown bazel to make sure we rely on the lockfile and not skyframe self.RunBazel(['shutdown']) diff --git a/src/test/py/bazel/bzlmod/bazel_module_test.py b/src/test/py/bazel/bzlmod/bazel_module_test.py index dc5399f1b6617d..6cfe1357b0b67f 100644 --- a/src/test/py/bazel/bzlmod/bazel_module_test.py +++ b/src/test/py/bazel/bzlmod/bazel_module_test.py @@ -416,10 +416,10 @@ def testNativePackageRelativeLabel(self): _, _, stderr = self.RunBazel(['build', '@bar//quux:book']) stderr = '\n'.join(stderr) - self.assertIn('1st: @@bar~override//quux:bleb', stderr) - self.assertIn('2nd: @@bar~override//bleb:bleb', stderr) + self.assertIn('1st: @@bar~//quux:bleb', stderr) + self.assertIn('2nd: @@bar~//bleb:bleb', stderr) self.assertIn('3rd: @@//bleb:bleb', stderr) - self.assertIn('4th: @@bar~override//bleb:bleb', stderr) + self.assertIn('4th: @@bar~//bleb:bleb', stderr) self.assertIn('5th: @@bleb//bleb:bleb', stderr) self.assertIn('6th: @@//bleb:bleb', stderr) @@ -459,10 +459,10 @@ def testWorkspaceEvaluatedBzlCanSeeRootModuleMappings(self): stderr = '\n'.join(stderr) # @bar is mapped to @@baz, which Bzlmod doesn't recognize, so we leave it be self.assertIn('1st: @@baz//:z', stderr) - # @my_aaa is mapped to @@aaa, which Bzlmod remaps to @@aaa~1.0 - self.assertIn('2nd: @@aaa~1.0//:z', stderr) - # @bbb isn't mapped in WORKSPACE, but Bzlmod maps it to @@bbb~1.0 - self.assertIn('3rd: @@bbb~1.0//:z', stderr) + # @my_aaa is mapped to @@aaa, which Bzlmod remaps to @@aaa~ + self.assertIn('2nd: @@aaa~//:z', stderr) + # @bbb isn't mapped in WORKSPACE, but Bzlmod maps it to @@bbb~ + self.assertIn('3rd: @@bbb~//:z', stderr) # @blarg isn't mapped by WORKSPACE or Bzlmod self.assertIn('4th: @@blarg//:z', stderr) @@ -641,11 +641,11 @@ def testNativeModuleNameAndVersion(self): ) stderr = '\n'.join(stderr) self.assertIn('@@ reporting in: root@0.1', stderr) - self.assertIn('@@foo~1.0 reporting in: foo@1.0', stderr) + self.assertIn('@@foo~ reporting in: foo@1.0', stderr) self.assertIn( - '@@foo~1.0~report_ext~report_repo reporting in: foo@1.0', stderr + '@@foo~~report_ext~report_repo reporting in: foo@1.0', stderr ) - self.assertIn('@@bar~override reporting in: bar@2.0', stderr) + self.assertIn('@@bar~ reporting in: bar@2.0', stderr) self.assertIn('@@quux reporting in: None@None', stderr) def testWorkspaceToolchainRegistrationWithPlatformsConstraint(self): @@ -791,7 +791,7 @@ def testLocationNonRegistry(self): ) self.ScratchFile('hello/MODULE.bazel', ['wat']) _, _, stderr = self.RunBazel(['build', '@what'], allow_failure=True) - self.assertIn('ERROR: @@hello~override//:MODULE.bazel', '\n'.join(stderr)) + self.assertIn('ERROR: @@hello~//:MODULE.bazel', '\n'.join(stderr)) def testLoadRulesJavaSymbolThroughBazelTools(self): """Tests that loads from @bazel_tools that delegate to other modules resolve.""" diff --git a/src/test/py/bazel/bzlmod/bazel_overrides_test.py b/src/test/py/bazel/bzlmod/bazel_overrides_test.py index b942700fe314a3..ece469bd94e8c6 100644 --- a/src/test/py/bazel/bzlmod/bazel_overrides_test.py +++ b/src/test/py/bazel/bzlmod/bazel_overrides_test.py @@ -265,7 +265,7 @@ def testCmdAbsoluteModuleOverride(self): ) # module file override should be ignored, and bb directory should be used self.assertIn( - 'Target @@ss~override//:choose_me up-to-date (nothing to build)', stderr + 'Target @@ss~//:choose_me up-to-date (nothing to build)', stderr ) def testCmdRelativeModuleOverride(self): @@ -303,7 +303,7 @@ def testCmdRelativeModuleOverride(self): cwd=self.Path('aa/cc'), ) self.assertIn( - 'Target @@ss~override//:choose_me up-to-date (nothing to build)', stderr + 'Target @@ss~//:choose_me up-to-date (nothing to build)', stderr ) def testCmdWorkspaceRelativeModuleOverride(self): @@ -338,7 +338,7 @@ def testCmdWorkspaceRelativeModuleOverride(self): cwd=self.Path('aa'), ) self.assertIn( - 'Target @@ss~override//:choose_me up-to-date (nothing to build)', stderr + 'Target @@ss~//:choose_me up-to-date (nothing to build)', stderr ) diff --git a/src/test/py/bazel/bzlmod/bazel_repo_mapping_test.py b/src/test/py/bazel/bzlmod/bazel_repo_mapping_test.py index 125d9c7ed65ff4..bde1f64d6e8cb6 100644 --- a/src/test/py/bazel/bzlmod/bazel_repo_mapping_test.py +++ b/src/test/py/bazel/bzlmod/bazel_repo_mapping_test.py @@ -104,6 +104,7 @@ def testRunfilesRepoMappingManifest(self): 'bazel_dep(name="foo",version="1.0")', 'bazel_dep(name="bar",version="2.0")', 'bazel_dep(name="bare_rule",version="1.0")', + 'multiple_version_override(module_name="quux",versions=["1.0","2.0"])', ], ) self.ScratchFile('WORKSPACE.bzlmod', ['workspace(name="me_ws")']) @@ -160,12 +161,12 @@ def testRunfilesRepoMappingManifest(self): with open(self.Path(path), 'r') as f: self.assertEqual( f.read().strip(), - """,foo,foo~1.0 + """,foo,foo~ ,me,_main ,me_ws,_main -foo~1.0,foo,foo~1.0 -foo~1.0,quux,quux~2.0 -quux~2.0,quux,quux~2.0""", +foo~,foo,foo~ +foo~,quux,quux~1.0 +quux~1.0,quux,quux~1.0""", ) with open(self.Path('bazel-bin/me.runfiles_manifest')) as f: self.assertIn('_repo_mapping ', f.read()) @@ -177,19 +178,19 @@ def testRunfilesRepoMappingManifest(self): '--test_output=errors', ]) - paths = ['bazel-bin/external/bar~2.0/bar.repo_mapping'] + paths = ['bazel-bin/external/bar~/bar.repo_mapping'] if not self.IsWindows(): - paths.append('bazel-bin/external/bar~2.0/bar.runfiles/_repo_mapping') + paths.append('bazel-bin/external/bar~/bar.runfiles/_repo_mapping') for path in paths: with open(self.Path(path), 'r') as f: self.assertEqual( f.read().strip(), - """bar~2.0,bar,bar~2.0 -bar~2.0,quux,quux~2.0 + """bar~,bar,bar~ +bar~,quux,quux~2.0 quux~2.0,quux,quux~2.0""", ) with open( - self.Path('bazel-bin/external/bar~2.0/bar.runfiles_manifest') + self.Path('bazel-bin/external/bar~/bar.runfiles_manifest') ) as f: self.assertIn('_repo_mapping ', f.read()) diff --git a/src/test/py/bazel/bzlmod/bazel_vendor_test.py b/src/test/py/bazel/bzlmod/bazel_vendor_test.py index a02743d1b340ed..24aa9309955f7d 100644 --- a/src/test/py/bazel/bzlmod/bazel_vendor_test.py +++ b/src/test/py/bazel/bzlmod/bazel_vendor_test.py @@ -90,10 +90,10 @@ def testBasicVendoring(self): # Assert repos are vendored with marker files and .vendorignore is created repos_vendored = os.listdir(self._test_cwd + '/vendor') - self.assertIn('aaa~1.0', repos_vendored) - self.assertIn('bbb~1.0', repos_vendored) - self.assertIn('@aaa~1.0.marker', repos_vendored) - self.assertIn('@bbb~1.0.marker', repos_vendored) + self.assertIn('aaa~', repos_vendored) + self.assertIn('bbb~', repos_vendored) + self.assertIn('@aaa~.marker', repos_vendored) + self.assertIn('@bbb~.marker', repos_vendored) self.assertIn('.vendorignore', repos_vendored) def testVendorFailsWithNofetch(self): @@ -126,7 +126,7 @@ def testVendoringMultipleTimes(self): self.RunBazel(['vendor', '--vendor_dir=vendor']) _, stdout, _ = self.RunBazel(['info', 'output_base']) - repo_path = stdout[0] + '/external/aaa~1.0' + repo_path = stdout[0] + '/external/aaa~' if self.IsWindows(): self.assertTrue(self.IsJunction(repo_path)) else: @@ -175,7 +175,7 @@ def testBuildingWithVendoredRepos(self): ) self.ScratchFile('BUILD') self.RunBazel(['vendor', '--vendor_dir=vendor']) - self.assertIn('aaa~1.0', os.listdir(self._test_cwd + '/vendor')) + self.assertIn('aaa~', os.listdir(self._test_cwd + '/vendor')) # Empty external & build with vendor self.RunBazel(['clean', '--expunge']) @@ -188,7 +188,7 @@ def testBuildingWithVendoredRepos(self): # Assert repo aaa in {OUTPUT_BASE}/external is a symlink (junction on # windows, this validates it was created from vendor and not fetched)= _, stdout, _ = self.RunBazel(['info', 'output_base']) - repo_path = stdout[0] + '/external/aaa~1.0' + repo_path = stdout[0] + '/external/aaa~' if self.IsWindows(): self.assertTrue(self.IsJunction(repo_path)) else: @@ -237,19 +237,19 @@ def testIgnoreFromVendoring(self): os.makedirs(self._test_cwd + '/vendor', exist_ok=True) with open(self._test_cwd + '/vendor/.vendorignore', 'w') as f: - f.write('aaa~1.0\n') + f.write('aaa~\n') self.RunBazel(['vendor', '--vendor_dir=vendor']) repos_vendored = os.listdir(self._test_cwd + '/vendor') # Assert bbb and the regularRepo are vendored with marker files - self.assertIn('bbb~1.0', repos_vendored) - self.assertIn('@bbb~1.0.marker', repos_vendored) + self.assertIn('bbb~', repos_vendored) + self.assertIn('@bbb~.marker', repos_vendored) self.assertIn('_main~ext~regularRepo', repos_vendored) self.assertIn('@_main~ext~regularRepo.marker', repos_vendored) # Assert aaa (from .vendorignore), local and config repos are not vendored - self.assertNotIn('aaa~1.0', repos_vendored) + self.assertNotIn('aaa~', repos_vendored) self.assertNotIn('bazel_tools', repos_vendored) self.assertNotIn('local_config_platform', repos_vendored) self.assertNotIn('_main~ext~localRepo', repos_vendored) @@ -322,7 +322,7 @@ def testBuildingOutOfDateVendoredRepo(self): stderr, ) _, stdout, _ = self.RunBazel(['info', 'output_base']) - self.assertFalse(os.path.islink(stdout[0] + '/external/bbb~1.0')) + self.assertFalse(os.path.islink(stdout[0] + '/external/bbb~')) # Assert vendoring again solves the problem self.RunBazel(['vendor', '--vendor_dir=vendor']) diff --git a/src/test/py/bazel/bzlmod/bzlmod_query_test.py b/src/test/py/bazel/bzlmod/bzlmod_query_test.py index 453cd02b17b9e4..d03f78affef977 100644 --- a/src/test/py/bazel/bzlmod/bzlmod_query_test.py +++ b/src/test/py/bazel/bzlmod/bzlmod_query_test.py @@ -76,7 +76,7 @@ def testQueryModuleRepoTransitiveDeps(self): '--notool_deps', ]) self.assertListEqual( - ['//:main', '@my_repo//:lib_aaa', '@@ccc~1.2//:lib_ccc'], stdout) + ['//:main', '@my_repo//:lib_aaa', '@@ccc~//:lib_ccc'], stdout) def testQueryModuleRepoTransitiveDeps_consistentLabels(self): self.ScratchFile( @@ -103,7 +103,7 @@ def testQueryModuleRepoTransitiveDeps_consistentLabels(self): '--consistent_labels', ]) self.assertListEqual( - ['@@//:main', '@@aaa~1.0//:lib_aaa', '@@ccc~1.2//:lib_ccc'], stdout + ['@@//:main', '@@aaa~1.0//:lib_aaa', '@@ccc~//:lib_ccc'], stdout ) def testQueryModuleRepoTransitiveDeps_consistentLabels_outputPackage(self): @@ -131,7 +131,7 @@ def testQueryModuleRepoTransitiveDeps_consistentLabels_outputPackage(self): '--consistent_labels', '--output=package', ]) - self.assertListEqual(['@@//pkg', '@@aaa~1.0//', '@@ccc~1.2//'], stdout) + self.assertListEqual(['@@//pkg', '@@aaa~1.0//', '@@ccc~//'], stdout) def testQueryModuleRepoTransitiveDeps_consistentLabels_outputBuild(self): self.ScratchFile( @@ -191,7 +191,7 @@ def testAqueryModuleRepoTransitiveDeps(self): ]) self.assertIn('Target: //:main', stdout) self.assertIn('Target: @my_repo//:lib_aaa', stdout) - self.assertIn('Target: @@ccc~1.2//:lib_ccc', stdout) + self.assertIn('Target: @@ccc~//:lib_ccc', stdout) def testAqueryModuleRepoTransitiveDeps_consistentLabels(self): self.ScratchFile( @@ -218,8 +218,8 @@ def testAqueryModuleRepoTransitiveDeps_consistentLabels(self): '--consistent_labels', ]) self.assertIn('Target: @@//:main', stdout) - self.assertIn('Target: @@aaa~1.0//:lib_aaa', stdout) - self.assertIn('Target: @@ccc~1.2//:lib_ccc', stdout) + self.assertIn('Target: @@aaa~//:lib_aaa', stdout) + self.assertIn('Target: @@ccc~//:lib_ccc', stdout) def testCqueryModuleRepoTargetsBelow(self): self.ScratchFile('MODULE.bazel', [ @@ -248,7 +248,7 @@ def testCqueryModuleRepoTransitiveDeps(self): ]) self.assertRegex(stdout[0], r'^//:main \([\w\d]+\)$') self.assertRegex(stdout[1], r'^@my_repo//:lib_aaa \([\w\d]+\)$') - self.assertRegex(stdout[2], r'^@@ccc~1.2//:lib_ccc \([\w\d]+\)$') + self.assertRegex(stdout[2], r'^@@ccc~//:lib_ccc \([\w\d]+\)$') self.assertEqual(len(stdout), 3) def testCqueryModuleRepoTransitiveDeps_consistentLabels(self): @@ -276,8 +276,8 @@ def testCqueryModuleRepoTransitiveDeps_consistentLabels(self): '--consistent_labels', ]) self.assertRegex(stdout[0], r'^@@//:main \([\w\d]+\)$') - self.assertRegex(stdout[1], r'^@@aaa~1.0//:lib_aaa \([\w\d]+\)$') - self.assertRegex(stdout[2], r'^@@ccc~1.2//:lib_ccc \([\w\d]+\)$') + self.assertRegex(stdout[1], r'^@@aaa~//:lib_aaa \([\w\d]+\)$') + self.assertRegex(stdout[2], r'^@@ccc~//:lib_ccc \([\w\d]+\)$') self.assertEqual(len(stdout), 3) def testFetchModuleRepoTargetsBelow(self): @@ -303,7 +303,7 @@ def testGenQueryTargetLiteralInGenRule(self): self.assertIsNotNone(output_file) output = output_file.readlines() output_file.close() - self.assertListEqual(['@@aaa~1.0//:lib_aaa\n'], output) + self.assertListEqual(['@@aaa~//:lib_aaa\n'], output) def testQueryCannotResolveRepoMapping_malformedModuleFile(self): self.ScratchFile('MODULE.bazel', [ diff --git a/src/test/py/bazel/bzlmod/external_repo_completion_test.py b/src/test/py/bazel/bzlmod/external_repo_completion_test.py index 5a0f1380d7820c..ac5f6991bd53f7 100644 --- a/src/test/py/bazel/bzlmod/external_repo_completion_test.py +++ b/src/test/py/bazel/bzlmod/external_repo_completion_test.py @@ -249,12 +249,12 @@ def testCompletions(self): # Packages are completed in external repos with canonical repo names. self.assertCountEqual( - ['@@ext~1.0//tools/', '@@ext~1.0//tools:'], - self.complete('build @@ext~1.0//tool'), + ['@@ext~//tools/', '@@ext~//tools:'], + self.complete('build @@ext~//tool'), ) self.assertCountEqual( - ['@@ext~1.0//tools/zip/', '@@ext~1.0//tools/zip:'], - self.complete('build @@ext~1.0//tools/zi'), + ['@@ext~//tools/zip/', '@@ext~//tools/zip:'], + self.complete('build @@ext~//tools/zi'), ) self.assertCountEqual( ['@@//pkg/', '@@//pkg:'], self.complete('build @@//p') @@ -276,7 +276,7 @@ def testCompletions(self): # Targets are completed in external repos with canonical repo names. self.assertCountEqual(['lib_foo'], self.complete('build @@foo~2.0//:')) self.assertCountEqual( - ['zipper'], self.complete('build @@ext~1.0//tools/zip:zipp') + ['zipper'], self.complete('build @@ext~//tools/zip:zipp') ) self.assertCountEqual(['my_lib'], self.complete('build @@//pkg:my_')) diff --git a/src/test/py/bazel/bzlmod/mod_command_test.py b/src/test/py/bazel/bzlmod/mod_command_test.py index 74172b0c765e7d..e962c669e742d5 100644 --- a/src/test/py/bazel/bzlmod/mod_command_test.py +++ b/src/test/py/bazel/bzlmod/mod_command_test.py @@ -162,27 +162,27 @@ def testGraphWithExtensions(self): stdout, [ ' (my_project@1.0)', - '|___$@@ext2~1.0//:ext.bzl%ext', + '|___$@@ext2~//:ext.bzl%ext', '| |___repo1', - '|___$@@ext~1.0//:ext.bzl%ext', + '|___$@@ext~//:ext.bzl%ext', '| |___repo1', '| |...repo2', '| |...repo5', '|___ext@1.0', '|___ext2@1.0', '|___foo@1.0', - '| |___$@@ext~1.0//:ext.bzl%ext ...', + '| |___$@@ext~//:ext.bzl%ext ...', '| | |___repo1', '| |___ext@1.0 (*)', '| |___bar@2.0', - '| |___$@@ext2~1.0//:ext.bzl%ext ...', + '| |___$@@ext2~//:ext.bzl%ext ...', '| | |___repo3', - '| |___$@@ext~1.0//:ext.bzl%ext ...', + '| |___$@@ext~//:ext.bzl%ext ...', '| | |___repo3', '| |___ext@1.0 (*)', '| |___ext2@1.0 (*)', '|___foo@2.0', - ' |___$@@ext~1.0//:ext.bzl%ext ...', + ' |___$@@ext~//:ext.bzl%ext ...', ' | |___repo3', ' | |___repo4', ' |___bar@2.0 (*)', @@ -206,16 +206,16 @@ def testGraphWithExtensionFilter(self): stdout, [ ' (my_project@1.0)', - '|___$@@ext~1.0//:ext.bzl%ext', + '|___$@@ext~//:ext.bzl%ext', '| |___repo1', '|___foo@1.0 #', - '| |___$@@ext~1.0//:ext.bzl%ext', + '| |___$@@ext~//:ext.bzl%ext', '| | |___repo1', '| |___bar@2.0 #', - '| |___$@@ext~1.0//:ext.bzl%ext', + '| |___$@@ext~//:ext.bzl%ext', '| |___repo3', '|___foo@2.0 #', - ' |___$@@ext~1.0//:ext.bzl%ext', + ' |___$@@ext~//:ext.bzl%ext', ' | |___repo3', ' | |___repo4', ' |___bar@2.0 (*)', @@ -243,7 +243,7 @@ def testShowExtensionAllUsages(self): self.assertListEqual( stdout, [ - '## @@ext~1.0//:ext.bzl%ext:', + '## @@ext~//:ext.bzl%ext:', '', 'Fetched repositories:', ' - repo1 (imported by , foo@1.0)', @@ -309,7 +309,7 @@ def testShowExtensionSomeExtensionsSomeUsages(self): self.assertListEqual( stdout, [ - '## @@ext2~1.0//:ext.bzl%ext:', + '## @@ext2~//:ext.bzl%ext:', '', 'Fetched repositories:', ' - repo1 (imported by )', @@ -322,7 +322,7 @@ def testShowExtensionSomeExtensionsSomeUsages(self): ' my_repo2="repo3",', ')', '', - '## @@ext~1.0//:ext.bzl%ext:', + '## @@ext~//:ext.bzl%ext:', '', 'Fetched repositories:', ' - repo1 (imported by , foo@1.0)', @@ -379,14 +379,14 @@ def testShowModuleAndExtensionReposFromBaseModule(self): '## @bar_from_foo2:', '# ', 'http_archive(', - ' name = "bar~2.0",', + ' name = "bar~",', # pop(4) -- urls=[...] # pop(4) -- integrity=... ' strip_prefix = "",', ' remote_patches = {},', ' remote_patch_strip = 0,', ')', - '# Rule bar~2.0 instantiated at (most recent call last):', + '# Rule bar~ instantiated at (most recent call last):', '# in ', '# Rule http_archive defined at (most recent call last):', # pop(11) @@ -394,19 +394,19 @@ def testShowModuleAndExtensionReposFromBaseModule(self): '## ext@1.0:', '# ', 'local_repository(', - ' name = "ext~1.0",', + ' name = "ext~",', # pop(16) -- path=... ')', - '# Rule ext~1.0 instantiated at (most recent call last):', + '# Rule ext~ instantiated at (most recent call last):', '# in ', '', '## @my_repo3:', '# ', 'data_repo(', - ' name = "ext~1.0~ext~repo3",', + ' name = "ext~~ext~repo3",', ' data = "requested repo",', ')', - '# Rule ext~1.0~ext~repo3 instantiated at (most recent call last):', + '# Rule ext~~ext~repo3 instantiated at (most recent call last):', '# in ', '# Rule data_repo defined at (most recent call last):', # pop(29) @@ -414,10 +414,10 @@ def testShowModuleAndExtensionReposFromBaseModule(self): '## @my_repo4:', '# ', 'data_repo(', - ' name = "ext~1.0~ext~repo4",', + ' name = "ext~~ext~repo4",', ' data = "requested repo",', ')', - '# Rule ext~1.0~ext~repo4 instantiated at (most recent call last):', + '# Rule ext~~ext~repo4 instantiated at (most recent call last):', '# in ', '# Rule data_repo defined at (most recent call last):', # pop(39) @@ -425,14 +425,14 @@ def testShowModuleAndExtensionReposFromBaseModule(self): '## bar@2.0:', '# ', 'http_archive(', - ' name = "bar~2.0",', + ' name = "bar~",', # pop(44) -- urls=[...] # pop(44) -- integrity=... ' strip_prefix = "",', ' remote_patches = {},', ' remote_patch_strip = 0,', ')', - '# Rule bar~2.0 instantiated at (most recent call last):', + '# Rule bar~ instantiated at (most recent call last):', '# in ', '# Rule http_archive defined at (most recent call last):', # pop(51) @@ -471,7 +471,7 @@ def testDumpRepoMapping(self): 'my_project': '', 'foo1': 'foo~1.0', 'foo2': 'foo~2.0', - 'myrepo2': 'ext2~1.0~ext~repo1', + 'myrepo2': 'ext2~~ext~repo1', 'bazel_tools': 'bazel_tools', }.items(), root_mapping.items(), @@ -480,8 +480,8 @@ def testDumpRepoMapping(self): self.assertContainsSubset( { 'foo': 'foo~2.0', - 'ext_mod': 'ext~1.0', - 'my_repo3': 'ext~1.0~ext~repo3', + 'ext_mod': 'ext~', + 'my_repo3': 'ext~~ext~repo3', 'bazel_tools': 'bazel_tools', }.items(), foo_mapping.items(), diff --git a/src/test/shell/bazel/python_version_test.sh b/src/test/shell/bazel/python_version_test.sh index 9dc85ffb862298..5215f36592dfea 100755 --- a/src/test/shell/bazel/python_version_test.sh +++ b/src/test/shell/bazel/python_version_test.sh @@ -537,7 +537,7 @@ package_group( name = "allowed", packages = [ "//__EXTERNAL_REPOS__/external_repo/...", - "//__EXTERNAL_REPOS__/external_repo~override/...", + "//__EXTERNAL_REPOS__/external_repo~/...", "//__EXTERNAL_REPOS__/bazel_tools/...", ##"//tools/python/windows...", ],