Skip to content

Commit 8aaaf93

Browse files
philscrickeylev
andauthored
chore: Migrate to rules_bazel_integration_test (#1598)
This patch deletes the old copy of `bazel_integration_test` that we had vendored into the repo. It's replaced with the maintained `rules_bazel_integration_test`. Summary of changes: * Increases minimum tested bazel version to 6.4.0. rules_bazel_integration_test depends on some features in 6.4 * Moves several CI jobs to be BIT tests. This free ups about 10 CI slots. * Runs these tests under a separate CI job. This is so that feedback from the regular test jobs is faster. Notes about these bazel-in-bazel integration tests: * The tests are very heavy and easily overwhelm a system. Unfortunately, there doesn't appear to be a way to cap their parallelism; only disable it entirely using the `exclusive` tag. Some light testing shows there is some speedup to be gained on CI if we can, in the future, limit them to 2 or 4 concurrent executions. * A special version named "self" is created that re-uses whatever the outer Bazel program is. This is mainly so that Bazel's "at head" testing pipelines (the one that runs tests with Bazel built from head) are able to affect the integration tests. It also comes in handy when locally testing a custom Bazel build. * The globbing of child workspace files can be somewhat prone to following `bazel-*` symlinks, so its important the `.bazelignore` and deleted packages configs are up-to-date. Otherwise the globbing can turn into 30,000+ files and consume a system-freezing level of memory and CPU. Fixes #1209 --------- Co-authored-by: Richard Levasseur <[email protected]>
1 parent 4fee7ef commit 8aaaf93

File tree

16 files changed

+295
-60
lines changed

16 files changed

+295
-60
lines changed

.bazelci/presubmit.yml

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ buildifier:
2121
.minimum_supported_version: &minimum_supported_version
2222
# For testing minimum supported version.
2323
# NOTE: Keep in sync with //:version.bzl
24-
bazel: 6.2.0
24+
bazel: 6.4.0
2525
skip_in_bazel_downstream_pipeline: "Bazel 6 required"
2626
.reusable_config: &reusable_config
2727
build_targets:
@@ -32,6 +32,7 @@ buildifier:
3232
- "@rules_python//examples/wheel/..."
3333
build_flags:
3434
- "--keep_going"
35+
- "--build_tag_filters=-integration-test"
3536
test_targets:
3637
- "--"
3738
- "..."
@@ -42,6 +43,18 @@ buildifier:
4243
- "--noenable_bzlmod"
4344
build_flags:
4445
- "--noenable_bzlmod"
46+
.common_bazelinbazel_config: &common_bazelinbazel_config
47+
build_flags:
48+
- "--build_tag_filters=integration-test"
49+
test_flags:
50+
- "--test_tag_filters=integration-test"
51+
- "--jobs=2"
52+
# The integration tests are so expensive that only a few can be run concurrently
53+
# without harming overall reliability and runtime.
54+
- "--local_test_jobs=2"
55+
build_targets: ["..."]
56+
test_targets: ["..."]
57+
4558
.reusable_build_test_all: &reusable_build_test_all
4659
build_targets: ["..."]
4760
test_targets: ["..."]
@@ -420,19 +433,14 @@ tasks:
420433
working_directory: examples/pip_repository_annotations
421434
platform: windows
422435

423-
integration_test_compile_pip_requirements_ubuntu_min_workspace:
424-
<<: *minimum_supported_version
425-
<<: *reusable_build_test_all
426-
<<: *common_workspace_flags
427-
name: "compile_pip_requirements: Ubuntu using minimum Bazel"
428-
working_directory: tests/integration/compile_pip_requirements
429-
platform: ubuntu2004
430-
integration_test_compile_pip_requirements_ubuntu_min_bzlmod:
431-
<<: *minimum_supported_version
432-
<<: *reusable_build_test_all
433-
name: "compile_pip_requirements: Ubuntu using minimum Bazel"
434-
working_directory: tests/integration/compile_pip_requirements
436+
integration_test_bazelinbazel_ubuntu:
437+
<<: *common_bazelinbazel_config
438+
name: "tests/integration bazel-in-bazel: Ubuntu"
435439
platform: ubuntu2004
440+
integration_test_bazelinbazel_debian:
441+
<<: *common_bazelinbazel_config
442+
name: "tests/integration bazel-in-bazel: Debian"
443+
platform: debian11
436444

437445
integration_test_compile_pip_requirements_ubuntu:
438446
<<: *reusable_build_test_all
@@ -507,18 +515,6 @@ tasks:
507515
- "bazel run //:os_specific_requirements.update"
508516
- "git diff --exit-code"
509517

510-
integration_test_pip_repository_entry_points_ubuntu_workspace:
511-
<<: *reusable_build_test_all
512-
<<: *common_workspace_flags
513-
name: "pip_repository_entry_points: Ubuntu, workspace"
514-
working_directory: tests/integration/pip_repository_entry_points
515-
platform: ubuntu2004
516-
integration_test_pip_repository_entry_points_debian_workspace:
517-
<<: *reusable_build_test_all
518-
<<: *common_workspace_flags
519-
name: "pip_repository_entry_points: Debian, workspace"
520-
working_directory: tests/integration/pip_repository_entry_points
521-
platform: debian11
522518
integration_test_pip_repository_entry_points_macos_workspace:
523519
<<: *reusable_build_test_all
524520
<<: *common_workspace_flags
@@ -532,18 +528,6 @@ tasks:
532528
working_directory: tests/integration/pip_repository_entry_points
533529
platform: windows
534530

535-
integration_test_ignore_root_user_error_ubuntu_workspace:
536-
<<: *reusable_build_test_all
537-
<<: *common_workspace_flags
538-
name: "ignore_root_user_error: Ubuntu, workspace"
539-
working_directory: tests/integration/ignore_root_user_error
540-
platform: ubuntu2004
541-
integration_test_ignore_root_user_error_debian_workspace:
542-
<<: *reusable_build_test_all
543-
<<: *common_workspace_flags
544-
name: "ignore_root_user_error: Debian, workspace"
545-
working_directory: tests/integration/ignore_root_user_error
546-
platform: debian11
547531
integration_test_ignore_root_user_error_macos_workspace:
548532
<<: *reusable_build_test_all
549533
<<: *common_workspace_flags
@@ -602,4 +586,3 @@ tasks:
602586
shell_commands:
603587
# Assert that @compile_pip_requirements//:requirements_test does the right thing.
604588
- "bazel test @compile_pip_requirements//..."
605-

.bazelignore

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ bazel-testlogs
1010
# treated as directories with valid BUILD files for the main repo.
1111
# Any directory with a WORKSPACE in it should be added here, with
1212
# an entry like `bazel-{workspacename}`
13+
examples/bzlmod/bazel-bin
1314
examples/bzlmod/bazel-bzlmod
15+
examples/bzlmod/bazel-out
16+
examples/bzlmod/bazel-testlogs
17+
examples/bzlmod/other_module/bazel-bin
1418
examples/bzlmod/other_module/bazel-other_module
19+
examples/bzlmod/other_module/bazel-out
20+
examples/bzlmod/other_module/bazel-testlogs
1521
examples/bzlmod_build_file_generation/bazel-bzlmod_build_file_generation
1622
examples/multi_python_versions/bazel-multi_python_versions
1723
examples/pip_parse/bazel-pip_parse
1824
examples/pip_parse_vendored/bazel-pip_parse_vendored
1925
examples/py_proto_library/bazel-py_proto_library
20-
tests/compile_pip_requirements/bazel-compile_pip_requirements
21-
tests/ignore_root_user_error/bazel-ignore_root_user_error
22-
tests/pip_repository_entry_points/bazel-pip_repository_entry_points
26+
tests/integration/compile_pip_requirements/bazel-compile_pip_requirements
27+
tests/integration/ignore_root_user_error/bazel-ignore_root_user_error
28+
tests/integration/pip_repository_entry_points/bazel-pip_repository_entry_points

.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Trick bazel into treating BUILD files under examples/* as being regular files
33
# This lets us glob() up all the files inside the examples to make them inputs to tests
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
5-
# To update these lines, run tools/update_deleted_packages.sh
5+
# To update these lines, execute
6+
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
67
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/pip_repository_entry_points
78
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/pip_repository_entry_points
89

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
rev: 6.1.0
2121
hooks:
2222
- id: buildifier
23-
args: &args
23+
args: &args
2424
# Keep this argument in sync with .bazelci/presubmit.yaml
2525
- --warnings=all
2626
- id: buildifier-lint
@@ -30,7 +30,7 @@ repos:
3030
hooks:
3131
- id: isort
3232
name: isort (python)
33-
args:
33+
args:
3434
- --profile
3535
- black
3636
- repo: https://github.com/psf/black
@@ -42,6 +42,6 @@ repos:
4242
- id: update-deleted-packages
4343
name: Update deleted packages
4444
language: script
45-
entry: ./tools/update_deleted_packages.sh
46-
files: ^((examples|tests)/*/(MODULE.bazel|WORKSPACE|WORKSPACE.bzlmod|BUILD.bazel)|.bazelrc|tools/update_deleted_packages.sh)$
45+
entry: bazel run @rules_bazel_integration_test//tools:update_deleted_packages
46+
files: ^((examples|tests)/.*/(MODULE.bazel|WORKSPACE|WORKSPACE.bzlmod|BUILD.bazel)|.bazelrc)$
4747
pass_filenames: false

BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ filegroup(
4444
"@rules_python_gazelle_plugin//:distribution",
4545
],
4646
visibility = [
47-
"//examples:__pkg__",
48-
"//tests:__pkg__",
49-
"//tests/toolchains:__pkg__",
47+
"//:__subpackages__",
5048
],
5149
)
5250

MODULE.bazel

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ bazel_dep(name = "platforms", version = "0.0.4")
1212
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
1313
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
1414

15-
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
16-
1715
internal_deps = use_extension("@rules_python//python/private/bzlmod:internal_deps.bzl", "internal_deps")
1816
internal_deps.install()
1917
use_repo(
@@ -55,7 +53,10 @@ use_repo(python, "pythons_hub")
5553
# This call registers the Python toolchains.
5654
register_toolchains("@pythons_hub//:all")
5755

58-
# ===== DEV ONLY SETUP =====
56+
# ===== DEV ONLY DEPS AND SETUP BELOW HERE =====
57+
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
58+
bazel_dep(name = "rules_bazel_integration_test", version = "0.20.0", dev_dependency = True)
59+
5960
dev_pip = use_extension(
6061
"//python/extensions:pip.bzl",
6162
"pip",
@@ -76,3 +77,27 @@ dev_pip.parse(
7677
python_version = "3.11",
7778
requirements_lock = "//docs/sphinx:requirements.txt",
7879
)
80+
81+
bazel_binaries = use_extension(
82+
"@rules_bazel_integration_test//:extensions.bzl",
83+
"bazel_binaries",
84+
dev_dependency = True,
85+
)
86+
87+
# Keep in sync with //:version.bzl
88+
bazel_binaries.local(
89+
name = "self",
90+
path = "tests/integration/bazel_from_env",
91+
)
92+
bazel_binaries.download(version = "6.4.0")
93+
bazel_binaries.download(version = "rolling")
94+
use_repo(
95+
bazel_binaries,
96+
"bazel_binaries",
97+
# These don't appear necessary, but are reported as direct dependencies
98+
# that should be use_repo()'d, so we add them as requested
99+
"bazel_binaries_bazelisk",
100+
"build_bazel_bazel_6_4_0",
101+
"build_bazel_bazel_rolling",
102+
"build_bazel_bazel_self",
103+
)

examples/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
package(default_visibility = ["//visibility:public"])
16-
1715
licenses(["notice"]) # Apache 2.0

gazelle/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ filegroup(
2828
name = "distribution",
2929
srcs = [
3030
":BUILD.bazel",
31+
":MODULE.bazel",
3132
":README.md",
3233
":WORKSPACE",
3334
":def.bzl",

internal_deps.bzl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@ def rules_python_internal_deps():
156156
],
157157
)
158158

159+
http_archive(
160+
name = "rules_bazel_integration_test",
161+
sha256 = "6e65d497c68f5794349bfa004369e144063686ce1ebd0227717cd23285be45ef",
162+
urls = [
163+
"https://github.com/bazel-contrib/rules_bazel_integration_test/releases/download/v0.20.0/rules_bazel_integration_test.v0.20.0.tar.gz",
164+
],
165+
)
166+
167+
# Dependency of rules_bazel_integration_test.
168+
http_archive(
169+
name = "cgrindel_bazel_starlib",
170+
sha256 = "9090280a9cff7322e7c22062506b3273a2e880ca464e520b5c77fdfbed4e8805",
171+
urls = [
172+
"https://github.com/cgrindel/bazel-starlib/releases/download/v0.18.1/bazel-starlib.v0.18.1.tar.gz",
173+
],
174+
)
175+
159176
http_archive(
160177
name = "rules_proto",
161178
sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd",

internal_setup.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
"""Setup for rules_python tests and tools."""
1616

1717
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
18+
load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")
1819
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
20+
load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies")
21+
load("@rules_bazel_integration_test//bazel_integration_test:repo_defs.bzl", "bazel_binaries")
1922
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
23+
load("//:version.bzl", "SUPPORTED_BAZEL_VERSIONS")
2024
load("//python/pip_install:repositories.bzl", "pip_install_dependencies")
2125
load("//python/private:internal_config_repo.bzl", "internal_config_repo") # buildifier: disable=bzl-visibility
2226

@@ -34,3 +38,7 @@ def rules_python_internal_setup():
3438
rules_proto_toolchains()
3539

3640
protobuf_deps()
41+
42+
bazel_integration_test_rules_dependencies()
43+
bazel_starlib_dependencies()
44+
bazel_binaries(versions = SUPPORTED_BAZEL_VERSIONS)

0 commit comments

Comments
 (0)