From 4442f20fec6130ef4728f81d8a8d6f6204eeede4 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 22 Dec 2024 12:26:11 -0700 Subject: [PATCH] Upgrade to Bazel 8.0. --- .bazelversion | 2 +- MODULE.bazel | 10 ++-- doc/integration_test_utils.md | 32 +++++++--- doc/rules_and_macros_overview.md | 58 ++++++++++--------- .../integration_tests/workspace/BUILD.bazel | 2 + .../sample_workspace/BUILD.bazel | 2 + shared.bazelrc | 4 ++ .../workspace/child_workspace/BUILD.bazel | 2 + tests/params_tests/env_inherit_attr_test.bzl | 4 +- tests/params_tests/workspace/BUILD.bazel | 2 + tests/tools_tests/BUILD.bazel | 1 + tools/BUILD.bazel | 1 + 12 files changed, 78 insertions(+), 42 deletions(-) diff --git a/.bazelversion b/.bazelversion index 815da58b..ae9a76b9 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -7.4.1 +8.0.0 diff --git a/MODULE.bazel b/MODULE.bazel index 0c2a2bd0..cf4539ac 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -3,11 +3,11 @@ module( version = "0.0.0", ) -bazel_dep(name = "bazel_skylib", version = "1.4.1") -bazel_dep(name = "rules_python", version = "0.19.0") -bazel_dep(name = "platforms", version = "0.0.7") -bazel_dep(name = "cgrindel_bazel_starlib", version = "0.18.0") -bazel_dep(name = "rules_shell", version = "0.2.0") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_python", version = "0.40.0") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "cgrindel_bazel_starlib", version = "0.21.0") +bazel_dep(name = "rules_shell", version = "0.3.0") # not a direct dependency, but required here for bazel starlib's difftest macros to work bazel_dep( diff --git a/doc/integration_test_utils.md b/doc/integration_test_utils.md index 38a7d15b..287509a2 100755 --- a/doc/integration_test_utils.md +++ b/doc/integration_test_utils.md @@ -7,6 +7,8 @@ ## integration_test_utils.bazel_binary_label
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")
+
 integration_test_utils.bazel_binary_label(version)
 
@@ -17,7 +19,7 @@ Returns a label for the specified Bazel version as provided by https://github.co | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| version | A string value representing the semantic version of Bazel to use for the integration test. | none | +| version | A `string` value representing the semantic version of Bazel to use for the integration test. | none | **RETURNS** @@ -29,6 +31,8 @@ A `string` representing a label for a version of Bazel. ## integration_test_utils.bazel_binary_repo_name
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")
+
 integration_test_utils.bazel_binary_repo_name(version)
 
@@ -39,7 +43,7 @@ Generates a Bazel binary repository name for the specified version. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| version | A string that represents a Bazel version or a label. | none | +| version | A `string` that represents a Bazel version or a label. | none | **RETURNS** @@ -51,6 +55,8 @@ A `string` that is suitable for use as a repository name. ## integration_test_utils.bazel_integration_test_name
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")
+
 integration_test_utils.bazel_integration_test_name(name, version)
 
@@ -61,8 +67,8 @@ Generates a test name from the provided base name and the Bazel version. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| name | The base name as a string. | none | -| version | The Bazel semantic version as a string. | none | +| name | The base name as a `string`. | none | +| version | The Bazel semantic version as a `string`. | none | **RETURNS** @@ -74,6 +80,8 @@ A `string` that is suitable as an integration test name. ## integration_test_utils.bazel_integration_test_names
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")
+
 integration_test_utils.bazel_integration_test_names(name, versions)
 
@@ -84,8 +92,8 @@ Generates a `list` of integration test names based upon the provided base name a | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| name | The base name as a string. | none | -| versions | A list of semantic version string values. | [] | +| name | The base name as a `string`. | none | +| versions | A `list` of semantic version `string` values. | `[]` | **RETURNS** @@ -97,6 +105,8 @@ A `list` of integration test names as `string` values. ## integration_test_utils.glob_workspace_files
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")
+
 integration_test_utils.glob_workspace_files(workspace_path)
 
@@ -107,7 +117,7 @@ Recursively globs the Bazel workspace files at the specified path. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| workspace_path | A string representing the path to glob. | none | +| workspace_path | A `string` representing the path to glob. | none | **RETURNS** @@ -120,6 +130,8 @@ A `list` of the files under the specified path ignoring certain Bazel ## integration_test_utils.is_version_file
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")
+
 integration_test_utils.is_version_file(version)
 
@@ -130,7 +142,7 @@ Determines if the version string is a reference to a version file. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| version | A string that represents a Bazel version or a label. | none | +| version | A `string` that represents a Bazel version or a label. | none | **RETURNS** @@ -142,6 +154,8 @@ A `bool` the specifies whether the string is a file reference. ## integration_test_utils.semantic_version_to_name
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")
+
 integration_test_utils.semantic_version_to_name(version)
 
@@ -152,7 +166,7 @@ Converts a semantic version string (e.g. X.Y.Z) to a suitable name string (e.g. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| version | A semantic version string. | none | +| version | A semantic version `string`. | none | **RETURNS** diff --git a/doc/rules_and_macros_overview.md b/doc/rules_and_macros_overview.md index cd62f9f1..2b36521e 100755 --- a/doc/rules_and_macros_overview.md +++ b/doc/rules_and_macros_overview.md @@ -16,6 +16,8 @@ On this page: ## default_test_runner
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "default_test_runner")
+
 default_test_runner(name, bazel_cmds)
 
@@ -27,7 +29,7 @@ default_test_runner(name, name | A unique name for this target. | Name | required | | -| bazel_cmds | The Bazel commands to be executed by the test runner in the test workspace. | List of strings | optional | ["info", "test //..."] | +| bazel_cmds | The Bazel commands to be executed by the test runner in the test workspace. | List of strings | optional | `["info", "test //..."]` | @@ -35,9 +37,11 @@ default_test_runner(name, name, test_runner, bazel_version, bazel_binary, workspace_path, workspace_files, tags, timeout, env, env_inherit, additional_env_inherit, - bazel_binaries, data, startup_options, kwargs) + bazel_binaries, data, startup_options, **kwargs) Macro that defines a set of targets for a single Bazel integration test. @@ -58,19 +62,19 @@ default test runner is provided by the `default_test_runner` macro. | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | name of the resulting py_test | none | -| test_runner | A Label for a test runner binary. (see description for details) | none | -| bazel_version | Optional. A string value representing the semantic version of Bazel to use for the integration test. If a version is not specified, then the bazel_binary must be specified. | None | -| bazel_binary | Optional. A Label for the Bazel binary to use for the execution of the integration test. Most users will not use this attribute. Use the bazel_version instead. | None | -| workspace_path | Optional. A string specifying the relative path to the child workspace. If not specified, then it is derived from the name. | None | -| workspace_files | Optional. A list of files for the child workspace. If not specified, then it is derived from the workspace_path. | None | -| tags | The Bazel tags to apply to the test declaration. | ["exclusive", "manual"] | -| timeout | A valid Bazel timeout value. https://docs.bazel.build/versions/main/test-encyclopedia.html#role-of-the-test-runner | "long" | -| env | Optional. A dictionary of strings. Specifies additional environment variables to be passed to the test. | None | -| 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 | 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 | -| data | Optional. A list of files to make present at test runtime. | None | -| startup_options | Optional. Flags that should be passed to Bazel as startup options using the BIT_STARTUP_OPTIONS environment variable. | "" | +| test_runner | A `Label` for a test runner binary. (see description for details) | none | +| bazel_version | Optional. A `string` value representing the semantic version of Bazel to use for the integration test. If a version is not specified, then the `bazel_binary` must be specified. | `None` | +| bazel_binary | Optional. A `Label` for the Bazel binary to use for the execution of the integration test. Most users will not use this attribute. Use the `bazel_version` instead. | `None` | +| workspace_path | Optional. A `string` specifying the relative path to the child workspace. If not specified, then it is derived from the name. | `None` | +| workspace_files | Optional. A `list` of files for the child workspace. If not specified, then it is derived from the `workspace_path`. | `None` | +| tags | The Bazel tags to apply to the test declaration. | `["exclusive", "manual"]` | +| timeout | A valid Bazel timeout value. https://docs.bazel.build/versions/main/test-encyclopedia.html#role-of-the-test-runner | `"long"` | +| env | Optional. A dictionary of `strings`. Specifies additional environment variables to be passed to the test. | `None` | +| 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 | 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` | +| data | Optional. A list of files to make present at test runtime. | `None` | +| startup_options | Optional. Flags that should be passed to Bazel as startup options using the `BIT_STARTUP_OPTIONS` environment variable. | `""` | | kwargs | additional attributes like timeout and visibility | none | @@ -79,9 +83,11 @@ default test runner is provided by the `default_test_runner` macro. ## bazel_integration_tests
+load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_integration_tests")
+
 bazel_integration_tests(name, test_runner, bazel_versions, workspace_path, workspace_files, tags,
                         timeout, env_inherit, additional_env_inherit, bazel_binaries, startup_options,
-                        kwargs)
+                        **kwargs)
 
Macro that defines a set Bazel integration tests each executed with a different version of Bazel. @@ -92,16 +98,16 @@ Macro that defines a set Bazel integration tests each executed with a different | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | name of the resulting py_test | none | -| test_runner | A Label for a test runner binary. | none | -| bazel_versions | A list of string string values representing the semantic versions of Bazel to use for the integration tests. | [] | -| workspace_path | A string specifying the path to the child workspace. If not specified, then it is derived from the name. | None | -| workspace_files | Optional. A list of files for the child workspace. If not specified, then it is derived from the workspace_path. | None | -| tags | The Bazel tags to apply to the test declaration. | ["exclusive", "manual"] | -| 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 | 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 | -| startup_options | Optional. Flags that should be passed to Bazel as startup options using the BIT_STARTUP_OPTIONS environment variable. | "" | +| test_runner | A `Label` for a test runner binary. | none | +| bazel_versions | A `list` of `string` string values representing the semantic versions of Bazel to use for the integration tests. | `[]` | +| workspace_path | A `string` specifying the path to the child workspace. If not specified, then it is derived from the name. | `None` | +| workspace_files | Optional. A `list` of files for the child workspace. If not specified, then it is derived from the `workspace_path`. | `None` | +| tags | The Bazel tags to apply to the test declaration. | `["exclusive", "manual"]` | +| 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 | 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` | +| startup_options | Optional. Flags that should be passed to Bazel as startup options using the `BIT_STARTUP_OPTIONS` environment variable. | `""` | | kwargs | additional attributes like timeout and visibility | none | diff --git a/examples/custom_test_runner/integration_tests/workspace/BUILD.bazel b/examples/custom_test_runner/integration_tests/workspace/BUILD.bazel index 1c7d8404..6cfd71a2 100644 --- a/examples/custom_test_runner/integration_tests/workspace/BUILD.bazel +++ b/examples/custom_test_runner/integration_tests/workspace/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_shell//shell:sh_test.bzl", "sh_test") + sh_test( name = "foo_test", srcs = ["foo_test.sh"], diff --git a/examples/env_var_with_rootpath/sample_workspace/BUILD.bazel b/examples/env_var_with_rootpath/sample_workspace/BUILD.bazel index 2c7b824c..3a4c9ccb 100644 --- a/examples/env_var_with_rootpath/sample_workspace/BUILD.bazel +++ b/examples/env_var_with_rootpath/sample_workspace/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_shell//shell:sh_test.bzl", "sh_test") + sh_test( name = "test", srcs = ["test.sh"], diff --git a/shared.bazelrc b/shared.bazelrc index b4788b01..04081ade 100644 --- a/shared.bazelrc +++ b/shared.bazelrc @@ -19,3 +19,7 @@ startup --windows_enable_symlinks # this library requires runfiles for the bzlformat_lint_test # but this is off by default on windows. Switch it on. common --enable_runfiles + +# # Do not autoload any modules. +# build --incompatible_autoload_externally= + diff --git a/tests/e2e_tests/workspace/child_workspace/BUILD.bazel b/tests/e2e_tests/workspace/child_workspace/BUILD.bazel index 35a19d64..f963a0cd 100644 --- a/tests/e2e_tests/workspace/child_workspace/BUILD.bazel +++ b/tests/e2e_tests/workspace/child_workspace/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_shell//shell:sh_test.bzl", "sh_test") + sh_test( name = "child_test", srcs = ["child_test.sh"], diff --git a/tests/params_tests/env_inherit_attr_test.bzl b/tests/params_tests/env_inherit_attr_test.bzl index 91df9119..ca1577f0 100644 --- a/tests/params_tests/env_inherit_attr_test.bzl +++ b/tests/params_tests/env_inherit_attr_test.bzl @@ -1,5 +1,7 @@ """Macro for asserting the existence of `env_inherit` values.""" +load("@rules_shell//shell:sh_test.bzl", "sh_test") + def env_inherit_attr_test(name, integration_test, expected_values): """Test for the existence of the specified values for a test target's `env_inherit` attribute. @@ -20,7 +22,7 @@ def env_inherit_attr_test(name, integration_test, expected_values): scope = [integration_test], ) - native.sh_test( + sh_test( name = name, srcs = ["env_inherit_attr_test.sh"], args = [ diff --git a/tests/params_tests/workspace/BUILD.bazel b/tests/params_tests/workspace/BUILD.bazel index 08b8645e..aad1e80d 100644 --- a/tests/params_tests/workspace/BUILD.bazel +++ b/tests/params_tests/workspace/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_shell//shell:sh_test.bzl", "sh_test") + sh_test( name = "noop_test", srcs = ["noop_test.sh"], diff --git a/tests/tools_tests/BUILD.bazel b/tests/tools_tests/BUILD.bazel index 9bf57f54..4286e014 100644 --- a/tests/tools_tests/BUILD.bazel +++ b/tests/tools_tests/BUILD.bazel @@ -1,4 +1,5 @@ load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load("@rules_shell//shell:sh_library.bzl", "sh_library") load("@rules_shell//shell:sh_test.bzl", "sh_test") bzlformat_pkg(name = "bzlformat") diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index a47a4569..70a4cfa1 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -1,5 +1,6 @@ load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") load("@rules_shell//shell:sh_binary.bzl", "sh_binary") +load("@rules_shell//shell:sh_library.bzl", "sh_library") exports_files(["fake_bazel.sh"])