bazelbuild / bazelbuild/bazel-skylib

Feature Request: Negative/Not conditionals for `selects`

Open
#272 22 comments 1 reaction 0 assignees View on GitHub
P3 type: feature request
Dominant language
Starlark
Stars
444
Forks
202
PR merge metrics
No merged PRs in 30d

Description

I don't have a clear proposal right now but wanted to put the request up to see if anyone else has thoughts or is interested.

I would like to use negative conditionals in [selects](https://github.com/bazelbuild/bazel-skylib/blob/master/docs/selects_doc.md) functions. I'm not sure what that might look like. My initial thought was that there would be some string parsing done on the strings passed into the `selects` macros.

Example:
```python
selects.with_or({
(
# This is a normal condition
":some_normal_condition",

# This is one proposal that uses the `!` character to indicate
# this condition is a negative condition
"!:some_negative_condition",

# This is similar to the previous which uses `!` but instead there
# is a wrapper function that will modify the string to have any
# required token for future parsing of the `selects.*` macros.
selects.not(":some_other_other_negative_condition"),
): [
"some_src.cc",
],
"//conditions:default": [],
})
```

To my knowledge the only way to do negative conditionals is the following which does seem to complicate potential solutions.
```python
select({
":some_condition": [],
"//conditions:default": [
"src_included_when_some_condition_is_false.cc",
],
})
```

Perhaps in the coming days come up with a nicer proposal but I also know the owners of this project are incredibly talented people and may also already have brilliant insights on various implementations or potential issues.

Looking forward to responses 😄

Contributor guide

Open the contributing guide

Research direction

Start with docs/selects_doc.md and the existing selects.with_or and selects macros, then read the 22-comment discussion for constraints and proposed directions. Done would require an agreed syntax and semantics for negative conditions, along with a concrete implementation scope accepted by the project owners.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.