Skip to content

Commit 5b81c97

Browse files
committed
Allow using requires_none and requires_not_none at the same time
This combination can be useful during migrations from old bazel features to new ones. You add your args as requiring the new feature to be not none, and the old feature to be none.
1 parent 62a7164 commit 5b81c97

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

cc/toolchains/impl/nested_args.bzl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ visibility([
2323
"//tests/rule_based_toolchain/...",
2424
])
2525

26-
REQUIRES_MUTUALLY_EXCLUSIVE_ERR = "requires_none, requires_not_none, requires_true, requires_false, and requires_equal are mutually exclusive"
26+
REQUIRES_MUTUALLY_EXCLUSIVE_ERR = "requires_none and requires_not_none are mututally exclusive with requires_true, requires_false, and requires_equal"
2727
REQUIRES_NOT_NONE_ERR = "requires_not_none only works on options"
2828
REQUIRES_NONE_ERR = "requires_none only works on options"
2929
REQUIRES_TRUE_ERR = "requires_true only works on bools"
@@ -198,17 +198,11 @@ def nested_args_provider(
198198
transitive_files = [ea.files for ea in nested]
199199
transitive_files.append(files)
200200

201-
has_value = [attr for attr in [
202-
requires_not_none,
203-
requires_none,
204-
requires_true,
205-
requires_false,
206-
requires_equal,
207-
] if attr != None]
208-
209201
# We may want to reconsider this down the line, but it's easier to open up
210202
# an API than to lock down an API.
211-
if len(has_value) > 1:
203+
optional_checks = any([requires_not_none, requires_none])
204+
boolean_checks = any([requires_true, requires_false, requires_equal])
205+
if optional_checks and boolean_checks:
212206
fail(REQUIRES_MUTUALLY_EXCLUSIVE_ERR)
213207

214208
kwargs = {}

0 commit comments

Comments
 (0)