From 3ca03ec4261fb9dce4ecf8e977b8672ed4309307 Mon Sep 17 00:00:00 2001 From: aignas <240938+aignas@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:26:56 +0900 Subject: [PATCH] Fix the select statements Test that the generated selects are actually correct --- python/config_settings/config_settings.bzl | 2 +- tests/toolchains/BUILD.bazel | 1 + tests/toolchains/config_settings/BUILD.bazel | 54 ++++++++++++++++++++ tests/toolchains/config_settings/want | 27 ++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tests/toolchains/config_settings/BUILD.bazel create mode 100644 tests/toolchains/config_settings/want diff --git a/python/config_settings/config_settings.bzl b/python/config_settings/config_settings.bzl index 7858364c90..cf19838bc6 100644 --- a/python/config_settings/config_settings.bzl +++ b/python/config_settings/config_settings.bzl @@ -95,7 +95,7 @@ def construct_config_settings(name, python_versions): ) native.alias( name = is_micro_version_name, - actual = "_is_python_" + minor_version, + actual = "_" + is_micro_version_name, visibility = ["//visibility:public"], ) matches_minor_version_names.append(equals_micro_name) diff --git a/tests/toolchains/BUILD.bazel b/tests/toolchains/BUILD.bazel index 2f804a4ca0..940e3a921a 100644 --- a/tests/toolchains/BUILD.bazel +++ b/tests/toolchains/BUILD.bazel @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel_skylib//rules:diff_test.bzl", "diff_test") load(":defs.bzl", "acceptance_tests") load(":versions_test.bzl", "versions_test_suite") diff --git a/tests/toolchains/config_settings/BUILD.bazel b/tests/toolchains/config_settings/BUILD.bazel new file mode 100644 index 0000000000..1a20a307b0 --- /dev/null +++ b/tests/toolchains/config_settings/BUILD.bazel @@ -0,0 +1,54 @@ +# 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 new file mode 100644 index 0000000000..0ecbd67b62 --- /dev/null +++ b/tests/toolchains/config_settings/want @@ -0,0 +1,27 @@ +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"}, +) +