Skip to content

Commit 50c8375

Browse files
meteorcloudycopybara-github
authored andcommitted
Enable Bzlmod in Python integration tests
Prepare for --enable_bzlmod flip: #18958 To avoid accessing BCR in integration tests, we have a default lockfile checked-in and used for tests with no MODULE.bazel file (most cases). Every time we update MODULE.tools, we should regenerate the default lockfile with `bazel run //src/test/tools/bzlmod:update_default_lock_file` PiperOrigin-RevId: 572424932 Change-Id: Ie6b3c95eae0c1306eac2d507132a9736b0b33a3e
1 parent ba3e0cc commit 50c8375

30 files changed

Lines changed: 1648 additions & 82 deletions

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ bazel_build_deps = use_extension("//:extensions.bzl", "bazel_build_deps")
247247
use_repo(
248248
bazel_build_deps,
249249
"bootstrap_repo_cache",
250+
"bazel_tools_repo_cache",
250251
"debian_cc_deps",
251252
"openjdk_linux_aarch64_vanilla",
252253
"openjdk_linux_ppc64le_vanilla",

MODULE.bazel.lock

Lines changed: 20 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

distdir.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ load("//tools/build_defs/repo:http.bzl", "http_archive", "http_file", "http_jar"
2020
_BUILD = """
2121
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
2222
23+
filegroup(
24+
name="files",
25+
srcs = {srcs},
26+
visibility = ["//visibility:public"],
27+
)
28+
2329
pkg_tar(
2430
name="archives",
25-
srcs = {srcs},
31+
srcs = [":files"],
2632
strip_prefix = "{strip_prefix}",
2733
package_dir = "{dirname}",
2834
visibility = ["//visibility:public"],

extensions.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ load("//:distdir_deps.bzl", "DIST_ARCHIVE_REPOS")
2121
load("//:repositories.bzl", "embedded_jdk_repositories")
2222
load("//src/main/res:winsdk_configure.bzl", "winsdk_configure")
2323
load("//src/test/shell/bazel:list_source_repository.bzl", "list_source_repository")
24+
load("//src/tools/bzlmod:utils.bzl", "parse_bazel_module_repos")
2425
load("//tools/distributions/debian:deps.bzl", "debian_deps")
2526

2627
### Dependencies for building Bazel
2728
def _bazel_build_deps(_ctx):
2829
embedded_jdk_repositories()
2930
debian_deps()
3031
repo_cache_tar(name = "bootstrap_repo_cache", repos = DIST_ARCHIVE_REPOS, dirname = "derived/repository_cache")
32+
BAZEL_TOOLS_DEPS_REPOS = parse_bazel_module_repos(_ctx, _ctx.path(Label("//src/test/tools/bzlmod:MODULE.bazel.lock")))
33+
repo_cache_tar(name = "bazel_tools_repo_cache", repos = BAZEL_TOOLS_DEPS_REPOS, lockfile = "//src/test/tools/bzlmod:MODULE.bazel.lock")
3134

3235
bazel_build_deps = module_extension(implementation = _bazel_build_deps)
3336

src/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ filegroup(
372372
"//src/test/shell:srcs",
373373
"//src/test/testdata/test_tls_certificate",
374374
"//src/test/tools:srcs",
375+
"//src/test/tools/bzlmod:srcs",
375376
"//src/tools/android:srcs",
376377
"//src/tools/android/java/com/google/devtools/build/android:srcs",
377378
"//src/tools/bzlmod:srcs",
@@ -586,5 +587,5 @@ filegroup(
586587
"@remotejdk%s_%s//:WORKSPACE" % (version, os)
587588
for version in ("17", "20")
588589
for os in ("macos", "macos_aarch64", "linux", "win")
589-
],
590+
] + ["@bazel_tools_repo_cache//:files"],
590591
)

src/test/py/bazel/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ py_library(
2727
data = [
2828
":default_repos_stanza.txt",
2929
":test-deps",
30+
"//src/test/tools/bzlmod:MODULE.bazel.lock",
3031
],
3132
visibility = [
3233
"//src/test/py/bazel:__pkg__",

src/test/py/bazel/bazel_windows_cpp_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ def testBuildWithClangClByCompilerFlag(self):
765765
self.assertIn('clang-cl.exe', ''.join(stderr))
766766

767767
def testBuildWithClangClByToolchainResolution(self):
768+
self.DisableBzlmod()
768769
self.CreateWorkspaceWithDefaultRepos('WORKSPACE', [
769770
'register_execution_platforms(',
770771
' ":windows_clang"',

src/test/py/bazel/bazel_workspace_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
class BazelWorkspaceTest(test_base.TestBase):
2222

23+
def setUp(self):
24+
test_base.TestBase.setUp(self)
25+
self.DisableBzlmod()
26+
2327
def testWorkspaceDotBazelFileInMainRepo(self):
2428
workspace_dot_bazel = self.ScratchFile("WORKSPACE.bazel")
2529
self.ScratchFile("BUILD", [

src/test/py/bazel/bzlmod/bazel_lockfile_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def setUp(self):
6060
# The existence of WORKSPACE.bzlmod prevents WORKSPACE prefixes or suffixes
6161
# from being used; this allows us to test built-in modules actually work
6262
self.ScratchFile('WORKSPACE.bzlmod')
63+
# TODO(pcloudy): investigate why this is needed, MODULE.bazel.lock is not
64+
# deterministic?
65+
os.remove(self.Path('MODULE.bazel.lock'))
6366

6467
def testChangeModuleInRegistryWithoutLockfile(self):
6568
# Add module 'sss' to the registry with dep on 'aaa'

src/test/py/bazel/launcher_test.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ def _buildJavaTargets(self, bazel_bin, binary_suffix):
3737
if self.IsWindows():
3838
self.assertTrue(os.path.isfile(main_binary))
3939
self.AssertRunfilesManifestContains(
40-
os.path.join(bazel_bin,
41-
'foo/foo%s.runfiles/MANIFEST' % binary_suffix),
42-
'__main__/bar/bar.txt')
40+
os.path.join(
41+
bazel_bin, 'foo/foo%s.runfiles/MANIFEST' % binary_suffix
42+
),
43+
'_main/bar/bar.txt',
44+
)
4345
else:
4446
self.assertTrue(
4547
os.path.islink(
46-
os.path.join(bazel_bin, 'foo/foo.runfiles/__main__/bar/bar.txt')))
48+
os.path.join(bazel_bin, 'foo/foo.runfiles/_main/bar/bar.txt')
49+
)
50+
)
4751

4852
_, stdout, _ = self.RunProgram([main_binary])
4953
self.assertEqual(len(stdout), 4)
@@ -99,25 +103,31 @@ def _buildShBinaryTargets(self, bazel_bin, bin1_suffix):
99103

100104
if self.IsWindows():
101105
self.AssertRunfilesManifestContains(
102-
os.path.join(bazel_bin,
103-
'foo/bin1.sh%s.runfiles/MANIFEST' % bin1_suffix),
104-
'__main__/bar/bar.txt')
106+
os.path.join(
107+
bazel_bin, 'foo/bin1.sh%s.runfiles/MANIFEST' % bin1_suffix
108+
),
109+
'_main/bar/bar.txt',
110+
)
105111
self.AssertRunfilesManifestContains(
106112
os.path.join(bazel_bin, 'foo/bin2.cmd.runfiles/MANIFEST'),
107-
'__main__/bar/bar.txt')
113+
'_main/bar/bar.txt',
114+
)
108115
else:
109116
self.assertTrue(
110117
os.path.islink(
111-
os.path.join(bazel_bin,
112-
'foo/bin1.sh.runfiles/__main__/bar/bar.txt')))
118+
os.path.join(bazel_bin, 'foo/bin1.sh.runfiles/_main/bar/bar.txt')
119+
)
120+
)
113121
self.assertTrue(
114122
os.path.islink(
115-
os.path.join(bazel_bin,
116-
'foo/bin2.cmd.runfiles/__main__/bar/bar.txt')))
123+
os.path.join(bazel_bin, 'foo/bin2.cmd.runfiles/_main/bar/bar.txt')
124+
)
125+
)
117126
self.assertTrue(
118127
os.path.islink(
119-
os.path.join(bazel_bin,
120-
'foo/bin3.bat.runfiles/__main__/bar/bar.txt')))
128+
os.path.join(bazel_bin, 'foo/bin3.bat.runfiles/_main/bar/bar.txt')
129+
)
130+
)
121131

122132
_, stdout, _ = self.RunProgram([bin1])
123133
self.assertEqual(len(stdout), 3)
@@ -155,13 +165,17 @@ def _buildPyTargets(self, bazel_bin, binary_suffix):
155165
# Verify contents of runfiles (manifest).
156166
if self.IsWindows():
157167
self.AssertRunfilesManifestContains(
158-
os.path.join(bazel_bin,
159-
'foo/foo%s.runfiles/MANIFEST' % binary_suffix),
160-
'__main__/bar/bar.txt')
168+
os.path.join(
169+
bazel_bin, 'foo/foo%s.runfiles/MANIFEST' % binary_suffix
170+
),
171+
'_main/bar/bar.txt',
172+
)
161173
else:
162174
self.assertTrue(
163175
os.path.islink(
164-
os.path.join(bazel_bin, 'foo/foo.runfiles/__main__/bar/bar.txt')))
176+
os.path.join(bazel_bin, 'foo/foo.runfiles/_main/bar/bar.txt')
177+
)
178+
)
165179

166180
# Try to run the built py_binary.
167181
_, stdout, _ = self.RunProgram([foo_bin])

0 commit comments

Comments
 (0)