diff --git a/tests/config_settings/construct_config_settings_tests.bzl b/tests/config_settings/construct_config_settings_tests.bzl index 8e4217139f..61beb9cd40 100644 --- a/tests/config_settings/construct_config_settings_tests.bzl +++ b/tests/config_settings/construct_config_settings_tests.bzl @@ -13,6 +13,7 @@ # limitations under the License. """Tests for construction of Python version matching config settings.""" +load("@//python:versions.bzl", "MINOR_MAPPING") load("@rules_testing//lib:analysis_test.bzl", "analysis_test") load("@rules_testing//lib:test_suite.bzl", "test_suite") load("@rules_testing//lib:truth.bzl", "subjects") @@ -30,6 +31,7 @@ _subject = rule( "match_micro": attr.string(), "match_minor": attr.string(), "no_match": attr.string(), + "no_match_micro": attr.string(), }, ) @@ -74,6 +76,54 @@ def _test_minor_version_matching_impl(env, target): _tests.append(_test_minor_version_matching) +def _test_latest_micro_version_matching(name): + rt_util.helper_target( + _subject, + name = name + "_subject", + match_minor = select({ + "//python/config_settings:is_python_3.12": "matched-3.12", + "//conditions:default": "matched-default", + }), + match_micro = select({ + "//python/config_settings:is_python_" + MINOR_MAPPING["3.12"]: "matched-3.12", + "//conditions:default": "matched-default", + }), + no_match_micro = select({ + "//python/config_settings:is_python_3.12.0": "matched-3.12", + "//conditions:default": "matched-default", + }), + no_match = select({ + "//python/config_settings:is_python_" + MINOR_MAPPING["3.11"]: "matched-3.11", + "//conditions:default": "matched-default", + }), + ) + + analysis_test( + name = name, + target = name + "_subject", + impl = _test_latest_micro_version_matching_impl, + config_settings = { + str(Label("//python/config_settings:python_version")): "3.12", + }, + ) + +def _test_latest_micro_version_matching_impl(env, target): + target = env.expect.that_target(target) + target.attr("match_minor", factory = subjects.str).equals( + "matched-3.12", + ) + target.attr("match_micro", factory = subjects.str).equals( + "matched-3.12", + ) + target.attr("no_match_micro", factory = subjects.str).equals( + "matched-default", + ) + target.attr("no_match", factory = subjects.str).equals( + "matched-default", + ) + +_tests.append(_test_latest_micro_version_matching) + def construct_config_settings_test_suite(name): test_suite( name = name, diff --git a/tests/toolchains/config_settings/BUILD.bazel b/tests/toolchains/config_settings/BUILD.bazel deleted file mode 100644 index babd19f17a..0000000000 --- a/tests/toolchains/config_settings/BUILD.bazel +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2024 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("@bazel_skylib//rules:diff_test.bzl", "diff_test") - -# Do bazel query for the following targets and put the results into a file -_TARGETS = [ - "is_python_3.12.0", - "is_python_3.12.1", - "_is_python_3.12.1", - "_python_version_flag_equals_3.12.1", - "_python_version_flag_equals_3.12", -] - -[ - genquery( - name = target, - expression = "//python/config_settings:" + target, - opts = ["--output=build"], - scope = ["//python/config_settings:" + target], - ) - for target in _TARGETS -] - -genrule( - name = "config_settings_query", - srcs = _TARGETS, - outs = ["config_settings_query.txt"], - # Strip comments that are specific to the host it is being run on and make the - # expectation output more maintainable. - cmd = "sed -e '/^#/d' -e '/^ generator_/d' $(SRCS) >$@", - target_compatible_with = select({ - # We don't have sed available on Windows - "@platforms//os:windows": ["@platforms//:incompatible"], - "//conditions:default": [], - }), -) - -diff_test( - name = "config_settings_test", - file1 = "want", - file2 = "config_settings_query", -) diff --git a/tests/toolchains/config_settings/want b/tests/toolchains/config_settings/want deleted file mode 100644 index 0ecbd67b62..0000000000 --- a/tests/toolchains/config_settings/want +++ /dev/null @@ -1,27 +0,0 @@ -config_setting( - name = "is_python_3.12.0", - visibility = ["//visibility:public"], - flag_values = {"//python/config_settings:python_version": "3.12.0"}, -) - -alias( - name = "is_python_3.12.1", - visibility = ["//visibility:public"], - actual = "//python/config_settings:_is_python_3.12.1", -) - -alias( - name = "_is_python_3.12.1", - actual = select({"//python/config_settings:_python_version_flag_equals_3.12.1": "//python/config_settings:_python_version_flag_equals_3.12.1", "//conditions:default": "//python/config_settings:_python_version_flag_equals_3.12"}), -) - -config_setting( - name = "_python_version_flag_equals_3.12.1", - flag_values = {"//python/config_settings:python_version": "3.12.1"}, -) - -config_setting( - name = "_python_version_flag_equals_3.12", - flag_values = {"//python/config_settings:python_version": "3.12"}, -) -