| load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") |
| load("//lib:diff_test.bzl", "diff_test") |
| load( |
| "//lib:transitions.bzl", |
| "platform_transition_binary", |
| "platform_transition_filegroup", |
| "platform_transition_test", |
| ) |
| |
| 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"], |
| ) |
| |
| go_test( |
| name = "test_transition_test", |
| srcs = ["simple_test.go"], |
| ) |
| |
| 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", |
| ) |
| |
| platform_transition_test( |
| name = "transitioned_go_test_x86_64", |
| binary = ":test_transition_test", |
| # only run this test on x86_64 platforms |
| target_compatible_with = [ |
| "@platforms//cpu:x86_64", |
| ], |
| target_platform = "x86_64_linux", |
| ) |
| |
| platform_transition_test( |
| name = "transitioned_go_test_arm64", |
| binary = ":test_transition_test", |
| # only run this test on arm64 platforms |
| target_compatible_with = [ |
| "@platforms//cpu:arm64", |
| ], |
| 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"], |
| ) |
| |
| sh_test( |
| name = "test_go_test_is_x86_64", |
| srcs = ["test_file_type_contains.sh"], |
| args = [ |
| "$(rootpath :transitioned_go_test_x86_64)", |
| "x86-64", |
| ], |
| data = [":transitioned_go_test_x86_64"], |
| ) |
| |
| sh_test( |
| name = "test_go_test_is_arm64", |
| srcs = ["test_file_type_contains.sh"], |
| args = [ |
| "$(rootpath :transitioned_go_test_arm64)", |
| "aarch64", |
| ], |
| data = [":transitioned_go_test_arm64"], |
| ) |
| |
| go_library( |
| name = "transitions_lib", |
| srcs = ["main.go"], |
| importpath = "github.com/aspect-build/bazel-lib/lib/tests/transitions", |
| visibility = ["//visibility:private"], |
| ) |