Skip to content

Commit

Permalink
Fix the select statements
Browse files Browse the repository at this point in the history
Test that the generated selects are actually correct
  • Loading branch information
aignas committed Jan 31, 2024
1 parent b739ed2 commit bc89626
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/config_settings/config_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
77 changes: 77 additions & 0 deletions tests/toolchains/config_settings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 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")

# This test is to check that the latest version select is an alias to a different value
genquery(
name = "config_setting_with_minor_query",
expression = "//python/config_settings:is_python_3.12.1",
opts=["--output=build"],
scope = ["//python/config_settings:is_python_3.12.1"],
)

genquery(
name = "config_setting_with_minor_query_private",
expression = "//python/config_settings:_is_python_3.12.1",
opts=["--output=build"],
scope = ["//python/config_settings:_is_python_3.12.1"],
)

genquery(
name = "config_setting_with_minor_query_private_2",
expression = "//python/config_settings:_python_version_flag_equals_3.12.1",
opts=["--output=build"],
scope = ["//python/config_settings:_python_version_flag_equals_3.12.1"],
)

genquery(
name = "config_setting_with_minor_query_private_3",
expression = "//python/config_settings:_python_version_flag_equals_3.12",
opts=["--output=build"],
scope = ["//python/config_settings:_python_version_flag_equals_3.12"],
)

genquery(
name = "config_setting_regular_query",
expression = "//python/config_settings:is_python_3.12.0",
opts=["--output=build"],
scope = ["//python/config_settings:is_python_3.12.0"],
)

genrule(
name = "config_settings_query",
srcs = [
"config_setting_regular_query",
"config_setting_with_minor_query",
"config_setting_with_minor_query_private",
"config_setting_with_minor_query_private_2",
"config_setting_with_minor_query_private_3",
],
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",
)
27 changes: 27 additions & 0 deletions tests/toolchains/config_settings/want
Original file line number Diff line number Diff line change
@@ -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"},
)

0 comments on commit bc89626

Please sign in to comment.