From 126e4436f4c98b6e236ea3f9b82a2ef3dea0b62b Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 22 Dec 2024 12:26:11 -0700 Subject: [PATCH 1/7] 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"]) From 39cc2e94bf85e76aeb4d88a61182c082820a16a5 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 25 Dec 2024 13:05:38 -0700 Subject: [PATCH 2/7] Export the Bazelisk API once it is found. Subsequent calls cannot always see the runfiles for bazel_binary. --- .../private/bazel_binaries_script.template | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bazel_integration_test/private/bazel_binaries_script.template b/bazel_integration_test/private/bazel_binaries_script.template index a7cccdde..69e976b3 100644 --- a/bazel_integration_test/private/bazel_binaries_script.template +++ b/bazel_integration_test/private/bazel_binaries_script.template @@ -1,4 +1,5 @@ #!/bin/bash +# vi: ft=sh # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. @@ -8,16 +9,21 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- export USE_BAZEL_VERSION="{version}" -# Need to write data here, the default is read-obly inside tests. -export BAZELISK_HOME="${PWD}" +# Need to write data here, the default is read-only inside tests. +if [[ -z "${BAZELISK_HOME:-}" ]]; then + export BAZELISK_HOME="${PWD}" +fi -# Find the bazelisk binary. -BINARY="$(rlocation {bazelisk})" || \ - (echo >&2 "Failed to locate bazelisk at {bazelisk}" && exit 1) +# Find the bazelisk binary, if it has not already been found. +if [[ -z "${BAZELISK_BINARY:-}" ]]; then + BAZELISK_BINARY="$(rlocation {bazelisk})" || \ + (echo >&2 "Failed to locate bazelisk at {bazelisk}" && exit 1) + export BAZELISK_BINARY +fi -exec "${BINARY}" ${BIT_STARTUP_OPTIONS:-} "$@" +exec "${BAZELISK_BINARY}" ${BIT_STARTUP_OPTIONS:-} "$@" From 482942754eb21d92320229e01a9c832ba6a77ca5 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 25 Dec 2024 13:07:04 -0700 Subject: [PATCH 3/7] Add better error message when runfiles cannot be found. --- bazel_integration_test/bzlmod/e2e_test_runner.sh | 2 +- examples/dynamic_workspace_test_runner.sh | 2 +- examples/local_bazel_binary_test.sh | 2 +- examples/sample_script_test.sh | 2 +- examples/use_create_scratch_dir_test.sh | 2 +- release/archive_test_runner.sh | 2 +- tests/params_tests/env_inherit_attr_test.sh | 2 +- tests/tools_tests/create_scratch_dir_test.sh | 2 +- tests/tools_tests/find_child_workspace_packages_test.sh | 2 +- tests/tools_tests/remove_child_wksp_bazel_symlinks_test.sh | 2 +- tests/tools_tests/shared_fns_tests/find_any_file_test.sh | 2 +- tests/tools_tests/shared_fns_tests/find_workspace_dirs_test.sh | 2 +- tests/tools_tests/update_deleted_packages_test.sh | 2 +- tools/create_scratch_dir.sh | 2 +- tools/find_child_workspace_packages.sh | 2 +- tools/remove_child_wksp_bazel_symlinks.sh | 2 +- tools/update_deleted_packages.sh | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bazel_integration_test/bzlmod/e2e_test_runner.sh b/bazel_integration_test/bzlmod/e2e_test_runner.sh index f0eb7fa2..0a953fde 100755 --- a/bazel_integration_test/bzlmod/e2e_test_runner.sh +++ b/bazel_integration_test/bzlmod/e2e_test_runner.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- diff --git a/examples/dynamic_workspace_test_runner.sh b/examples/dynamic_workspace_test_runner.sh index f0eb7fa2..0a953fde 100755 --- a/examples/dynamic_workspace_test_runner.sh +++ b/examples/dynamic_workspace_test_runner.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- diff --git a/examples/local_bazel_binary_test.sh b/examples/local_bazel_binary_test.sh index 64849283..0adeb604 100755 --- a/examples/local_bazel_binary_test.sh +++ b/examples/local_bazel_binary_test.sh @@ -9,7 +9,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -o errexit + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -o errexit # --- end runfiles.bash initialization v2 --- # MARK - Locate Deps diff --git a/examples/sample_script_test.sh b/examples/sample_script_test.sh index 91053df7..66ff19d3 100755 --- a/examples/sample_script_test.sh +++ b/examples/sample_script_test.sh @@ -12,7 +12,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- # Use shlib assertions for testing. diff --git a/examples/use_create_scratch_dir_test.sh b/examples/use_create_scratch_dir_test.sh index 2ee194f5..19156b14 100755 --- a/examples/use_create_scratch_dir_test.sh +++ b/examples/use_create_scratch_dir_test.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- assertions_sh_location=cgrindel_bazel_starlib/shlib/lib/assertions.sh diff --git a/release/archive_test_runner.sh b/release/archive_test_runner.sh index 8321bb4d..2d818673 100755 --- a/release/archive_test_runner.sh +++ b/release/archive_test_runner.sh @@ -9,7 +9,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -o errexit + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -o errexit # --- end runfiles.bash initialization v2 --- # MARK - Locate Deps diff --git a/tests/params_tests/env_inherit_attr_test.sh b/tests/params_tests/env_inherit_attr_test.sh index 1a1991f3..cbf59559 100755 --- a/tests/params_tests/env_inherit_attr_test.sh +++ b/tests/params_tests/env_inherit_attr_test.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- # MARK - Locate Deps diff --git a/tests/tools_tests/create_scratch_dir_test.sh b/tests/tools_tests/create_scratch_dir_test.sh index 8f02ac94..efe07eab 100755 --- a/tests/tools_tests/create_scratch_dir_test.sh +++ b/tests/tools_tests/create_scratch_dir_test.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- assertions_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/assertions.sh)" diff --git a/tests/tools_tests/find_child_workspace_packages_test.sh b/tests/tools_tests/find_child_workspace_packages_test.sh index d7b41cc0..88b0a9eb 100755 --- a/tests/tools_tests/find_child_workspace_packages_test.sh +++ b/tests/tools_tests/find_child_workspace_packages_test.sh @@ -9,7 +9,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- assertions_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/assertions.sh)" diff --git a/tests/tools_tests/remove_child_wksp_bazel_symlinks_test.sh b/tests/tools_tests/remove_child_wksp_bazel_symlinks_test.sh index 16fe799c..2098467e 100755 --- a/tests/tools_tests/remove_child_wksp_bazel_symlinks_test.sh +++ b/tests/tools_tests/remove_child_wksp_bazel_symlinks_test.sh @@ -9,7 +9,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -o errexit + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -o errexit # --- end runfiles.bash initialization v2 --- # MARK - Locate Deps diff --git a/tests/tools_tests/shared_fns_tests/find_any_file_test.sh b/tests/tools_tests/shared_fns_tests/find_any_file_test.sh index afcb7f18..7ee7b918 100755 --- a/tests/tools_tests/shared_fns_tests/find_any_file_test.sh +++ b/tests/tools_tests/shared_fns_tests/find_any_file_test.sh @@ -9,7 +9,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -o errexit + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -o errexit # --- end runfiles.bash initialization v2 --- # MARK - Locate Deps diff --git a/tests/tools_tests/shared_fns_tests/find_workspace_dirs_test.sh b/tests/tools_tests/shared_fns_tests/find_workspace_dirs_test.sh index 9112cf0a..78e51581 100755 --- a/tests/tools_tests/shared_fns_tests/find_workspace_dirs_test.sh +++ b/tests/tools_tests/shared_fns_tests/find_workspace_dirs_test.sh @@ -9,7 +9,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -o errexit + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -o errexit # --- end runfiles.bash initialization v2 --- # MARK - Locate Deps diff --git a/tests/tools_tests/update_deleted_packages_test.sh b/tests/tools_tests/update_deleted_packages_test.sh index 0166cf24..70e6c615 100755 --- a/tests/tools_tests/update_deleted_packages_test.sh +++ b/tests/tools_tests/update_deleted_packages_test.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- assertions_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/assertions.sh)" diff --git a/tools/create_scratch_dir.sh b/tools/create_scratch_dir.sh index ce011e09..5c3e0ad3 100755 --- a/tools/create_scratch_dir.sh +++ b/tools/create_scratch_dir.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- diff --git a/tools/find_child_workspace_packages.sh b/tools/find_child_workspace_packages.sh index 136f8298..2c00ccf6 100755 --- a/tools/find_child_workspace_packages.sh +++ b/tools/find_child_workspace_packages.sh @@ -16,7 +16,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- arrays_lib="$(rlocation cgrindel_bazel_starlib/shlib/lib/arrays.sh)" diff --git a/tools/remove_child_wksp_bazel_symlinks.sh b/tools/remove_child_wksp_bazel_symlinks.sh index 7388f456..241d34a0 100755 --- a/tools/remove_child_wksp_bazel_symlinks.sh +++ b/tools/remove_child_wksp_bazel_symlinks.sh @@ -8,7 +8,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -o errexit + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -o errexit # --- end runfiles.bash initialization v2 --- # MARK - Locate Deps diff --git a/tools/update_deleted_packages.sh b/tools/update_deleted_packages.sh index 259155f0..e375f0c6 100755 --- a/tools/update_deleted_packages.sh +++ b/tools/update_deleted_packages.sh @@ -23,7 +23,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v2 --- find_pkgs_script="$(rlocation rules_bazel_integration_test/tools/find_child_workspace_packages.sh)" From 9717398083d2403469278baa2699c6283a0887ac Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 25 Dec 2024 13:34:11 -0700 Subject: [PATCH 4/7] Add missing rules_shell declarations. --- .../private/bazel_binaries_script.template | 37 +++++---- examples/custom_test_runner/WORKSPACE | 83 +------------------ .../integration_tests/workspace/MODULE.bazel | 12 +-- .../integration_tests/workspace/WORKSPACE | 2 +- .../sample_workspace/MODULE.bazel | 1 + .../sample_workspace/WORKSPACE.bazel | 1 + examples/simple/WORKSPACE | 30 +------ .../workspace/child_workspace/MODULE.bazel | 2 + tests/params_tests/workspace/MODULE.bazel | 7 +- 9 files changed, 36 insertions(+), 139 deletions(-) create mode 100644 examples/env_var_with_rootpath/sample_workspace/MODULE.bazel diff --git a/bazel_integration_test/private/bazel_binaries_script.template b/bazel_integration_test/private/bazel_binaries_script.template index 69e976b3..d5dfa3d1 100644 --- a/bazel_integration_test/private/bazel_binaries_script.template +++ b/bazel_integration_test/private/bazel_binaries_script.template @@ -1,17 +1,6 @@ #!/bin/bash # vi: ft=sh -# --- begin runfiles.bash initialization v2 --- -# Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- - export USE_BAZEL_VERSION="{version}" # Need to write data here, the default is read-only inside tests. @@ -20,10 +9,28 @@ if [[ -z "${BAZELISK_HOME:-}" ]]; then fi # Find the bazelisk binary, if it has not already been found. -if [[ -z "${BAZELISK_BINARY:-}" ]]; then - BAZELISK_BINARY="$(rlocation {bazelisk})" || \ +# +# Code that uses cgrindel/bazel-starlib's updatesrc utilities can execute Bazel +# invocations from directories that cannot find the runfiles. The first +# invocation will find the BIT_BAZELISK_BINARY. So, we export the value so that +# subsequent invocations can find it. This allows us to forgo the runfiles +# evaluation for this script in those cases. +if [[ -z "${BIT_BAZELISK_BINARY:-}" ]]; then + # --- begin runfiles.bash initialization v2 --- + # Copy-pasted from the Bazel Bash runfiles library v2. + set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash + # shellcheck disable=SC1090 + source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ + source "$0.runfiles/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + { echo>&2 "ERROR: ${BASH_SOURCE[0]} cannot find $f"; exit 1; }; f=; set -e + # --- end runfiles.bash initialization v2 --- + + BIT_BAZELISK_BINARY="$(rlocation {bazelisk})" || \ (echo >&2 "Failed to locate bazelisk at {bazelisk}" && exit 1) - export BAZELISK_BINARY + export BIT_BAZELISK_BINARY fi -exec "${BAZELISK_BINARY}" ${BIT_STARTUP_OPTIONS:-} "$@" +exec "${BIT_BAZELISK_BINARY}" ${BIT_STARTUP_OPTIONS:-} "$@" diff --git a/examples/custom_test_runner/WORKSPACE b/examples/custom_test_runner/WORKSPACE index 05d1e672..a2e29e87 100644 --- a/examples/custom_test_runner/WORKSPACE +++ b/examples/custom_test_runner/WORKSPACE @@ -1,82 +1 @@ -workspace(name = "custom_test_runner_example") - -# MARK: - rules_bazel_integration_test - -local_repository( - name = "rules_bazel_integration_test", - path = "../..", -) - -load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies") - -bazel_integration_test_rules_dependencies() - -load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") - -bazel_starlib_dependencies() - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries") - -bazel_binaries(versions = ["//:.bazelversion"]) - -# MARK: - rules_swift and swift_bazel - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "rules_swift_package_manager", - sha256 = "17319e76637ecfd0f8f8081fa9d08feec225f883170b6bd55ad1a4182dfb5466", - urls = [ - "https://github.com/cgrindel/rules_swift_package_manager/releases/download/v0.43.0/rules_swift_package_manager.v0.43.0.tar.gz", - ], -) - -load("@rules_swift_package_manager//:deps.bzl", "swift_bazel_dependencies") - -swift_bazel_dependencies() - -http_archive( - name = "build_bazel_rules_swift", - sha256 = "5bb49e7a1764f3f227677c572d6487b5bfeb2613eaaae2a82b240d9b836a0b4e", - url = "https://github.com/bazelbuild/rules_swift/releases/download/2.3.1/rules_swift.2.3.1.tar.gz", -) - -load("//:swift_deps.bzl", "swift_dependencies") - -# gazelle:repository_macro swift_deps.bzl%swift_dependencies -swift_dependencies() - -load( - "@build_bazel_rules_swift//swift:repositories.bzl", - "swift_rules_dependencies", -) - -swift_rules_dependencies() - -load( - "@build_bazel_rules_swift//swift:extras.bzl", - "swift_rules_extra_dependencies", -) - -swift_rules_extra_dependencies() - -# MARK: - Gazelle - -# gazelle:repo bazel_gazelle - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -load("@rules_swift_package_manager//:go_deps.bzl", "swift_bazel_go_dependencies") - -# Declare Go dependencies before calling go_rules_dependencies. -swift_bazel_go_dependencies() - -go_rules_dependencies() - -go_register_toolchains(version = "1.19.1") - -gazelle_dependencies() +# Intentionally blank. diff --git a/examples/custom_test_runner/integration_tests/workspace/MODULE.bazel b/examples/custom_test_runner/integration_tests/workspace/MODULE.bazel index 00bb1836..71ff01b8 100644 --- a/examples/custom_test_runner/integration_tests/workspace/MODULE.bazel +++ b/examples/custom_test_runner/integration_tests/workspace/MODULE.bazel @@ -1,6 +1,6 @@ -############################################################################### -# Bazel now uses Bzlmod by default to manage external dependencies. -# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. -# -# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 -############################################################################### +module( + name = "test_workspace", + version = "0.0.0", +) + +bazel_dep(name = "rules_shell", version = "0.3.0") diff --git a/examples/custom_test_runner/integration_tests/workspace/WORKSPACE b/examples/custom_test_runner/integration_tests/workspace/WORKSPACE index f04d2d05..a2e29e87 100644 --- a/examples/custom_test_runner/integration_tests/workspace/WORKSPACE +++ b/examples/custom_test_runner/integration_tests/workspace/WORKSPACE @@ -1 +1 @@ -workspace(name = "test_workspace") +# Intentionally blank. diff --git a/examples/env_var_with_rootpath/sample_workspace/MODULE.bazel b/examples/env_var_with_rootpath/sample_workspace/MODULE.bazel new file mode 100644 index 00000000..1038a534 --- /dev/null +++ b/examples/env_var_with_rootpath/sample_workspace/MODULE.bazel @@ -0,0 +1 @@ +bazel_dep(name = "rules_shell", version = "0.3.0") diff --git a/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel b/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel index e69de29b..a2e29e87 100644 --- a/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel +++ b/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel @@ -0,0 +1 @@ +# Intentionally blank. diff --git a/examples/simple/WORKSPACE b/examples/simple/WORKSPACE index 38c84730..a2e29e87 100644 --- a/examples/simple/WORKSPACE +++ b/examples/simple/WORKSPACE @@ -1,29 +1 @@ -workspace(name = "simple_example") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "cgrindel_bazel_starlib", - sha256 = "43e375213dabe0c3928e65412ea7ec16850db93285c8c6f8b0eaa41cacd0f882", - urls = [ - "https://github.com/cgrindel/bazel-starlib/releases/download/v0.21.0/bazel-starlib.v0.21.0.tar.gz", - ], -) - -load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") - -bazel_starlib_dependencies() - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -# Buildifier Dependencies - -load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") - -buildifier_prebuilt_deps() - -load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") - -buildifier_prebuilt_register_toolchains() +# Intentionally blank. diff --git a/tests/e2e_tests/workspace/child_workspace/MODULE.bazel b/tests/e2e_tests/workspace/child_workspace/MODULE.bazel index aedea8b1..efc6fde3 100644 --- a/tests/e2e_tests/workspace/child_workspace/MODULE.bazel +++ b/tests/e2e_tests/workspace/child_workspace/MODULE.bazel @@ -2,3 +2,5 @@ module( name = "e2e_child", version = "0.0.0", ) + +bazel_dep(name = "rules_shell", version = "0.3.0") diff --git a/tests/params_tests/workspace/MODULE.bazel b/tests/params_tests/workspace/MODULE.bazel index 00bb1836..1038a534 100644 --- a/tests/params_tests/workspace/MODULE.bazel +++ b/tests/params_tests/workspace/MODULE.bazel @@ -1,6 +1 @@ -############################################################################### -# Bazel now uses Bzlmod by default to manage external dependencies. -# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. -# -# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 -############################################################################### +bazel_dep(name = "rules_shell", version = "0.3.0") From 20479f7a5373c9155e319afb261a954e90f2c03d Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 25 Dec 2024 13:47:31 -0700 Subject: [PATCH 5/7] Revert removal of legacy workspace stuff. --- examples/custom_test_runner/WORKSPACE | 83 ++++++++++++++++++- .../integration_tests/workspace/WORKSPACE | 17 +++- .../sample_workspace/WORKSPACE.bazel | 15 +++- examples/simple/WORKSPACE | 43 +++++++++- 4 files changed, 154 insertions(+), 4 deletions(-) diff --git a/examples/custom_test_runner/WORKSPACE b/examples/custom_test_runner/WORKSPACE index a2e29e87..05d1e672 100644 --- a/examples/custom_test_runner/WORKSPACE +++ b/examples/custom_test_runner/WORKSPACE @@ -1 +1,82 @@ -# Intentionally blank. +workspace(name = "custom_test_runner_example") + +# MARK: - rules_bazel_integration_test + +local_repository( + name = "rules_bazel_integration_test", + path = "../..", +) + +load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies") + +bazel_integration_test_rules_dependencies() + +load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") + +bazel_starlib_dependencies() + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries") + +bazel_binaries(versions = ["//:.bazelversion"]) + +# MARK: - rules_swift and swift_bazel + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_swift_package_manager", + sha256 = "17319e76637ecfd0f8f8081fa9d08feec225f883170b6bd55ad1a4182dfb5466", + urls = [ + "https://github.com/cgrindel/rules_swift_package_manager/releases/download/v0.43.0/rules_swift_package_manager.v0.43.0.tar.gz", + ], +) + +load("@rules_swift_package_manager//:deps.bzl", "swift_bazel_dependencies") + +swift_bazel_dependencies() + +http_archive( + name = "build_bazel_rules_swift", + sha256 = "5bb49e7a1764f3f227677c572d6487b5bfeb2613eaaae2a82b240d9b836a0b4e", + url = "https://github.com/bazelbuild/rules_swift/releases/download/2.3.1/rules_swift.2.3.1.tar.gz", +) + +load("//:swift_deps.bzl", "swift_dependencies") + +# gazelle:repository_macro swift_deps.bzl%swift_dependencies +swift_dependencies() + +load( + "@build_bazel_rules_swift//swift:repositories.bzl", + "swift_rules_dependencies", +) + +swift_rules_dependencies() + +load( + "@build_bazel_rules_swift//swift:extras.bzl", + "swift_rules_extra_dependencies", +) + +swift_rules_extra_dependencies() + +# MARK: - Gazelle + +# gazelle:repo bazel_gazelle + +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@rules_swift_package_manager//:go_deps.bzl", "swift_bazel_go_dependencies") + +# Declare Go dependencies before calling go_rules_dependencies. +swift_bazel_go_dependencies() + +go_rules_dependencies() + +go_register_toolchains(version = "1.19.1") + +gazelle_dependencies() diff --git a/examples/custom_test_runner/integration_tests/workspace/WORKSPACE b/examples/custom_test_runner/integration_tests/workspace/WORKSPACE index a2e29e87..7fe687ae 100644 --- a/examples/custom_test_runner/integration_tests/workspace/WORKSPACE +++ b/examples/custom_test_runner/integration_tests/workspace/WORKSPACE @@ -1 +1,16 @@ -# Intentionally blank. +workspace(name = "test_workspace") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_shell", + sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53", + strip_prefix = "rules_shell-0.3.0", + url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz", +) + +load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains") + +rules_shell_dependencies() + +rules_shell_toolchains() diff --git a/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel b/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel index a2e29e87..1935e554 100644 --- a/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel +++ b/examples/env_var_with_rootpath/sample_workspace/WORKSPACE.bazel @@ -1 +1,14 @@ -# Intentionally blank. +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_shell", + sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53", + strip_prefix = "rules_shell-0.3.0", + url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz", +) + +load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains") + +rules_shell_dependencies() + +rules_shell_toolchains() diff --git a/examples/simple/WORKSPACE b/examples/simple/WORKSPACE index a2e29e87..a5a3ddc7 100644 --- a/examples/simple/WORKSPACE +++ b/examples/simple/WORKSPACE @@ -1 +1,42 @@ -# Intentionally blank. +workspace(name = "simple_example") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_shell", + sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53", + strip_prefix = "rules_shell-0.3.0", + url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz", +) + +load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains") + +rules_shell_dependencies() + +rules_shell_toolchains() + +http_archive( + name = "cgrindel_bazel_starlib", + sha256 = "43e375213dabe0c3928e65412ea7ec16850db93285c8c6f8b0eaa41cacd0f882", + urls = [ + "https://github.com/cgrindel/bazel-starlib/releases/download/v0.21.0/bazel-starlib.v0.21.0.tar.gz", + ], +) + +load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") + +bazel_starlib_dependencies() + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +# Buildifier Dependencies + +load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") + +buildifier_prebuilt_deps() + +load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") + +buildifier_prebuilt_register_toolchains() From 94d792a71e9c3f19be9b30299b5aa956b731e124 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 25 Dec 2024 13:50:34 -0700 Subject: [PATCH 6/7] Remove commented code. --- shared.bazelrc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/shared.bazelrc b/shared.bazelrc index 04081ade..b4788b01 100644 --- a/shared.bazelrc +++ b/shared.bazelrc @@ -19,7 +19,3 @@ 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= - From 0aec75afeaeff4a0ba8d84e2dd716f97cd5e18b4 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Wed, 25 Dec 2024 13:57:00 -0700 Subject: [PATCH 7/7] Change to use last_green for integration tests. --- MODULE.bazel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index cf4539ac..8f90854a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -25,14 +25,14 @@ bazel_binaries = use_extension( dev_dependency = True, ) bazel_binaries.download(version_file = "//:.bazelversion") -bazel_binaries.download(version = "8.0.0rc2") +bazel_binaries.download(version = "last_green") bazel_binaries.local(path = "tools/fake_bazel.sh") use_repo( bazel_binaries, "bazel_binaries", "bazel_binaries_bazelisk", "build_bazel_bazel_.bazelversion", - "build_bazel_bazel_8_0_0rc2", + "build_bazel_bazel_last_green", "build_bazel_bazel_local", )