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 3ca03ec
Show file tree
Hide file tree
Showing 4 changed files with 83 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
54 changes: 54 additions & 0 deletions tests/toolchains/config_settings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
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 3ca03ec

Please sign in to comment.