From 78dc5830513764521fc89540b075b01f54123d75 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 5 Dec 2024 12:51:19 +0100 Subject: [PATCH 1/8] Call bash wrapper on Windows - remove powershell wrapper script (it was not equivalent to the bash script) --- tools/bazel.bat | 13 ++++++++++++- tools/bazel_wrapper.ps1 | 30 ------------------------------ 2 files changed, 12 insertions(+), 31 deletions(-) delete mode 100644 tools/bazel_wrapper.ps1 diff --git a/tools/bazel.bat b/tools/bazel.bat index dc4b2d2..fa08a4c 100644 --- a/tools/bazel.bat +++ b/tools/bazel.bat @@ -1 +1,12 @@ -@pwsh -File "%~dp0bazel_wrapper.ps1" %* +@echo off + +:: Check if bash is available +where bash >nul 2>nul +if errorlevel 1 ( + echo Bash is not installed or not in PATH. Please install WSL or add bash to PATH. + exit /b 1 +) + +:: Call the Bash wrapper +bash --noprofile --norc -o errexit -o nounset -o pipefail "%~dp0bazel" %* + diff --git a/tools/bazel_wrapper.ps1 b/tools/bazel_wrapper.ps1 deleted file mode 100644 index 1a15798..0000000 --- a/tools/bazel_wrapper.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -# Exit immediately if a command fails, if a variable is used without being defined, or if a pipeline fails -Set-StrictMode -Version Latest -$ErrorActionPreference = "Stop" - -# Get the Bazel version -$bazel_version = & $Env:BAZEL_REAL --version | ForEach-Object { ($_ -split ' ')[1] } - -# Construct the config flag based on the major version -$config = "--config=bazel$($bazel_version -split '\.' | Select-Object -First 1)" - -# Initialize an array for startup options -$startup_options = @() - -# Parse command-line arguments for options -while ($args.Count -gt 0) { - $option = $args[0] - if ($option -match '^-') { - $startup_options += $option - $args = $args[1..$($args.Count - 1)] - } else { - break - } -} - -# Get the command and remaining arguments -$command = $args[0] -$args = $args[1..$($args.Count - 1)] - -# Execute Bazel with the collected options and arguments -& $Env:BAZEL_REAL @startup_options $command $config @args From 1301843c112b1a190c525f060148c6403279285c Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 5 Dec 2024 13:03:22 +0100 Subject: [PATCH 2/8] Fix bazel wrapper There might be no startup options and no command. --- tools/bazel | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/bazel b/tools/bazel index 3a516f2..1d13dd1 100755 --- a/tools/bazel +++ b/tools/bazel @@ -12,20 +12,24 @@ bazel_version=$( # enable config per each major version, i.e. bazel6, bazel7, bazel8, ... config="--config=bazel${bazel_version%%.*}" -declare -a startup_options=() +declare -a args=() while [ "$#" -gt 0 ]; do option="$1" if [[ "$option" = -* ]]; then - startup_options+=( "$option" ) + args+=( "$option" ) shift else break fi done -command=$1 ; shift +if [ "$#" -gt 0 ]; then + command="$1" ; shift + args+=( "$command" "$config" "$@" ) +elif [ "${#args[@]}" -eq 0 ]; then + # no startup options, no command + exec "$BAZEL_REAL" +fi -# N.B. using a default value if unset for `startup_options` is needed for compatiblity with Bash 3 -# which treats an empty array as unset -exec "$BAZEL_REAL" "${startup_options[@]-}" "$command" "$config" "$@" +exec "$BAZEL_REAL" "${args[@]}" From a6051defd790f385f66dfcb744c11142ee29ecb0 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 5 Dec 2024 13:07:49 +0100 Subject: [PATCH 3/8] Revert "Update dependency stardoc to v0.7.2" stardoc version 0.7.2 is not compatible with older Bazel versions. Note, CI passed but that was because no tests were actually run. This reverts commit 5fba4edc4172f5b73baac076d65696d8c8617194. --- tests/MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MODULE.bazel b/tests/MODULE.bazel index ad1eb88..772faf2 100644 --- a/tests/MODULE.bazel +++ b/tests/MODULE.bazel @@ -8,7 +8,7 @@ local_path_override( bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "platforms", version = "0.0.10") -bazel_dep(name = "stardoc", version = "0.7.2", repo_name = "io_bazel_stardoc") +bazel_dep(name = "stardoc", version = "0.6.2", repo_name = "io_bazel_stardoc") sh_configure = use_extension("@rules_sh//bzlmod:extensions.bzl", "sh_configure") use_repo(sh_configure, "local_posix_config", "rules_sh_shim_exe") From f9a5570af129960f28d6ec3cc29441a6dbcced08 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 5 Dec 2024 13:41:41 +0100 Subject: [PATCH 4/8] Upgrade Bazel Bash runfiles library to v3 --- tests/import/create_shim_test.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/import/create_shim_test.sh b/tests/import/create_shim_test.sh index d1d0185..7d6fc80 100755 --- a/tests/import/create_shim_test.sh +++ b/tests/import/create_shim_test.sh @@ -1,14 +1,17 @@ #!/usr/bin/env 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 + +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail; set +e; 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: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v2 --- + 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 v3 --- + set -euo pipefail SHIM_EXE="$(rlocation "$1")" From eef603287b32bab132ca27c5758c38c0a9e6be95 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 5 Dec 2024 13:57:02 +0100 Subject: [PATCH 5/8] Use bazel 8.0.0 Bazel 8 has been released! --- .github/workflows/workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 6efe67f..71dc9fc 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -20,7 +20,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] bazel_mode: [workspace, module] - version: ["5.4.1", "6.4.0", "7.0.0", "8.0.0rc6"] + version: ["5.4.1", "6.4.0", "7.0.0", "8.0.0"] include: # Bazel 5.4.1 does not find Visual Studio on windows-2022. So, we # test it on windows-2019. From da1fb78f3de071bf07dcb17427f1523801a3d421 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 5 Dec 2024 14:20:38 +0100 Subject: [PATCH 6/8] Use rlocationpath instead of rootpath Bazel 8 uses the plus sign instead of tilde in repo names now (the `--incompatible_use_plus_in_repo_names` flag is a no-op). That causes the `rlocation` lookup for the arguments of the `@rules_sh_tests//import:create_shim_test` to fail and just return empty results. ``` comm: '': No such file or directory Expected files to be equal, but they are different: '' and ''. ``` --- tests/import/import_test.bzl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/import/import_test.bzl b/tests/import/import_test.bzl index c78437c..62b9d6b 100644 --- a/tests/import/import_test.bzl +++ b/tests/import/import_test.bzl @@ -17,12 +17,12 @@ def _create_shim_test(): "@rules_sh_import_test_create_shim_test_shim//prefix:another.shim", ], args = [ - "rules_sh_tests/$(rootpath @rules_sh_shim_exe//:shim.exe)", - "rules_sh_tests/$(rootpath @rules_sh_import_test_create_shim_test_source//:empty.exe)", - "rules_sh_tests/$(rootpath @rules_sh_import_test_create_shim_test_shim//:shimmed.exe)", - "rules_sh_tests/$(rootpath @rules_sh_import_test_create_shim_test_shim//:shimmed.shim)", - "rules_sh_tests/$(rootpath @rules_sh_import_test_create_shim_test_shim//prefix:another.exe)", - "rules_sh_tests/$(rootpath @rules_sh_import_test_create_shim_test_shim//prefix:another.shim)", + "$(rlocationpath @rules_sh_shim_exe//:shim.exe)", + "$(rlocationpath @rules_sh_import_test_create_shim_test_source//:empty.exe)", + "$(rlocationpath @rules_sh_import_test_create_shim_test_shim//:shimmed.exe)", + "$(rlocationpath @rules_sh_import_test_create_shim_test_shim//:shimmed.shim)", + "$(rlocationpath @rules_sh_import_test_create_shim_test_shim//prefix:another.exe)", + "$(rlocationpath @rules_sh_import_test_create_shim_test_shim//prefix:another.shim)", ], ) From c703396209044130e16bac036516e675d862fa84 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Fri, 6 Dec 2024 09:27:00 +0100 Subject: [PATCH 7/8] Set MSYS_NO_PATHCONV=1 in batch wrapper This disables automatic POSIX-to-Windows path conversion (/ -> c:\some\path, // -> /). See https://github.com/git-for-windows/build-extra/blob/main/ReleaseNotes.md#known-issues --- tools/bazel.bat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/bazel.bat b/tools/bazel.bat index fa08a4c..3d94db1 100644 --- a/tools/bazel.bat +++ b/tools/bazel.bat @@ -7,6 +7,9 @@ if errorlevel 1 ( exit /b 1 ) +# disable POSIX-to-Windows path conversion for MINGW / MSYS2 +set MSYS_NO_PATHCONV=1 + :: Call the Bash wrapper bash --noprofile --norc -o errexit -o nounset -o pipefail "%~dp0bazel" %* From 1636949490c4a7d4bb2d14d9208cb7f539863486 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Tue, 10 Dec 2024 09:58:07 +0100 Subject: [PATCH 8/8] Use Bazel 7 in ghajoin_jobs action It used the latest Bazel version by default and failed, see https://github.com/cgrindel/gha_join_jobs/issues/67 --- .github/workflows/workflow.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 71dc9fc..ab59839 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -82,5 +82,7 @@ jobs: if: ${{ always() }} steps: - uses: cgrindel/gha_join_jobs@794a2d117251f22607f1aab937d3fd3eaaf9a2f5 # v1 + env: + USE_BAZEL_VERSION: '7.x' with: github_token: ${{ secrets.GITHUB_TOKEN }}