From 1d7fd51ceab8d09858eca85cce9a16b867b8a3e2 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:22:04 +0900 Subject: [PATCH] fix(ci): use --enable_workspace for bazel-in-bazel tests (#2237) The CI on `main` started failing and is affecting all PRs. Most likely a fixup to #2184. --- .bazelversion | 2 +- CHANGELOG.md | 1 + MODULE.bazel | 2 + tests/integration/BUILD.bazel | 24 +++++- tests/integration/integration_test.bzl | 107 ++++++++++++++----------- version.bzl | 2 +- 6 files changed, 90 insertions(+), 48 deletions(-) diff --git a/.bazelversion b/.bazelversion index 66ce77b7e..a3fcc7121 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -7.0.0 +7.1.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0300824bd..1d8632f76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ A brief description of the categories of changes: * (toolchains) {obj}`py_cc_toolchain.libs` and {obj}`PyCcToolchainInfo.libs` is optional. This is to support situations where only the Python headers are available. +* (bazel) Minimum bazel 7 version that we test against has been bumped to `7.1`. ### Fixed * (whl_library): Remove `--no-index` and add `--no-build-isolation` to the diff --git a/MODULE.bazel b/MODULE.bazel index 9ac3e7a04..424b4f84c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -116,6 +116,7 @@ bazel_binaries.local( path = "tests/integration/bazel_from_env", ) bazel_binaries.download(version = "6.4.0") +bazel_binaries.download(version = "7.3.1") bazel_binaries.download(version = "rolling") use_repo( bazel_binaries, @@ -124,6 +125,7 @@ use_repo( # that should be use_repo()'d, so we add them as requested "bazel_binaries_bazelisk", "build_bazel_bazel_6_4_0", + "build_bazel_bazel_7_3_1", "build_bazel_bazel_rolling", "build_bazel_bazel_self", ) diff --git a/tests/integration/BUILD.bazel b/tests/integration/BUILD.bazel index 8724b2528..289c85d38 100644 --- a/tests/integration/BUILD.bazel +++ b/tests/integration/BUILD.bazel @@ -19,10 +19,14 @@ load(":integration_test.bzl", "rules_python_integration_test") licenses(["notice"]) -_WORKSPACE_FLAGS = [ +_LEGACY_WORKSPACE_FLAGS = [ "--noenable_bzlmod", ] +_WORKSPACE_FLAGS = _LEGACY_WORKSPACE_FLAGS + [ + "--enable_workspace", +] + _WORKSPACE_GAZELLE_PLUGIN_FLAGS = [ "--override_repository=rules_python_gazelle_plugin=../../../rules_python_gazelle_plugin", ] @@ -31,6 +35,24 @@ _GAZELLE_PLUGIN_FLAGS = [ "--override_module=rules_python_gazelle_plugin=../../../rules_python_gazelle_plugin", ] +default_test_runner( + name = "bazel_6_4_workspace_test_runner", + bazel_cmds = [ + "info {}".format(" ".join(_LEGACY_WORKSPACE_FLAGS)), + "test {} //...".format(" ".join(_LEGACY_WORKSPACE_FLAGS)), + ], + visibility = ["//visibility:public"], +) + +default_test_runner( + name = "bazel_6_4_workspace_test_runner_gazelle_plugin", + bazel_cmds = [ + "info {}".format(" ".join(_LEGACY_WORKSPACE_FLAGS + _WORKSPACE_GAZELLE_PLUGIN_FLAGS)), + "test {} //...".format(" ".join(_LEGACY_WORKSPACE_FLAGS + _WORKSPACE_GAZELLE_PLUGIN_FLAGS)), + ], + visibility = ["//visibility:public"], +) + default_test_runner( name = "workspace_test_runner", bazel_cmds = [ diff --git a/tests/integration/integration_test.bzl b/tests/integration/integration_test.bzl index 8606f66bb..c43795331 100644 --- a/tests/integration/integration_test.bzl +++ b/tests/integration/integration_test.bzl @@ -16,11 +16,40 @@ load("@bazel_binaries//:defs.bzl", "bazel_binaries") load( "@rules_bazel_integration_test//bazel_integration_test:defs.bzl", - "bazel_integration_tests", + "bazel_integration_test", "integration_test_utils", ) load("//python:py_test.bzl", "py_test") +def _test_runner(*, name, bazel_version, py_main, bzlmod, gazelle_plugin): + if py_main: + test_runner = "{}_bazel_{}_py_runner".format(name, bazel_version) + py_test( + name = test_runner, + srcs = [py_main], + main = py_main, + deps = [":runner_lib"], + # Hide from ... patterns; should only be run as part + # of the bazel integration test + tags = ["manual"], + ) + return test_runner + + if bazel_version.startswith("6") and not bzlmod: + if gazelle_plugin: + return "//tests/integration:bazel_6_4_workspace_test_runner_gazelle_plugin" + else: + return "//tests/integration:bazel_6_4_workspace_test_runner" + + if bzlmod and gazelle_plugin: + return "//tests/integration:test_runner_gazelle_plugin" + elif bzlmod: + return "//tests/integration:test_runner" + elif gazelle_plugin: + return "//tests/integration:workspace_test_runner_gazelle_plugin" + else: + return "//tests/integration:workspace_test_runner" + def rules_python_integration_test( name, workspace_path = None, @@ -48,26 +77,6 @@ def rules_python_integration_test( **kwargs: Passed to the upstream `bazel_integration_tests` rule. """ workspace_path = workspace_path or name.removesuffix("_test") - if py_main: - test_runner = name + "_py_runner" - py_test( - name = test_runner, - srcs = [py_main], - main = py_main, - deps = [":runner_lib"], - # Hide from ... patterns; should only be run as part - # of the bazel integration test - tags = ["manual"], - ) - elif bzlmod: - if gazelle_plugin: - test_runner = "//tests/integration:test_runner_gazelle_plugin" - else: - test_runner = "//tests/integration:test_runner" - elif gazelle_plugin: - test_runner = "//tests/integration:workspace_test_runner_gazelle_plugin" - else: - test_runner = "//tests/integration:workspace_test_runner" # Because glob expansion happens at loading time, the bazel-* symlinks # in the workspaces can recursively expand to tens-of-thousands of entries, @@ -89,27 +98,35 @@ def rules_python_integration_test( ], ) kwargs.setdefault("size", "enormous") - bazel_integration_tests( - name = name, - workspace_path = workspace_path, - test_runner = test_runner, - bazel_versions = bazel_versions or bazel_binaries.versions.all, - workspace_files = [name + "_workspace_files"], - # Override the tags so that the `manual` tag isn't applied. - tags = (tags or []) + [ - # These tests are very heavy weight, so much so that only a couple - # can be run in parallel without harming their reliability, - # overall runtime, and the system's stability. Unfortunately, - # there doesn't appear to be a way to tell Bazel to limit their - # concurrency, only disable it entirely with exclusive. - "exclusive", - # The default_test_runner() assumes it can write to the user's home - # directory for caching purposes. Give it access. - "no-sandbox", - # The CI RBE setup can't successfully run these tests remotely. - "no-remote-exec", - # A special tag is used so CI can run them as a separate job. - "integration-test", - ], - **kwargs - ) + for bazel_version in bazel_versions or bazel_binaries.versions.all: + test_runner = _test_runner( + name = name, + bazel_version = bazel_version, + py_main = py_main, + bzlmod = bzlmod, + gazelle_plugin = gazelle_plugin, + ) + bazel_integration_test( + name = "{}_bazel_{}".format(name, bazel_version), + workspace_path = workspace_path, + test_runner = test_runner, + bazel_version = bazel_version, + workspace_files = [name + "_workspace_files"], + # Override the tags so that the `manual` tag isn't applied. + tags = (tags or []) + [ + # These tests are very heavy weight, so much so that only a couple + # can be run in parallel without harming their reliability, + # overall runtime, and the system's stability. Unfortunately, + # there doesn't appear to be a way to tell Bazel to limit their + # concurrency, only disable it entirely with exclusive. + "exclusive", + # The default_test_runner() assumes it can write to the user's home + # directory for caching purposes. Give it access. + "no-sandbox", + # The CI RBE setup can't successfully run these tests remotely. + "no-remote-exec", + # A special tag is used so CI can run them as a separate job. + "integration-test", + ], + **kwargs + ) diff --git a/version.bzl b/version.bzl index 2e8fc0b0f..5194f3007 100644 --- a/version.bzl +++ b/version.bzl @@ -17,7 +17,7 @@ # against. # This version should be updated together with the version of Bazel # in .bazelversion. -BAZEL_VERSION = "7.0.0" +BAZEL_VERSION = "7.1.0" # NOTE: Keep in sync with .bazelci/presubmit.yml # This is the minimum supported bazel version, that we have some tests for.