Skip to content

Commit

Permalink
integration_test_setup.sh: load bash runfiles library
Browse files Browse the repository at this point in the history
Instead of getting the rlocation function from [test-setup.sh](https://cs.opensource.google/bazel/bazel/+/master:tools/test/test-setup.sh;l=115), we should use the actual bash runfiles library which supports repo mapping.

Working towards: #18957

RELNOTES: None
PiperOrigin-RevId: 552778831
Change-Id: Ie747faf58a5c3fc33d38653130d9657224909430
  • Loading branch information
meteorcloudy authored and copybara-github committed Aug 1, 2023
1 parent 282fffa commit b20085a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/test/shell/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ sh_library(
"unittest.bash",
"unittest_utils.sh",
],
data = [":testenv.sh"],
data = [
":testenv.sh",
"@bazel_tools//tools/bash/runfiles",
],
visibility = ["//visibility:public"],
)

Expand Down
13 changes: 1 addition & 12 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ gen_workspace_stanza(
],
)

gen_workspace_stanza(
name = "rules_proto_stanza",
out = "rules_proto_stanza.txt",
repos = [
"rules_proto",
],
)

filegroup(
name = "test-deps",
testonly = 1,
Expand Down Expand Up @@ -346,10 +338,7 @@ sh_test(
name = "bazel_proto_library_test",
size = "large", # Downloads and compiles protobuf for *every* *test* *case*
srcs = ["bazel_proto_library_test.sh"],
data = [
":rules_proto_stanza.txt",
":test-deps",
],
data = [":test-deps"],
exec_compatible_with = ["//:highcpu_machine"],
tags = ["no_windows"], # Doesn't work on Windows for unknown reason
)
Expand Down
2 changes: 0 additions & 2 deletions src/test/shell/bazel/bazel_proto_library_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ function write_workspace() {
mkdir -p "$workspace"
fi

cat $(rlocation io_bazel/src/tests/shell/bazel/rules_proto_stanza.txt) >> "$workspace"WORKSPACE

cat >> "$workspace"WORKSPACE << EOF
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
Expand Down
15 changes: 14 additions & 1 deletion src/test/shell/integration_test_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ function print_message_and_exit() {
}

if type rlocation >&/dev/null; then
# If rlocation is defined, use it to look up data-dependencies.
# An incomplete rlocation function is defined in Bazel's test-setup.sh script,
# load the actual Bash runfiles library from @bazel_tools//tools/bash/runfiles
# to make sure repo mappings is respected.
# --- 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
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 v3 ---

# Load the unit test framework
source "$(rlocation io_bazel/src/test/shell/unittest.bash)" \
|| print_message_and_exit "unittest.bash not found!"
Expand Down

0 comments on commit b20085a

Please sign in to comment.