Skip to content

Commit e67310b

Browse files
authored
Use rules_bazel_integration_test to download Bazel binary (#8495)
1 parent 121c4c9 commit e67310b

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

WORKSPACE

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
workspace(name = "com_github_google_flatbuffers")
22

3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44

55
http_archive(
66
name = "platforms",
@@ -191,12 +191,22 @@ esbuild_register_toolchains(
191191
esbuild_version = LATEST_ESBUILD_VERSION,
192192
)
193193

194-
http_file(
195-
name = "bazel_linux_x86_64",
196-
downloaded_file_path = "bazel",
197-
executable = True,
198-
sha256 = "e78fc3394deae5408d6f49a15c7b1e615901969ecf6e50d55ef899996b0b8458",
194+
http_archive(
195+
name = "rules_bazel_integration_test",
196+
sha256 = "3e24bc0fba88177cd0ae87c1e37bf7de5d5af8e812f00817a58498b1a8368fca",
199197
urls = [
200-
"https://github.com/bazelbuild/bazel/releases/download/6.3.2/bazel-6.3.2-linux-x86_64",
198+
"https://github.com/bazel-contrib/rules_bazel_integration_test/releases/download/v0.31.0/rules_bazel_integration_test.v0.31.0.tar.gz",
201199
],
202200
)
201+
202+
load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies")
203+
204+
bazel_integration_test_rules_dependencies()
205+
206+
load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")
207+
208+
bazel_starlib_dependencies()
209+
210+
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries")
211+
212+
bazel_binaries(versions = ["6.3.2"])

tests/bazel_repository_test_template.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
1414
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
1515
# --- end runfiles.bash initialization v3 ---
1616

17-
BAZEL_BIN="$(rlocation bazel_linux_x86_64/file/bazel)"
17+
BAZEL_BIN="$(rlocation {{BAZEL_PATH}})"
1818
readonly BAZEL_BIN
1919

2020
if [[ ! -x "${BAZEL_BIN}" ]]; then

tests/defs.bzl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
"""Helper macros and rules for tests."""
22

3+
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
34
load("@bazel_skylib//lib:paths.bzl", "paths")
45
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
56

7+
def repo_name(label):
8+
if hasattr(label, "repo_name"): # Added in Bazel 7.1
9+
return label.repo_name
10+
else:
11+
return "build_bazel_bazel_6_3_2"
12+
13+
def rlocationpath(label):
14+
"""Returns the rlocationpath for a label
15+
16+
Args:
17+
label (Label): The label to determine the rlocationpath for
18+
19+
Returns:
20+
str: The rlocationpath for label
21+
"""
22+
path = ""
23+
if repo_name(label):
24+
path += repo_name(label) + "/"
25+
if label.package:
26+
path += label.package + "/"
27+
path += label.name
28+
return path
29+
630
def flatbuffers_as_external_repo_test(name, directory):
731
"""Run all tests in a bazel workspace that imports flatbuffers as an external repository.
832
@@ -11,11 +35,13 @@ def flatbuffers_as_external_repo_test(name, directory):
1135
directory: The directory in which the bazel workspace is located. This is the directory
1236
that imports flatbuffers as an external repository.
1337
"""
38+
bazel_binary_label = Label(bazel_binaries.label(bazel_binaries.versions.current))
1439
expand_template(
1540
name = name + "__template_expansion",
1641
out = name + ".sh",
1742
substitutions = {
1843
"{{REPOSITORY_DIR}}": paths.join(native.package_name(), directory),
44+
"{{BAZEL_PATH}}": rlocationpath(bazel_binary_label),
1945
},
2046
template = "//tests:bazel_repository_test_template.sh",
2147
)
@@ -25,7 +51,7 @@ def flatbuffers_as_external_repo_test(name, directory):
2551
srcs = [":%s.sh" % name],
2652
data = [
2753
"//:distribution",
28-
"@bazel_linux_x86_64//file",
54+
bazel_binary_label,
2955
] + native.glob(
3056
[
3157
directory + "/**/*",

0 commit comments

Comments
 (0)