Switch everything to @platforms//:incompatible
This commit is contained in:
parent
0d87298560
commit
9eb896ec83
|
@ -20,7 +20,6 @@ bzl_library(
|
|||
srcs = ["compatibility.bzl"],
|
||||
deps = [
|
||||
":selects",
|
||||
"//lib/compatibility:defs",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ more information.
|
|||
"""
|
||||
|
||||
load(":selects.bzl", "selects")
|
||||
load("//lib/compatibility:defs.bzl", "MAX_NUM_ALL_OF_SETTINGS")
|
||||
|
||||
def _none_of(*settings):
|
||||
"""Create a `select()` for `target_compatible_with` which matches none of the given settings.
|
||||
|
@ -40,7 +39,7 @@ def _none_of(*settings):
|
|||
A native `select()` which maps any of the settings to the incompatible target.
|
||||
"""
|
||||
return selects.with_or({
|
||||
tuple(settings): ["@bazel_skylib//lib/compatibility:incompatible_in_none_of"],
|
||||
tuple(settings): ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
|
@ -73,7 +72,7 @@ def _any_of(*settings):
|
|||
"""
|
||||
return selects.with_or({
|
||||
tuple(settings): [],
|
||||
"//conditions:default": ["@bazel_skylib//lib/compatibility:incompatible_in_any_of"],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
})
|
||||
|
||||
def _all_of(*settings):
|
||||
|
@ -112,14 +111,11 @@ def _all_of(*settings):
|
|||
Returns:
|
||||
A native series of `select()`s. The result is "incompatible" unless all settings are true.
|
||||
"""
|
||||
if len(settings) > MAX_NUM_ALL_OF_SETTINGS:
|
||||
fail("Cannot support more than {} arguments. Use selects.config_setting_group() instead.".format(MAX_NUM_ALL_OF_SETTINGS))
|
||||
|
||||
result = []
|
||||
for i, setting in enumerate(settings):
|
||||
for setting in settings:
|
||||
result += select({
|
||||
setting: [],
|
||||
"//conditions:default": ["@bazel_skylib//lib/compatibility:incompatible_in_all_of_{}".format(i)],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
})
|
||||
return result
|
||||
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
load(":defs.bzl", "MAX_NUM_ALL_OF_SETTINGS")
|
||||
load("//:bzl_library.bzl", "bzl_library")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
bzl_library(
|
||||
name = "defs",
|
||||
srcs = ["defs.bzl"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "build_file",
|
||||
testonly = True,
|
||||
srcs = ["BUILD"],
|
||||
)
|
||||
|
||||
# We create custom incompatible constraints here instead of using the more
|
||||
# general @platforms//:incompatible constraint. We do this because we cannot
|
||||
# compose multiple select() statements that point at the same constraint. Bazel
|
||||
# complains about duplicated labels in the "target_compatible_with" attribute.
|
||||
#
|
||||
# For example, the following select() statements may cause bazel to error out.
|
||||
#
|
||||
# foo_binary(
|
||||
# name = "bin",
|
||||
# target_compatible_with = select({
|
||||
# "//some:config1": ["@platforms//:incompatible"],
|
||||
# "//conditions:default": [],
|
||||
# }) + select({
|
||||
# "//some:config2": [],
|
||||
# "//conditions:default": ["@platforms//:incompatible"],
|
||||
# }),
|
||||
# )
|
||||
#
|
||||
# The above can be read as "If //some:config1 is true or //some:config2 is
|
||||
# false, then "bin" is incompatible". If both select() statements evaluate to
|
||||
# @platforms//:incompatible, however, then bazel will error out and complain
|
||||
# about duplicated labels.
|
||||
|
||||
constraint_value(
|
||||
name = "incompatible_in_none_of",
|
||||
constraint_setting = "@platforms//:incompatible_setting",
|
||||
)
|
||||
|
||||
constraint_value(
|
||||
name = "incompatible_in_any_of",
|
||||
constraint_setting = "@platforms//:incompatible_setting",
|
||||
)
|
||||
|
||||
[constraint_value(
|
||||
name = "incompatible_in_all_of_" + str(i),
|
||||
constraint_setting = "@platforms//:incompatible_setting",
|
||||
) for i in range(MAX_NUM_ALL_OF_SETTINGS)]
|
|
@ -1,4 +0,0 @@
|
|||
"""Implementation details for lib/compatibility.bzl."""
|
||||
|
||||
# The maximum number of arguments we support for compatibility.all_of().
|
||||
MAX_NUM_ALL_OF_SETTINGS = 50
|
|
@ -98,7 +98,6 @@ sh_test(
|
|||
data = [
|
||||
":unittest.bash",
|
||||
"//lib:compatibility",
|
||||
"//lib/compatibility:build_file",
|
||||
],
|
||||
tags = ["local"],
|
||||
deps = [
|
||||
|
|
|
@ -52,6 +52,8 @@ if "$is_windows"; then
|
|||
fi
|
||||
|
||||
function set_up() {
|
||||
export PATH="/home/jenkins/repos/bazel/bazel-bin/src:${PATH}"
|
||||
|
||||
mkdir -p target_skipping || fail "couldn't create directory"
|
||||
|
||||
cat > target_skipping/pass.sh <<EOF || fail "couldn't create pass.sh"
|
||||
|
@ -79,7 +81,7 @@ EOF
|
|||
cat > lib/BUILD <<EOF
|
||||
EOF
|
||||
|
||||
for file in compatibility.bzl selects.bzl compatibility/BUILD compatibility/defs.bzl; do
|
||||
for file in compatibility.bzl selects.bzl; do
|
||||
mkdir -p "$(dirname "lib/${file}")" \
|
||||
|| fail "couldn't mkdir for ${file}"
|
||||
ln -sf "$(rlocation "bazel_skylib/lib/${file}")" "lib/${file}" \
|
||||
|
@ -227,7 +229,7 @@ EOF
|
|||
|
||||
ensure_that_target_doesnt_build_for_platforms \
|
||||
//target_skipping:pass_on_foo1_or_foo2_but_not_on_foo3 \
|
||||
"didn't satisfy constraint //lib/compatibility:incompatible_in_any_of$" \
|
||||
"didn't satisfy constraint @platforms//:incompatible$" \
|
||||
//target_skipping:foo3_platform \
|
||||
//target_skipping:bar1_platform
|
||||
}
|
||||
|
@ -250,7 +252,7 @@ EOF
|
|||
|
||||
ensure_that_target_doesnt_build_for_platforms \
|
||||
//target_skipping:pass_on_everything_but_foo1_and_foo2 \
|
||||
"didn't satisfy constraint //lib/compatibility:incompatible_in_none_of$" \
|
||||
"didn't satisfy constraint @platforms//:incompatible$" \
|
||||
//target_skipping:foo1_bar1_platform \
|
||||
//target_skipping:foo2_bar1_platform \
|
||||
//target_skipping:foo2_bar2_platform
|
||||
|
@ -273,7 +275,7 @@ EOF
|
|||
|
||||
ensure_that_target_doesnt_build_for_platforms \
|
||||
//target_skipping:pass_on_only_foo1_and_bar1 \
|
||||
"didn't satisfy constraints\\? \\[\\?//lib/compatibility:incompatible_in_all_of_" \
|
||||
"didn't satisfy constraint @platforms//:incompatible" \
|
||||
//target_skipping:foo2_bar1_platform \
|
||||
//target_skipping:foo2_bar2_platform \
|
||||
//target_skipping:foo3_platform \
|
||||
|
@ -301,23 +303,19 @@ EOF
|
|||
|
||||
ensure_that_target_doesnt_build_for_platforms \
|
||||
//target_skipping:pass_on_foo1_or_foo2_but_not_bar1 \
|
||||
"didn't satisfy constraint //lib/compatibility:incompatible_in_none_of$" \
|
||||
"didn't satisfy constraint @platforms//:incompatible$" \
|
||||
//target_skipping:foo1_bar1_platform \
|
||||
//target_skipping:foo2_bar1_platform
|
||||
|
||||
ensure_that_target_doesnt_build_for_platforms \
|
||||
//target_skipping:pass_on_foo1_or_foo2_but_not_bar1 \
|
||||
"didn't satisfy constraint //lib/compatibility:incompatible_in_any_of$" \
|
||||
"didn't satisfy constraint @platforms//:incompatible$" \
|
||||
//target_skipping:foo3_platform
|
||||
|
||||
ensure_that_target_doesnt_build_for_platforms \
|
||||
//target_skipping:pass_on_foo1_or_foo2_but_not_bar1 \
|
||||
"didn't satisfy constraints \\[//lib/compatibility:incompatible_in_" \
|
||||
"didn't satisfy constraint @platforms//:incompatible$" \
|
||||
//target_skipping:bar1_platform
|
||||
# Since the order of constraints isn't guaranteed until
|
||||
# 72787a1267a6087923aca83bf161f93c0a1323e0, we do two individual checks here.
|
||||
expect_log "//lib/compatibility:incompatible_in_any_of\\>"
|
||||
expect_log "//lib/compatibility:incompatible_in_none_of\\>"
|
||||
}
|
||||
|
||||
cd "$TEST_TMPDIR"
|
||||
|
|
Loading…
Reference in New Issue