Skip to content

Commit

Permalink
tests: make analysis tests support --incompatible_enable_cc_toolchain…
Browse files Browse the repository at this point in the history
…_resolution (#1281)

The analysis tests transition to different platforms to test some
platform-specific logic.

When cc toolchain registration is enabled, this also requires that a
more complete
toolchain be defined and available.
  • Loading branch information
comius committed Jun 20, 2023
1 parent 00962c4 commit 0d59fcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tools/build_defs/python/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ cc_toolchain(
toolchain_identifier = "mac-toolchain",
)

toolchain(
name = "mac_toolchain_definition",
target_compatible_with = ["@platforms//os:macos"],
toolchain = ":mac_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

fake_cc_toolchain_config(
name = "mac_toolchain_config",
target_cpu = "darwin_x86_64",
Expand All @@ -72,6 +79,13 @@ cc_toolchain(
toolchain_identifier = "linux-toolchain",
)

toolchain(
name = "linux_toolchain_definition",
target_compatible_with = ["@platforms//os:linux"],
toolchain = ":linux_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

fake_cc_toolchain_config(
name = "linux_toolchain_config",
target_cpu = "k8",
Expand Down
3 changes: 3 additions & 0 deletions tools/build_defs/python/tests/py_test/py_test_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ load("//tools/build_defs/python/tests:util.bzl", pt_util = "util")
# Explicit Label() calls are required so that it resolves in @rules_python context instead of
# @rules_testing context.
_FAKE_CC_TOOLCHAIN = Label("//tools/build_defs/python/tests:cc_toolchain_suite")
_FAKE_CC_TOOLCHAINS = [str(Label("//tools/build_defs/python/tests:all"))]
_PLATFORM_MAC = Label("//tools/build_defs/python/tests:mac")
_PLATFORM_LINUX = Label("//tools/build_defs/python/tests:linux")

Expand All @@ -51,6 +52,7 @@ def _test_mac_requires_darwin_for_execution(name, config):
config_settings = {
"//command_line_option:cpu": "darwin_x86_64",
"//command_line_option:crosstool_top": _FAKE_CC_TOOLCHAIN,
"//command_line_option:extra_toolchains": _FAKE_CC_TOOLCHAINS,
"//command_line_option:platforms": [_PLATFORM_MAC],
},
)
Expand Down Expand Up @@ -82,6 +84,7 @@ def _test_non_mac_doesnt_require_darwin_for_execution(name, config):
config_settings = {
"//command_line_option:cpu": "k8",
"//command_line_option:crosstool_top": _FAKE_CC_TOOLCHAIN,
"//command_line_option:extra_toolchains": _FAKE_CC_TOOLCHAINS,
"//command_line_option:platforms": [_PLATFORM_LINUX],
},
)
Expand Down

0 comments on commit 0d59fcf

Please sign in to comment.