From a39e79d8000503ae135e0228e8bc1eb70a963286 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Wed, 4 Sep 2024 12:35:07 -0700 Subject: [PATCH 1/2] tests: move various supporting code under tests/support * Move subject classes under support * Switch to using rules_testing DefaultInfo subject * Move fake cc toolchains under tests/support/cc_toolchains (these are used in several places, not just tests/cc) * Make literal references of old //tests/cc locations use the constants from support.bzl This is both for code clarity (support code being in a common location), but also to make it easier to import the support code for the subset of tests Google imports and runs. --- tests/base_rules/base_tests.bzl | 2 +- .../precompile/precompile_tests.bzl | 2 +- tests/base_rules/py_executable_base_tests.bzl | 10 +- tests/base_rules/py_test/py_test_tests.bzl | 15 +- tests/cc/BUILD.bazel | 137 ---------------- .../current_py_cc_headers_tests.bzl | 9 +- .../current_py_cc_libs_tests.bzl | 6 +- .../py_cc_toolchain/py_cc_toolchain_tests.bzl | 21 +-- .../transition/multi_version_tests.bzl | 3 +- tests/py_runtime/py_runtime_tests.bzl | 2 +- .../py_runtime_pair/py_runtime_pair_tests.bzl | 5 +- tests/runtime_env_toolchain/BUILD.bazel | 3 +- tests/{ => support}/cc_info_subject.bzl | 0 tests/support/cc_toolchains/BUILD.bazel | 150 ++++++++++++++++++ .../fake_cc_toolchain_config.bzl | 0 .../py_cc_toolchain_info_subject.bzl | 0 .../py_info_subject.bzl | 0 .../{ => support}/py_runtime_info_subject.bzl | 0 tests/support/sh_py_run_test.bzl | 2 +- tests/support/support.bzl | 3 +- 20 files changed, 188 insertions(+), 182 deletions(-) rename tests/{ => support}/cc_info_subject.bzl (100%) create mode 100644 tests/support/cc_toolchains/BUILD.bazel rename tests/{cc => support/cc_toolchains}/fake_cc_toolchain_config.bzl (100%) rename tests/{ => support}/py_cc_toolchain_info_subject.bzl (100%) rename tests/{base_rules => support}/py_info_subject.bzl (100%) rename tests/{ => support}/py_runtime_info_subject.bzl (100%) diff --git a/tests/base_rules/base_tests.bzl b/tests/base_rules/base_tests.bzl index fb95c15017..ae298edb4f 100644 --- a/tests/base_rules/base_tests.bzl +++ b/tests/base_rules/base_tests.bzl @@ -18,8 +18,8 @@ load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS", rt_util = "util") load("//python:defs.bzl", "PyInfo") load("//python/private:reexports.bzl", "BuiltinPyInfo") # buildifier: disable=bzl-visibility -load("//tests/base_rules:py_info_subject.bzl", "py_info_subject") load("//tests/base_rules:util.bzl", pt_util = "util") +load("//tests/support:py_info_subject.bzl", "py_info_subject") _tests = [] diff --git a/tests/base_rules/precompile/precompile_tests.bzl b/tests/base_rules/precompile/precompile_tests.bzl index 5599f6101f..62659fcfbd 100644 --- a/tests/base_rules/precompile/precompile_tests.bzl +++ b/tests/base_rules/precompile/precompile_tests.bzl @@ -23,7 +23,7 @@ load("//python:py_binary.bzl", "py_binary") load("//python:py_info.bzl", "PyInfo") load("//python:py_library.bzl", "py_library") load("//python:py_test.bzl", "py_test") -load("//tests/base_rules:py_info_subject.bzl", "py_info_subject") +load("//tests/support:py_info_subject.bzl", "py_info_subject") load( "//tests/support:support.bzl", "CC_TOOLCHAIN", diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl index 1f805cb153..873349f289 100644 --- a/tests/base_rules/py_executable_base_tests.bzl +++ b/tests/base_rules/py_executable_base_tests.bzl @@ -23,7 +23,7 @@ load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable load("//tests/base_rules:base_tests.bzl", "create_base_tests") load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util") load("//tests/support:py_executable_info_subject.bzl", "PyExecutableInfoSubject") -load("//tests/support:support.bzl", "LINUX_X86_64", "WINDOWS_X86_64") +load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "LINUX_X86_64", "WINDOWS_X86_64") _BuiltinPyRuntimeInfo = PyRuntimeInfo @@ -51,8 +51,8 @@ def _test_basic_windows(name, config): # platforms. "//command_line_option:build_python_zip": "true", "//command_line_option:cpu": "windows_x86_64", - "//command_line_option:crosstool_top": Label("//tests/cc:cc_toolchain_suite"), - "//command_line_option:extra_toolchains": [str(Label("//tests/cc:all"))], + "//command_line_option:crosstool_top": CROSSTOOL_TOP, + "//command_line_option:extra_toolchains": [CC_TOOLCHAIN], "//command_line_option:platforms": [WINDOWS_X86_64], }, attr_values = {"target_compatible_with": target_compatible_with}, @@ -96,8 +96,8 @@ def _test_basic_zip(name, config): # platforms. "//command_line_option:build_python_zip": "true", "//command_line_option:cpu": "linux_x86_64", - "//command_line_option:crosstool_top": Label("//tests/cc:cc_toolchain_suite"), - "//command_line_option:extra_toolchains": [str(Label("//tests/cc:all"))], + "//command_line_option:crosstool_top": CROSSTOOL_TOP, + "//command_line_option:extra_toolchains": [CC_TOOLCHAIN], "//command_line_option:platforms": [LINUX_X86_64], }, attr_values = {"target_compatible_with": target_compatible_with}, diff --git a/tests/base_rules/py_test/py_test_tests.bzl b/tests/base_rules/py_test/py_test_tests.bzl index c77bd7eb04..6bd31ed3f9 100644 --- a/tests/base_rules/py_test/py_test_tests.bzl +++ b/tests/base_rules/py_test/py_test_tests.bzl @@ -21,12 +21,7 @@ load( "create_executable_tests", ) load("//tests/base_rules:util.bzl", pt_util = "util") -load("//tests/support:support.bzl", "LINUX_X86_64", "MAC_X86_64") - -# Explicit Label() calls are required so that it resolves in @rules_python -# context instead of @rules_testing context. -_FAKE_CC_TOOLCHAIN = Label("//tests/cc:cc_toolchain_suite") -_FAKE_CC_TOOLCHAINS = [str(Label("//tests/cc:all"))] +load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "LINUX_X86_64", "MAC_X86_64") # The Windows CI currently runs as root, which breaks when # the analysis tests try to install (but not use, because @@ -63,8 +58,8 @@ def _test_mac_requires_darwin_for_execution(name, config): target = name + "_subject", 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:crosstool_top": CROSSTOOL_TOP, + "//command_line_option:extra_toolchains": CC_TOOLCHAIN, "//command_line_option:platforms": [MAC_X86_64], }, attr_values = _SKIP_WINDOWS, @@ -96,8 +91,8 @@ def _test_non_mac_doesnt_require_darwin_for_execution(name, config): target = name + "_subject", 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:crosstool_top": CROSSTOOL_TOP, + "//command_line_option:extra_toolchains": CC_TOOLCHAIN, "//command_line_option:platforms": [LINUX_X86_64], }, attr_values = _SKIP_WINDOWS, diff --git a/tests/cc/BUILD.bazel b/tests/cc/BUILD.bazel index 889f9e02d2..aa21042e25 100644 --- a/tests/cc/BUILD.bazel +++ b/tests/cc/BUILD.bazel @@ -11,140 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite") -load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS") -load("//python/cc:py_cc_toolchain.bzl", "py_cc_toolchain") -load(":fake_cc_toolchain_config.bzl", "fake_cc_toolchain_config") - -package(default_visibility = ["//:__subpackages__"]) - -exports_files(["fake_header.h"]) - -filegroup( - name = "libpython", - srcs = ["libpython-fake.so"], - tags = PREVENT_IMPLICIT_BUILDING_TAGS, -) - -toolchain( - name = "fake_py_cc_toolchain", - tags = PREVENT_IMPLICIT_BUILDING_TAGS, - toolchain = ":fake_py_cc_toolchain_impl", - toolchain_type = "@rules_python//python/cc:toolchain_type", -) - -py_cc_toolchain( - name = "fake_py_cc_toolchain_impl", - headers = ":fake_headers", - libs = ":fake_libs", - python_version = "3.999", - tags = PREVENT_IMPLICIT_BUILDING_TAGS, -) - -# buildifier: disable=native-cc -cc_library( - name = "fake_headers", - hdrs = ["fake_header.h"], - data = ["data.txt"], - includes = ["fake_include"], - tags = PREVENT_IMPLICIT_BUILDING_TAGS, -) - -# buildifier: disable=native-cc -cc_library( - name = "fake_libs", - srcs = ["libpython3.so"], - data = ["libdata.txt"], - tags = PREVENT_IMPLICIT_BUILDING_TAGS, -) - -cc_toolchain_suite( - name = "cc_toolchain_suite", - tags = ["manual"], - toolchains = { - "darwin_x86_64": ":mac_toolchain", - "k8": ":linux_toolchain", - "windows_x86_64": ":windows_toolchain", - }, -) - -filegroup(name = "empty") - -cc_toolchain( - name = "mac_toolchain", - all_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - toolchain_config = ":mac_toolchain_config", - 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", - toolchain_identifier = "mac-toolchain", -) - -cc_toolchain( - name = "linux_toolchain", - all_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - toolchain_config = ":linux_toolchain_config", - 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", - toolchain_identifier = "linux-toolchain", -) - -cc_toolchain( - name = "windows_toolchain", - all_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - toolchain_config = ":windows_toolchain_config", - toolchain_identifier = "windows-toolchain", -) - -toolchain( - name = "windows_toolchain_definition", - target_compatible_with = ["@platforms//os:windows"], - toolchain = ":windows_toolchain", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -fake_cc_toolchain_config( - name = "windows_toolchain_config", - target_cpu = "windows_x86_64", - toolchain_identifier = "windows-toolchain", -) diff --git a/tests/cc/current_py_cc_headers/current_py_cc_headers_tests.bzl b/tests/cc/current_py_cc_headers/current_py_cc_headers_tests.bzl index 9aeec38698..8bbdaceaf0 100644 --- a/tests/cc/current_py_cc_headers/current_py_cc_headers_tests.bzl +++ b/tests/cc/current_py_cc_headers/current_py_cc_headers_tests.bzl @@ -17,7 +17,8 @@ load("@rules_cc//cc:defs.bzl", "CcInfo") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") -load("//tests:cc_info_subject.bzl", "cc_info_subject") +load("//tests/support:cc_info_subject.bzl", "cc_info_subject") +load("//tests/support:support.bzl", "CC_TOOLCHAIN") _tests = [] @@ -27,11 +28,11 @@ def _test_current_toolchain_headers(name): impl = _test_current_toolchain_headers_impl, target = "//python/cc:current_py_cc_headers", config_settings = { - "//command_line_option:extra_toolchains": [str(Label("//tests/cc:all"))], + "//command_line_option:extra_toolchains": [CC_TOOLCHAIN], }, attrs = { "header": attr.label( - default = "//tests/cc:fake_header.h", + default = "//tests/support/cc_toolchains:fake_header.h", allow_single_file = True, ), }, @@ -58,7 +59,7 @@ def _test_current_toolchain_headers_impl(env, target): # Check that the forward DefaultInfo looks correct env.expect.that_target(target).runfiles().contains_predicate( - matching.str_matches("*/cc/data.txt"), + matching.str_matches("*/cc_toolchains/data.txt"), ) _tests.append(_test_current_toolchain_headers) diff --git a/tests/cc/current_py_cc_libs/current_py_cc_libs_tests.bzl b/tests/cc/current_py_cc_libs/current_py_cc_libs_tests.bzl index 44615eeb4b..4a08ce745e 100644 --- a/tests/cc/current_py_cc_libs/current_py_cc_libs_tests.bzl +++ b/tests/cc/current_py_cc_libs/current_py_cc_libs_tests.bzl @@ -17,7 +17,7 @@ load("@rules_cc//cc:defs.bzl", "CcInfo") load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching") -load("//tests:cc_info_subject.bzl", "cc_info_subject") +load("//tests/support:cc_info_subject.bzl", "cc_info_subject") _tests = [] @@ -27,11 +27,11 @@ def _test_current_toolchain_libs(name): impl = _test_current_toolchain_libs_impl, target = "//python/cc:current_py_cc_libs", config_settings = { - "//command_line_option:extra_toolchains": [str(Label("//tests/cc:all"))], + "//command_line_option:extra_toolchains": [str(Label("//tests/support/cc_toolchains:all"))], }, attrs = { "lib": attr.label( - default = "//tests/cc:libpython", + default = "//tests/support/cc_toolchains:libpython", allow_single_file = True, ), }, diff --git a/tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl b/tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl index fe83bf2e2d..fcc520e291 100644 --- a/tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl +++ b/tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl @@ -16,9 +16,8 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") load("@rules_testing//lib:truth.bzl", "matching", "subjects") -load("//tests:cc_info_subject.bzl", "cc_info_subject") -load("//tests:default_info_subject.bzl", "default_info_subject") -load("//tests:py_cc_toolchain_info_subject.bzl", "PyCcToolchainInfoSubject") +load("//tests/support:cc_info_subject.bzl", "cc_info_subject") +load("//tests/support:py_cc_toolchain_info_subject.bzl", "PyCcToolchainInfoSubject") _tests = [] @@ -26,10 +25,10 @@ def _py_cc_toolchain_test(name): analysis_test( name = name, impl = _py_cc_toolchain_test_impl, - target = "//tests/cc:fake_py_cc_toolchain_impl", + target = "//tests/support/cc_toolchains:fake_py_cc_toolchain_impl", attrs = { "header": attr.label( - default = "//tests/cc:fake_header.h", + default = "//tests/support/cc_toolchains:fake_header.h", allow_single_file = True, ), }, @@ -63,15 +62,9 @@ def _py_cc_toolchain_test_impl(env, target): matching.str_matches("*/fake_include"), ]) - # TODO: Once subjects.default_info is available, do - # default_info = headers_providers.get("DefaultInfo", factory=subjects.default_info) - # https://github.com/bazelbuild/rules_python/issues/1297 - default_info = default_info_subject( - headers_providers.get("DefaultInfo", factory = lambda v, meta: v), - meta = env.expect.meta.derive(expr = "default_info"), - ) + default_info = headers_providers.get("DefaultInfo", factory = subjects.default_info) default_info.runfiles().contains_predicate( - matching.str_matches("*/cc/data.txt"), + matching.str_matches("*/cc_toolchains/data.txt"), ) libs_providers = toolchain.libs().providers_map() @@ -82,7 +75,7 @@ def _py_cc_toolchain_test_impl(env, target): cc_info.linking_context().linker_inputs().has_size(2) default_info = libs_providers.get("DefaultInfo", factory = subjects.default_info) - default_info.runfiles().contains("{workspace}/tests/cc/libdata.txt") + default_info.runfiles().contains("{workspace}/tests/support/cc_toolchains/libdata.txt") default_info.runfiles().contains_predicate( matching.str_matches("/libpython3."), ) diff --git a/tests/config_settings/transition/multi_version_tests.bzl b/tests/config_settings/transition/multi_version_tests.bzl index 6659da574c..367837b3fb 100644 --- a/tests/config_settings/transition/multi_version_tests.bzl +++ b/tests/config_settings/transition/multi_version_tests.bzl @@ -20,6 +20,7 @@ load("//python:py_info.bzl", "PyInfo") load("//python/config_settings:transition.bzl", py_binary_transitioned = "py_binary", py_test_transitioned = "py_test") load("//python/private:reexports.bzl", "BuiltinPyInfo") # buildifier: disable=bzl-visibility load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility +load("//tests/support:support.bzl", "CC_TOOLCHAIN") # NOTE @aignas 2024-06-04: we are using here something that is registered in the MODULE.Bazel # and if you find tests failing, it could be because of the toolchain resolution issues here. @@ -87,7 +88,7 @@ def _setup_py_binary_windows(name, *, impl, build_python_zip): impl = impl, config_settings = { "//command_line_option:build_python_zip": build_python_zip, - "//command_line_option:extra_toolchains": "//tests/cc:all", + "//command_line_option:extra_toolchains": CC_TOOLCHAIN, "//command_line_option:platforms": str(Label("//tests/support:windows_x86_64")), }, ) diff --git a/tests/py_runtime/py_runtime_tests.bzl b/tests/py_runtime/py_runtime_tests.bzl index b47923d4ed..596cace4fc 100644 --- a/tests/py_runtime/py_runtime_tests.bzl +++ b/tests/py_runtime/py_runtime_tests.bzl @@ -20,8 +20,8 @@ load("@rules_testing//lib:truth.bzl", "matching") load("@rules_testing//lib:util.bzl", rt_util = "util") load("//python:py_runtime.bzl", "py_runtime") load("//python:py_runtime_info.bzl", "PyRuntimeInfo") -load("//tests:py_runtime_info_subject.bzl", "py_runtime_info_subject") load("//tests/base_rules:util.bzl", br_util = "util") +load("//tests/support:py_runtime_info_subject.bzl", "py_runtime_info_subject") _tests = [] diff --git a/tests/py_runtime_pair/py_runtime_pair_tests.bzl b/tests/py_runtime_pair/py_runtime_pair_tests.bzl index 236f1ba3a5..e89e080868 100644 --- a/tests/py_runtime_pair/py_runtime_pair_tests.bzl +++ b/tests/py_runtime_pair/py_runtime_pair_tests.bzl @@ -21,7 +21,8 @@ load("//python:py_binary.bzl", "py_binary") load("//python:py_runtime.bzl", "py_runtime") load("//python:py_runtime_pair.bzl", "py_runtime_pair") load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo") # buildifier: disable=bzl-visibility -load("//tests:py_runtime_info_subject.bzl", "py_runtime_info_subject") +load("//tests/support:py_runtime_info_subject.bzl", "py_runtime_info_subject") +load("//tests/support:support.bzl", "CC_TOOLCHAIN") def _toolchain_factory(value, meta): return subjects.struct( @@ -129,7 +130,7 @@ def _test_py_runtime_pair_and_binary(name): config_settings = { "//command_line_option:extra_toolchains": [ "//tests/py_runtime_pair:{}_toolchain".format(name), - "//tests/cc:all", + CC_TOOLCHAIN, ], }, ) diff --git a/tests/runtime_env_toolchain/BUILD.bazel b/tests/runtime_env_toolchain/BUILD.bazel index 99bdbab101..afc6b587f0 100644 --- a/tests/runtime_env_toolchain/BUILD.bazel +++ b/tests/runtime_env_toolchain/BUILD.bazel @@ -13,6 +13,7 @@ # limitations under the License. load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test") +load("//tests/support:support.bzl", "CC_TOOLCHAIN") load(":runtime_env_toolchain_tests.bzl", "runtime_env_toolchain_test_suite") runtime_env_toolchain_test_suite(name = "runtime_env_toolchain_tests") @@ -26,7 +27,7 @@ py_reconfig_test( extra_toolchains = [ "//python/runtime_env_toolchains:all", # Necessary for RBE CI - "//tests/cc:all", + CC_TOOLCHAIN, ], main = "toolchain_runs_test.py", deps = ["//python/runfiles"], diff --git a/tests/cc_info_subject.bzl b/tests/support/cc_info_subject.bzl similarity index 100% rename from tests/cc_info_subject.bzl rename to tests/support/cc_info_subject.bzl diff --git a/tests/support/cc_toolchains/BUILD.bazel b/tests/support/cc_toolchains/BUILD.bazel new file mode 100644 index 0000000000..889f9e02d2 --- /dev/null +++ b/tests/support/cc_toolchains/BUILD.bazel @@ -0,0 +1,150 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite") +load("@rules_testing//lib:util.bzl", "PREVENT_IMPLICIT_BUILDING_TAGS") +load("//python/cc:py_cc_toolchain.bzl", "py_cc_toolchain") +load(":fake_cc_toolchain_config.bzl", "fake_cc_toolchain_config") + +package(default_visibility = ["//:__subpackages__"]) + +exports_files(["fake_header.h"]) + +filegroup( + name = "libpython", + srcs = ["libpython-fake.so"], + tags = PREVENT_IMPLICIT_BUILDING_TAGS, +) + +toolchain( + name = "fake_py_cc_toolchain", + tags = PREVENT_IMPLICIT_BUILDING_TAGS, + toolchain = ":fake_py_cc_toolchain_impl", + toolchain_type = "@rules_python//python/cc:toolchain_type", +) + +py_cc_toolchain( + name = "fake_py_cc_toolchain_impl", + headers = ":fake_headers", + libs = ":fake_libs", + python_version = "3.999", + tags = PREVENT_IMPLICIT_BUILDING_TAGS, +) + +# buildifier: disable=native-cc +cc_library( + name = "fake_headers", + hdrs = ["fake_header.h"], + data = ["data.txt"], + includes = ["fake_include"], + tags = PREVENT_IMPLICIT_BUILDING_TAGS, +) + +# buildifier: disable=native-cc +cc_library( + name = "fake_libs", + srcs = ["libpython3.so"], + data = ["libdata.txt"], + tags = PREVENT_IMPLICIT_BUILDING_TAGS, +) + +cc_toolchain_suite( + name = "cc_toolchain_suite", + tags = ["manual"], + toolchains = { + "darwin_x86_64": ":mac_toolchain", + "k8": ":linux_toolchain", + "windows_x86_64": ":windows_toolchain", + }, +) + +filegroup(name = "empty") + +cc_toolchain( + name = "mac_toolchain", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":mac_toolchain_config", + 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", + toolchain_identifier = "mac-toolchain", +) + +cc_toolchain( + name = "linux_toolchain", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":linux_toolchain_config", + 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", + toolchain_identifier = "linux-toolchain", +) + +cc_toolchain( + name = "windows_toolchain", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":windows_toolchain_config", + toolchain_identifier = "windows-toolchain", +) + +toolchain( + name = "windows_toolchain_definition", + target_compatible_with = ["@platforms//os:windows"], + toolchain = ":windows_toolchain", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) + +fake_cc_toolchain_config( + name = "windows_toolchain_config", + target_cpu = "windows_x86_64", + toolchain_identifier = "windows-toolchain", +) diff --git a/tests/cc/fake_cc_toolchain_config.bzl b/tests/support/cc_toolchains/fake_cc_toolchain_config.bzl similarity index 100% rename from tests/cc/fake_cc_toolchain_config.bzl rename to tests/support/cc_toolchains/fake_cc_toolchain_config.bzl diff --git a/tests/py_cc_toolchain_info_subject.bzl b/tests/support/py_cc_toolchain_info_subject.bzl similarity index 100% rename from tests/py_cc_toolchain_info_subject.bzl rename to tests/support/py_cc_toolchain_info_subject.bzl diff --git a/tests/base_rules/py_info_subject.bzl b/tests/support/py_info_subject.bzl similarity index 100% rename from tests/base_rules/py_info_subject.bzl rename to tests/support/py_info_subject.bzl diff --git a/tests/py_runtime_info_subject.bzl b/tests/support/py_runtime_info_subject.bzl similarity index 100% rename from tests/py_runtime_info_subject.bzl rename to tests/support/py_runtime_info_subject.bzl diff --git a/tests/support/sh_py_run_test.bzl b/tests/support/sh_py_run_test.bzl index 455f64e49f..32df5b8caf 100644 --- a/tests/support/sh_py_run_test.bzl +++ b/tests/support/sh_py_run_test.bzl @@ -99,7 +99,7 @@ def _make_reconfig_rule(**kwargs): doc = """ Value for the --extra_toolchains flag. -NOTE: You'll likely have to also specify //tests/cc:all (or some CC toolchain) +NOTE: You'll likely have to also specify //tests/support/cc_toolchains:all (or some CC toolchain) to make the RBE presubmits happy, which disable auto-detection of a CC toolchain. """, diff --git a/tests/support/support.bzl b/tests/support/support.bzl index a74346d7b3..098ada06de 100644 --- a/tests/support/support.bzl +++ b/tests/support/support.bzl @@ -27,7 +27,8 @@ WINDOWS = Label("//tests/support:windows") WINDOWS_X86_64 = Label("//tests/support:windows_x86_64") PLATFORM_TOOLCHAIN = str(Label("//tests/support:platform_toolchain")) -CC_TOOLCHAIN = str(Label("//tests/cc:all")) +CC_TOOLCHAIN = str(Label("//tests/support/cc_toolchains:all")) +CROSSTOOL_TOP = Label("//tests/cc:cc_toolchain_suite") # str() around Label() is necessary because rules_testing's config_settings # doesn't accept yet Label objects. From 6cf380c5355973a17f04aee8a06e09f1accc3186 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Wed, 4 Sep 2024 20:32:43 -0700 Subject: [PATCH 2/2] fixup! tests: move various supporting code under tests/support --- tests/support/support.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/support/support.bzl b/tests/support/support.bzl index 098ada06de..b7d8fa9fa6 100644 --- a/tests/support/support.bzl +++ b/tests/support/support.bzl @@ -28,7 +28,7 @@ WINDOWS_X86_64 = Label("//tests/support:windows_x86_64") PLATFORM_TOOLCHAIN = str(Label("//tests/support:platform_toolchain")) CC_TOOLCHAIN = str(Label("//tests/support/cc_toolchains:all")) -CROSSTOOL_TOP = Label("//tests/cc:cc_toolchain_suite") +CROSSTOOL_TOP = Label("//tests/support/cc_toolchains:cc_toolchain_suite") # str() around Label() is necessary because rules_testing's config_settings # doesn't accept yet Label objects.