1
1
"""Helper macros and rules for tests."""
2
2
3
+ load ("@bazel_binaries//:defs.bzl" , "bazel_binaries" )
3
4
load ("@bazel_skylib//lib:paths.bzl" , "paths" )
4
5
load ("@bazel_skylib//rules:expand_template.bzl" , "expand_template" )
5
6
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
+
6
30
def flatbuffers_as_external_repo_test (name , directory ):
7
31
"""Run all tests in a bazel workspace that imports flatbuffers as an external repository.
8
32
@@ -11,11 +35,13 @@ def flatbuffers_as_external_repo_test(name, directory):
11
35
directory: The directory in which the bazel workspace is located. This is the directory
12
36
that imports flatbuffers as an external repository.
13
37
"""
38
+ bazel_binary_label = Label (bazel_binaries .label (bazel_binaries .versions .current ))
14
39
expand_template (
15
40
name = name + "__template_expansion" ,
16
41
out = name + ".sh" ,
17
42
substitutions = {
18
43
"{{REPOSITORY_DIR}}" : paths .join (native .package_name (), directory ),
44
+ "{{BAZEL_PATH}}" : rlocationpath (bazel_binary_label ),
19
45
},
20
46
template = "//tests:bazel_repository_test_template.sh" ,
21
47
)
@@ -25,7 +51,7 @@ def flatbuffers_as_external_repo_test(name, directory):
25
51
srcs = [":%s.sh" % name ],
26
52
data = [
27
53
"//:distribution" ,
28
- "@bazel_linux_x86_64//file" ,
54
+ bazel_binary_label ,
29
55
] + native .glob (
30
56
[
31
57
directory + "/**/*" ,
0 commit comments