Skip to content

Commit

Permalink
chore: upgrade to Bazel 8.0.0 (#423)
Browse files Browse the repository at this point in the history
- Upgrade to Bazel 8.0.0.
- Use `rules_shell`.
- Refactor `bazel_binary` template to check for Bazelisk binary and
export the value. prevents issues with the runfiles for the
`bazel_binary` not being present if used with the `updatesrc` rules from
`cgrindel/bazel-starlib`.
- Enhanced the error message when runfiles cannot be found.
- Update integration test to use `last_green` for some integration
tests.

Closes #414.
Closes #410.
  • Loading branch information
cgrindel authored Jan 2, 2025
1 parent f994a50 commit 82b67d1
Show file tree
Hide file tree
Showing 36 changed files with 175 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4.1
8.0.0
14 changes: 7 additions & 7 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
)

Expand Down
2 changes: 1 addition & 1 deletion bazel_integration_test/bzlmod/e2e_test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---


Expand Down
47 changes: 30 additions & 17 deletions bazel_integration_test/private/bazel_binaries_script.template
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
#!/bin/bash

# --- 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: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---
# vi: ft=sh

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, if it has not already been found.
#
# 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 ---

# Find the bazelisk binary.
BINARY="$(rlocation {bazelisk})" || \
(echo >&2 "Failed to locate bazelisk at {bazelisk}" && exit 1)
BIT_BAZELISK_BINARY="$(rlocation {bazelisk})" || \
(echo >&2 "Failed to locate bazelisk at {bazelisk}" && exit 1)
export BIT_BAZELISK_BINARY
fi

exec "${BINARY}" ${BIT_STARTUP_OPTIONS:-} "$@"
exec "${BIT_BAZELISK_BINARY}" ${BIT_STARTUP_OPTIONS:-} "$@"
32 changes: 23 additions & 9 deletions doc/integration_test_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
## integration_test_utils.bazel_binary_label

<pre>
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")

integration_test_utils.bazel_binary_label(<a href="#integration_test_utils.bazel_binary_label-version">version</a>)
</pre>

Expand All @@ -17,7 +19,7 @@ Returns a label for the specified Bazel version as provided by https://github.co

| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="integration_test_utils.bazel_binary_label-version"></a>version | A <code>string</code> value representing the semantic version of Bazel to use for the integration test. | none |
| <a id="integration_test_utils.bazel_binary_label-version"></a>version | A `string` value representing the semantic version of Bazel to use for the integration test. | none |

**RETURNS**

Expand All @@ -29,6 +31,8 @@ A `string` representing a label for a version of Bazel.
## integration_test_utils.bazel_binary_repo_name

<pre>
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")

integration_test_utils.bazel_binary_repo_name(<a href="#integration_test_utils.bazel_binary_repo_name-version">version</a>)
</pre>

Expand All @@ -39,7 +43,7 @@ Generates a Bazel binary repository name for the specified version.

| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="integration_test_utils.bazel_binary_repo_name-version"></a>version | A <code>string</code> that represents a Bazel version or a label. | none |
| <a id="integration_test_utils.bazel_binary_repo_name-version"></a>version | A `string` that represents a Bazel version or a label. | none |

**RETURNS**

Expand All @@ -51,6 +55,8 @@ A `string` that is suitable for use as a repository name.
## integration_test_utils.bazel_integration_test_name

<pre>
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")

integration_test_utils.bazel_integration_test_name(<a href="#integration_test_utils.bazel_integration_test_name-name">name</a>, <a href="#integration_test_utils.bazel_integration_test_name-version">version</a>)
</pre>

Expand All @@ -61,8 +67,8 @@ Generates a test name from the provided base name and the Bazel version.

| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="integration_test_utils.bazel_integration_test_name-name"></a>name | The base name as a <code>string</code>. | none |
| <a id="integration_test_utils.bazel_integration_test_name-version"></a>version | The Bazel semantic version as a <code>string</code>. | none |
| <a id="integration_test_utils.bazel_integration_test_name-name"></a>name | The base name as a `string`. | none |
| <a id="integration_test_utils.bazel_integration_test_name-version"></a>version | The Bazel semantic version as a `string`. | none |

**RETURNS**

Expand All @@ -74,6 +80,8 @@ A `string` that is suitable as an integration test name.
## integration_test_utils.bazel_integration_test_names

<pre>
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")

integration_test_utils.bazel_integration_test_names(<a href="#integration_test_utils.bazel_integration_test_names-name">name</a>, <a href="#integration_test_utils.bazel_integration_test_names-versions">versions</a>)
</pre>

Expand All @@ -84,8 +92,8 @@ Generates a `list` of integration test names based upon the provided base name a

| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="integration_test_utils.bazel_integration_test_names-name"></a>name | The base name as a <code>string</code>. | none |
| <a id="integration_test_utils.bazel_integration_test_names-versions"></a>versions | A <code>list</code> of semantic version <code>string</code> values. | <code>[]</code> |
| <a id="integration_test_utils.bazel_integration_test_names-name"></a>name | The base name as a `string`. | none |
| <a id="integration_test_utils.bazel_integration_test_names-versions"></a>versions | A `list` of semantic version `string` values. | `[]` |

**RETURNS**

Expand All @@ -97,6 +105,8 @@ A `list` of integration test names as `string` values.
## integration_test_utils.glob_workspace_files

<pre>
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")

integration_test_utils.glob_workspace_files(<a href="#integration_test_utils.glob_workspace_files-workspace_path">workspace_path</a>)
</pre>

Expand All @@ -107,7 +117,7 @@ Recursively globs the Bazel workspace files at the specified path.

| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="integration_test_utils.glob_workspace_files-workspace_path"></a>workspace_path | A <code>string</code> representing the path to glob. | none |
| <a id="integration_test_utils.glob_workspace_files-workspace_path"></a>workspace_path | A `string` representing the path to glob. | none |

**RETURNS**

Expand All @@ -120,6 +130,8 @@ A `list` of the files under the specified path ignoring certain Bazel
## integration_test_utils.is_version_file

<pre>
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")

integration_test_utils.is_version_file(<a href="#integration_test_utils.is_version_file-version">version</a>)
</pre>

Expand All @@ -130,7 +142,7 @@ Determines if the version string is a reference to a version file.

| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="integration_test_utils.is_version_file-version"></a>version | A <code>string</code> that represents a Bazel version or a label. | none |
| <a id="integration_test_utils.is_version_file-version"></a>version | A `string` that represents a Bazel version or a label. | none |

**RETURNS**

Expand All @@ -142,6 +154,8 @@ A `bool` the specifies whether the string is a file reference.
## integration_test_utils.semantic_version_to_name

<pre>
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "integration_test_utils")

integration_test_utils.semantic_version_to_name(<a href="#integration_test_utils.semantic_version_to_name-version">version</a>)
</pre>

Expand All @@ -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 |
| :------------- | :------------- | :------------- |
| <a id="integration_test_utils.semantic_version_to_name-version"></a>version | A semantic version <code>string</code>. | none |
| <a id="integration_test_utils.semantic_version_to_name-version"></a>version | A semantic version `string`. | none |

**RETURNS**

Expand Down
Loading

0 comments on commit 82b67d1

Please sign in to comment.