Use rules_bazel_integration_test to download Bazel binary (#8495)

This commit is contained in:
Marcel
2025-01-22 01:51:08 +01:00
committed by GitHub
parent 121c4c99ae
commit e67310bf1c
3 changed files with 45 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v3 ---
BAZEL_BIN="$(rlocation bazel_linux_x86_64/file/bazel)"
BAZEL_BIN="$(rlocation {{BAZEL_PATH}})"
readonly BAZEL_BIN
if [[ ! -x "${BAZEL_BIN}" ]]; then

View File

@@ -1,8 +1,32 @@
"""Helper macros and rules for tests."""
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
def repo_name(label):
if hasattr(label, "repo_name"): # Added in Bazel 7.1
return label.repo_name
else:
return "build_bazel_bazel_6_3_2"
def rlocationpath(label):
"""Returns the rlocationpath for a label
Args:
label (Label): The label to determine the rlocationpath for
Returns:
str: The rlocationpath for label
"""
path = ""
if repo_name(label):
path += repo_name(label) + "/"
if label.package:
path += label.package + "/"
path += label.name
return path
def flatbuffers_as_external_repo_test(name, directory):
"""Run all tests in a bazel workspace that imports flatbuffers as an external repository.
@@ -11,11 +35,13 @@ def flatbuffers_as_external_repo_test(name, directory):
directory: The directory in which the bazel workspace is located. This is the directory
that imports flatbuffers as an external repository.
"""
bazel_binary_label = Label(bazel_binaries.label(bazel_binaries.versions.current))
expand_template(
name = name + "__template_expansion",
out = name + ".sh",
substitutions = {
"{{REPOSITORY_DIR}}": paths.join(native.package_name(), directory),
"{{BAZEL_PATH}}": rlocationpath(bazel_binary_label),
},
template = "//tests:bazel_repository_test_template.sh",
)
@@ -25,7 +51,7 @@ def flatbuffers_as_external_repo_test(name, directory):
srcs = [":%s.sh" % name],
data = [
"//:distribution",
"@bazel_linux_x86_64//file",
bazel_binary_label,
] + native.glob(
[
directory + "/**/*",