• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# select_multi works around a restriction in native select() that prevents multiple
2# keys from being matched unless one is a strict subset of another. For some features,
3# we allow multiple of that component to be active. For example, with codecs, we let
4# the clients mix and match anywhere from 0 built in codecs to all of them.
5#
6# select_multi takes a given map and turns it into several distinct select statements
7# that have the effect of using any values associated with any active keys.
8# For example, if the following parameters are passed in:
9#    values_map = {
10#        ":alpha": ["apple", "apricot"],
11#        ":beta": ["banana"],
12#        ":gamma": ["grapefruit"],
13#    },
14#    default = []
15# it will be unrolled into the following select statements
16#    [] + select({
17#        ":apple": ["apple", "apricot"],
18#        "//conditions:default": [],
19#    }) + select({
20#        ":beta": ["banana"],
21#        "//conditions:default": [],
22#    }) + select({
23#        ":gamma": ["grapefruit"],
24#        "//conditions:default": [],
25#    })
26def select_multi(values_map, default):
27    if len(values_map) == 0:
28        return default
29    rv = []
30    for key, value in values_map.items():
31        rv += select({
32            key: value,
33            "//conditions:default": default,
34        })
35    return rv
36