Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): add and use permissive wrapper for select.with_or (#5587)
* feat(build): add and use permissive wrapper for select.with_or * chore: fix typo
- Loading branch information
Showing
4 changed files
with
72 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@bazel_skylib//lib:selects.bzl", "selects") | ||
|
||
def with_or(mapping, no_match_error = ""): | ||
"""Like selects.with_or, but allows duplicate conditions in the key tuples.""" | ||
return select(with_or_dict(mapping), no_match_error = no_match_error) | ||
|
||
def with_or_dict(mapping): | ||
"""Like selects.with_or_dict, but allows duplicate condtions in tuples.""" | ||
output_dict = {} | ||
for key, value in mapping.items(): | ||
if type(key) == type(()): | ||
# Keep only unique values from the tuple. | ||
key = tuple({k: None for k in key if k}) | ||
|
||
# Omit empty-keyed values. | ||
if key: | ||
output_dict[key] = value | ||
|
||
return selects.with_or_dict(output_dict) |