Skip to content

Commit 3a4521b

Browse files
committed
Update to not use rules_bazel_integration_test
1 parent 82b95af commit 3a4521b

7 files changed

Lines changed: 356 additions & 45 deletions

File tree

MODULE.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,12 @@ use_repo(
9797
"build_bazel_bazel_9_x",
9898
"build_bazel_bazel_last_green",
9999
)
100+
101+
local_bazel = use_extension("//:extensions.bzl", "local_bazel_extension")
102+
use_repo(local_bazel, "local_bazel")
103+
104+
remote_bazel_fetcher = use_extension("//:extensions.bzl", "remote_bazel_extension")
105+
remote_bazel_fetcher.download(bazel_version = "bazel_7")
106+
remote_bazel_fetcher.download(bazel_version = "bazel_8")
107+
remote_bazel_fetcher.download(bazel_version = "bazel_9")
108+
use_repo(remote_bazel_fetcher, "bazel_7", "bazel_8", "bazel_9")

extensions.bzl

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
2+
load("//:local_bazel.bzl", "local_bazel_import")
3+
4+
SHORT_VERSION_MAPPING = {
5+
"bazel_7": "7.7.1",
6+
"bazel_8": "8.7.0",
7+
"bazel_9": "9.1.0",
8+
}
9+
10+
SHA_MATRIX = {
11+
"7.7.1": {
12+
"linux_x86_64": "115a1b62be95f29e5821d4dddffba1b058905a48019b499919c285e7f708d5e2",
13+
"linux_arm64": "71df04ec724f1b577f1f47ec9a6b81d13f39683f6c3215cacf45fdaf40b2c5c1",
14+
"darwin_x86_64": "8582aea5ee2d8d0448bbda10fd7034734db1a21cbe4ea351a10012b969aa5d31",
15+
"darwin_arm64": "fe8a1ee9064e94afae075c0dd4efb453db9c1373b9df12fecbff8479d408eb08",
16+
"windows_x86_64": "6d9fb21e806cf4f4e61bfa2bc865df4900ffdc1e9ea90ca1016ba70367ef0de4",
17+
},
18+
"8.7.0": {
19+
"linux_x86_64": "d7606e679b78067c811096fb3d6cf135225b528835ca396e3a4dddf957859544",
20+
"linux_arm64": "bfe9558bd8a2ecfe4841ec46c0dbccb4b469fe22d81f2f859de0de222b3e7ce3",
21+
"darwin_x86_64": "76f3eb05782098e9f9ddd8247ec969b085195a3ae2978c81721a2235052ccf26",
22+
"darwin_arm64": "575f20fb23955e02f73519befd180df635b4ed0960c60f0e70fcc8d74014a713",
23+
"windows_x86_64": "29f1796f57379933340afa135f02703ffa21dd30135754bea695f8fd15103420",
24+
},
25+
"9.1.0": {
26+
"linux_x86_64": "a667454f3f4f8878df8199136b82c199f6ada8477b337fae3b1ef854f01e4e2f",
27+
"linux_arm64": "ba933bfc943e4c44f0743a5823aa2312a34b39628532add5dd037e08d8ec27a4",
28+
"darwin_x86_64": "666c6c79eda285cada5f5c39c891c6dd7ee0971b20bff365ea87a4b897271433",
29+
"darwin_arm64": "084a1784fa8f0dcae77fb4e88faa15048d8149a36c947ce198508bffb060e1bb",
30+
"windows_x86_64": "b457dccd36a9bb9be01326cc1d069a201bb50b4b94562a652afb6f43c5148d42",
31+
},
32+
}
33+
34+
def _remote_bazel_extension_impl(module_ctx):
35+
os_name = module_ctx.os.name.lower()
36+
os_key = "linux"
37+
exe_extension = ""
38+
if "windows" in os_name:
39+
os_key = "windows"
40+
exe_extension = ".exe"
41+
elif "mac" in os_name or "darwin" in os_name:
42+
os_key = "darwin"
43+
44+
cpu_arch = module_ctx.os.arch.lower()
45+
if "x86_64" in cpu_arch or "amd64" in cpu_arch:
46+
arch_key = "x86_64"
47+
elif "arm64" in cpu_arch:
48+
arch_key = "arm64"
49+
else:
50+
fail("Unsupported architecture '{}'.".format(cpu_arch))
51+
52+
platform_key = "{}_{}".format(os_key, arch_key)
53+
54+
requested_versions = {}
55+
for mod in module_ctx.modules:
56+
for tag in mod.tags.download:
57+
requested_versions[tag.bazel_version] = True
58+
59+
for bazel_version in requested_versions:
60+
if bazel_version not in SHORT_VERSION_MAPPING:
61+
fail("Unrecognised version '%s'" % bazel_version)
62+
version = SHORT_VERSION_MAPPING[bazel_version]
63+
filename = "bazel-%s-%s-%s%s" % (version, os_key, arch_key, exe_extension)
64+
url = "https://github.com/bazelbuild/bazel/releases/download/%s/%s" % (version, filename)
65+
66+
http_file(
67+
name = bazel_version,
68+
downloaded_file_path = "bazel" + exe_extension,
69+
executable = True,
70+
url = url,
71+
sha256 = SHA_MATRIX[version][platform_key],
72+
)
73+
74+
75+
def _local_bazel_extension_impl(module_ctx):
76+
local_bazel_import(name = "local_bazel")
77+
78+
download_tag = tag_class(attrs = {"bazel_version": attr.string(mandatory = True)})
79+
80+
remote_bazel_extension = module_extension(
81+
implementation = _remote_bazel_extension_impl,
82+
tag_classes = {"download": download_tag},
83+
)
84+
85+
local_bazel_extension = module_extension(
86+
implementation = _local_bazel_extension_impl,
87+
)

local_bazel.bzl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
def _local_bazel_import_impl(repository_ctx):
2+
if "windows" in repository_ctx.os.name.lower():
3+
bazel_real = "bazel-real.exe"
4+
bazel_name = "bazel.exe"
5+
else:
6+
bazel_real = "bazel-real"
7+
bazel_name = "bazel"
8+
9+
# Prioritise bazel-real if it exists since it's much more likely to be an actual executable.
10+
bazel_path = repository_ctx.which(bazel_real)
11+
if bazel_path == None:
12+
bazel_path = repository_ctx.which(bazel_name)
13+
if bazel_path == None:
14+
fail("Neither '%s' or '%s' not found on PATH." % (bazel_real, bazel_name))
15+
16+
repository_ctx.symlink(bazel_path, bazel_real)
17+
repository_ctx.file(
18+
"BUILD",
19+
executable = False,
20+
content = """
21+
load({sh_binary_bzl}, "sh_binary")
22+
23+
sh_binary(
24+
name = "{bazel_bin}",
25+
srcs = ["{bazel_binary}"],
26+
visibility = ["//visibility:public"],
27+
)
28+
29+
alias(
30+
name = "bazel_bin",
31+
actual = "{bazel_bin}",
32+
visibility = ["//visibility:public"],
33+
)
34+
""".format(
35+
sh_binary_bzl = repr(str(Label("@rules_shell//shell:sh_binary.bzl"))),
36+
bazel_bin = bazel_name,
37+
bazel_binary = bazel_real,
38+
),
39+
)
40+
41+
local_bazel_import = repository_rule(
42+
implementation = _local_bazel_import_impl,
43+
environ = ["PATH"],
44+
)

tests/integration/BUILD

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,33 @@ sh_library(
3030
srcs = ["test_utils.sh"],
3131
)
3232

33+
sh_library(
34+
name = "platform_utils",
35+
srcs = ["platform_utils.sh"],
36+
)
37+
3338
gen_workspace(
34-
"simple_compile",
39+
"simple_compile_workspace",
3540
workspace_files = glob(["simple_compile/**"]),
3641
)
3742

3843
rules_cc_integration_test(
3944
name = "simple_compile_test",
4045
test_script = "simple_compile_test.sh",
41-
workspace = "simple_compile",
46+
workspace = "simple_compile_workspace",
47+
workspace_name = "simple_compile",
4248
)
4349

4450
rules_cc_integration_test(
4551
name = "stripped_compile_test",
4652
test_script = "stripped_compile_test.sh",
47-
workspace = "simple_compile",
53+
workspace = "simple_compile_workspace",
54+
workspace_name = "simple_compile",
4855
)
4956

5057
rules_cc_integration_test(
5158
name = "no_recompile_on_shutdown_test",
5259
test_script = "no_recompile_on_shutdown_test.sh",
53-
workspace = "simple_compile",
60+
workspace = "simple_compile_workspace",
61+
workspace_name = "simple_compile",
5462
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
case "$(uname -s | tr [:upper:] [:lower:])" in
2+
linux*)
3+
declare -r PLATFORM=linux
4+
;;
5+
darwin*)
6+
declare -r PLATFORM=darwin
7+
;;
8+
msys*|mingw*|cygwin*)
9+
declare -r PLATFORM=windows
10+
;;
11+
*)
12+
declare -r PLATFORM=unknown
13+
;;
14+
esac
15+
16+
function is_linux() {
17+
[[ "$PLATFORM" == "linux" ]]
18+
}
19+
20+
function is_darwin() {
21+
[[ "$PLATFORM" == "darwin" ]]
22+
}
23+
24+
function is_windows() {
25+
[[ "$PLATFORM" == "windows" ]]
26+
}
27+
28+
if is_windows; then
29+
declare -r EXE_EXT=".exe"
30+
else
31+
declare -r EXE_EXT=""
32+
fi

0 commit comments

Comments
 (0)