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")