xref: /aosp_15_r20/external/bazel-skylib/docs/selects_doc.md (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2
3Skylib module containing convenience interfaces for select().
4
5<a id="selects.config_setting_group"></a>
6
7## selects.config_setting_group
8
9<pre>
10selects.config_setting_group(<a href="#selects.config_setting_group-name">name</a>, <a href="#selects.config_setting_group-match_any">match_any</a>, <a href="#selects.config_setting_group-match_all">match_all</a>, <a href="#selects.config_setting_group-visibility">visibility</a>)
11</pre>
12
13Matches if all or any of its member `config_setting`s match.
14
15Example:
16
17  ```build
18  config_setting(name = "one", define_values = {"foo": "true"})
19  config_setting(name = "two", define_values = {"bar": "false"})
20  config_setting(name = "three", define_values = {"baz": "more_false"})
21
22  config_setting_group(
23      name = "one_two_three",
24      match_all = [":one", ":two", ":three"]
25  )
26
27  cc_binary(
28      name = "myapp",
29      srcs = ["myapp.cc"],
30      deps = select({
31          ":one_two_three": [":special_deps"],
32          "//conditions:default": [":default_deps"]
33      })
34  ```
35
36
37**PARAMETERS**
38
39
40| Name  | Description | Default Value |
41| :------------- | :------------- | :------------- |
42| <a id="selects.config_setting_group-name"></a>name |  The group's name. This is how `select()`s reference it.   |  none |
43| <a id="selects.config_setting_group-match_any"></a>match_any |  A list of `config_settings`. This group matches if *any* member in the list matches. If this is set, `match_all` must not be set.   |  `[]` |
44| <a id="selects.config_setting_group-match_all"></a>match_all |  A list of `config_settings`. This group matches if *every* member in the list matches. If this is set, `match_any` must be not set.   |  `[]` |
45| <a id="selects.config_setting_group-visibility"></a>visibility |  Visibility of the config_setting_group.   |  `None` |
46
47
48<a id="selects.with_or"></a>
49
50## selects.with_or
51
52<pre>
53selects.with_or(<a href="#selects.with_or-input_dict">input_dict</a>, <a href="#selects.with_or-no_match_error">no_match_error</a>)
54</pre>
55
56Drop-in replacement for `select()` that supports ORed keys.
57
58Example:
59
60      ```build
61      deps = selects.with_or({
62          "//configs:one": [":dep1"],
63          ("//configs:two", "//configs:three"): [":dep2or3"],
64          "//configs:four": [":dep4"],
65          "//conditions:default": [":default"]
66      })
67      ```
68
69      Key labels may appear at most once anywhere in the input.
70
71
72**PARAMETERS**
73
74
75| Name  | Description | Default Value |
76| :------------- | :------------- | :------------- |
77| <a id="selects.with_or-input_dict"></a>input_dict |  The same dictionary `select()` takes, except keys may take either the usual form `"//foo:config1"` or `("//foo:config1", "//foo:config2", ...)` to signify `//foo:config1` OR `//foo:config2` OR `...`.   |  none |
78| <a id="selects.with_or-no_match_error"></a>no_match_error |  Optional custom error to report if no condition matches.   |  `""` |
79
80**RETURNS**
81
82A native `select()` that expands
83
84`("//configs:two", "//configs:three"): [":dep2or3"]`
85
86to
87
88```build
89"//configs:two": [":dep2or3"],
90"//configs:three": [":dep2or3"],
91```
92
93
94<a id="selects.with_or_dict"></a>
95
96## selects.with_or_dict
97
98<pre>
99selects.with_or_dict(<a href="#selects.with_or_dict-input_dict">input_dict</a>)
100</pre>
101
102Variation of `with_or` that returns the dict of the `select()`.
103
104Unlike `select()`, the contents of the dict can be inspected by Starlark
105macros.
106
107
108**PARAMETERS**
109
110
111| Name  | Description | Default Value |
112| :------------- | :------------- | :------------- |
113| <a id="selects.with_or_dict-input_dict"></a>input_dict |  Same as `with_or`.   |  none |
114
115**RETURNS**
116
117A dictionary usable by a native `select()`.
118
119
120