Skip to content

Commit

Permalink
Merge pull request #96 from tweag/cb/remove-ps1-wrapper
Browse files Browse the repository at this point in the history
Call bash wrapper on Windows
  • Loading branch information
mergify[bot] authored Dec 10, 2024
2 parents dfd9051 + 1636949 commit 0d39762
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 54 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion tests/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 12 additions & 9 deletions tests/import/create_shim_test.sh
Original file line number Diff line number Diff line change
@@ -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")"
Expand Down
12 changes: 6 additions & 6 deletions tests/import/import_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
],
)

Expand Down
16 changes: 10 additions & 6 deletions tools/bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
16 changes: 15 additions & 1 deletion tools/bazel.bat
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
@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
)

# 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" %*

30 changes: 0 additions & 30 deletions tools/bazel_wrapper.ps1

This file was deleted.

0 comments on commit 0d39762

Please sign in to comment.