2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-12-02 10:15:22 +00:00
bazel-lib/lib/tests/transitions/BUILD.bazel
2023-01-01 15:37:00 -08:00

150 lines
3.3 KiB
Python

load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//lib:transitions.bzl", "platform_transition_binary", "platform_transition_filegroup")
load("//lib:diff_test.bzl", "diff_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
platform(
name = "armv7_linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:armv7",
],
)
platform(
name = "x86_64_linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
"@io_bazel_rules_go//go/toolchain:cgo_off", # https://github.com/bazelbuild/rules_go/pull/3390
],
)
platform(
name = "arm64_linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
"@io_bazel_rules_go//go/toolchain:cgo_off", # https://github.com/bazelbuild/rules_go/pull/3390
],
)
config_setting(
name = "is_x86",
constraint_values = [
"@platforms//cpu:x86_64",
],
)
# Simple test fixture that produces something different depending on the
# target platform.
filegroup(
name = "platform_description",
srcs = select({
":is_x86": ["linux_x86.txt"],
"//conditions:default": ["linux_arm.txt"],
}),
)
platform_transition_filegroup(
name = "for_x86",
srcs = ["platform_description"],
target_platform = ":x86_64_linux",
)
platform_transition_filegroup(
name = "for_arm",
srcs = ["platform_description"],
target_platform = ":armv7_linux",
)
genrule(
name = "for_x86_path",
srcs = [":for_x86"],
outs = ["for_x86_path.txt"],
cmd = "echo $(rootpath :for_x86) > $@",
)
genrule(
name = "for_arm_path",
srcs = [":for_arm"],
outs = ["for_arm_path.txt"],
cmd = "echo $(rootpath :for_arm) > $@",
)
write_file(
name = "expected_x86_path",
out = "expected_x86_path.txt",
content = [
"lib/tests/transitions/linux_x86.txt",
"",
],
)
write_file(
name = "expected_arm_path",
out = "expected_arm_path.txt",
content = [
"lib/tests/transitions/linux_arm.txt",
"",
],
)
diff_test(
name = "test_x86",
file1 = ":for_x86_path",
file2 = ":expected_x86_path",
)
diff_test(
name = "test_arm",
file1 = ":for_arm_path",
file2 = ":expected_arm_path",
)
go_binary(
name = "test_transition_binary",
embed = [":transitions_lib"],
tags = ["manual"],
visibility = ["//visibility:public"],
)
platform_transition_binary(
name = "transitioned_go_binary_x86_64",
binary = ":test_transition_binary",
target_platform = "x86_64_linux",
)
platform_transition_binary(
name = "transitioned_go_binary_arm64",
binary = ":test_transition_binary",
target_platform = "arm64_linux",
)
sh_test(
name = "test_go_binary_is_x86_64",
srcs = ["test_file_type_contains.sh"],
args = [
"$(rootpath :transitioned_go_binary_x86_64)",
"x86-64",
],
data = [":transitioned_go_binary_x86_64"],
)
sh_test(
name = "test_go_binary_is_arm64",
srcs = ["test_file_type_contains.sh"],
args = [
"$(rootpath :transitioned_go_binary_arm64)",
"aarch64",
],
data = [":transitioned_go_binary_arm64"],
)
go_library(
name = "transitions_lib",
srcs = ["main.go"],
importpath = "github.com/aspect-build/bazel-lib/lib/tests/transitions",
visibility = ["//visibility:private"],
)