From c229a18a1787fe3ca9f188c2d9115651966ebb73 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Thu, 16 Mar 2023 14:13:00 -0600 Subject: [PATCH] Update workspace_bazel_binaries to take the version values. --- WORKSPACE | 9 +++++++- .../bzlmod/workspace_bazel_binaries.bzl | 22 +++++++++++++++++++ doc/rules_and_macros_overview.md | 4 ++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 5aa7034e..73e43a76 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -30,16 +30,23 @@ buildifier_prebuilt_register_toolchains() # MARK: - Integration Tests +load( + "//:bazel_versions.bzl", + "CURRENT_BAZEL_VERSION", + "OTHER_BAZEL_VERSIONS", + "SUPPORTED_BAZEL_VERSIONS", +) load("//bazel_integration_test/bzlmod:workspace_bazel_binaries.bzl", "workspace_bazel_binaries") # This is only necessary while rules_bazel_integration_test switches back and # forth between WORKSPACE repositories and bzlmod repositories. workspace_bazel_binaries( name = "bazel_binaries", + current_version = CURRENT_BAZEL_VERSION, + other_versions = OTHER_BAZEL_VERSIONS, rbt_repo_name = "", ) -load("//:bazel_versions.bzl", "SUPPORTED_BAZEL_VERSIONS") load("//bazel_integration_test:defs.bzl", "bazel_binaries") bazel_binaries(versions = SUPPORTED_BAZEL_VERSIONS) diff --git a/bazel_integration_test/bzlmod/workspace_bazel_binaries.bzl b/bazel_integration_test/bzlmod/workspace_bazel_binaries.bzl index dda91102..62df9e7d 100644 --- a/bazel_integration_test/bzlmod/workspace_bazel_binaries.bzl +++ b/bazel_integration_test/bzlmod/workspace_bazel_binaries.bzl @@ -2,14 +2,29 @@ _BAZEL_BINARIES_HELPER_DEFS_BZL = """load("@{rbt_repo_name}//bazel_integration_test/private:integration_test_utils.bzl", "integration_test_utils") +_versions = struct( + current = "{current_version}", + other = {other_versions}, + all = {all_versions} +) + bazel_binaries = struct( label = integration_test_utils.bazel_binary_label, + versions = _versions, ) """ def _workspace_bazel_binaries_impl(repository_ctx): + current_version = repository_ctx.attr.current_version + if current_version == "": + fail("A current version must be specified.") + other_versions = repository_ctx.attr.other_versions + all_versions = sorted([current_version] + other_versions) repository_ctx.file("defs.bzl", _BAZEL_BINARIES_HELPER_DEFS_BZL.format( rbt_repo_name = repository_ctx.attr.rbt_repo_name, + current_version = current_version, + other_versions = other_versions, + all_versions = all_versions, )) repository_ctx.file("WORKSPACE") repository_ctx.file("BUILD.bazel") @@ -17,6 +32,13 @@ def _workspace_bazel_binaries_impl(repository_ctx): workspace_bazel_binaries = repository_rule( implementation = _workspace_bazel_binaries_impl, attrs = { + "current_version": attr.string( + doc = "The current version.", + mandatory = True, + ), + "other_versions": attr.string_list( + doc = "The other versions", + ), "rbt_repo_name": attr.string( doc = "The name of the rules_bazel_integration_test repo.", default = "rules_bazel_integration_test", diff --git a/doc/rules_and_macros_overview.md b/doc/rules_and_macros_overview.md index f3b8e361..c9168f71 100755 --- a/doc/rules_and_macros_overview.md +++ b/doc/rules_and_macros_overview.md @@ -49,7 +49,7 @@ default test runner is provided by the `default_test_runner` macro. | env | Optional. A dictionary of strings. Specifies additional environment variables to be passed to the test. | {} | | env_inherit | Optional. Override the env_inherit values passed to the test. Only do this if you understand what needs to be passed along. Most folks will want to use additional_env_inherit to pass additional env_inherit values. | ["SUDO_ASKPASS", "HOME", "CC"] | | additional_env_inherit | Optional. Specify additional env_inherit values that should be passed to the test. | [] | -| bazel_binaries |

-

| None | +| bazel_binaries | Optional for WORKSPACE loaded repositories. Required for repositories that enable bzlmod. The value for this parameter is loaded by adding load("@bazel_binaries//:defs.bzl", "bazel_binaries") to your build file. | None | | kwargs | additional attributes like timeout and visibility | none | @@ -78,7 +78,7 @@ Macro that defines a set Bazel integration tests each executed with a different | timeout | A valid Bazel timeout value. https://docs.bazel.build/versions/main/test-encyclopedia.html#role-of-the-test-runner | "long" | | env_inherit | Optional. Override the env_inherit values passed to the test. Only do this if you understand what needs to be passed along. Most folks will want to use additional_env_inherit to pass additional env_inherit values. | ["SUDO_ASKPASS", "HOME", "CC"] | | additional_env_inherit | Optional. Specify additional env_inherit values that should be passed to the test. | [] | -| bazel_binaries |

-

| None | +| bazel_binaries | Optional for WORKSPACE loaded repositories. Required for repositories that enable bzlmod. The value for this parameter is loaded by adding load("@bazel_binaries//:defs.bzl", "bazel_binaries") to your build file. | None | | kwargs | additional attributes like timeout and visibility | none |