Expand docs a bit
This commit is contained in:
parent
e202c2b484
commit
4b34b67ccd
|
@ -2,6 +2,15 @@
|
|||
|
||||
Skylib module of convenience functions for `target_compatible_with`.
|
||||
|
||||
Load the macros as follows in your `BUILD` files:
|
||||
```build
|
||||
load("@bazel_skylib//lib:compatibility.bzl", "compatibility")
|
||||
```
|
||||
|
||||
See the [Platform docs](https://bazel.build/docs/platforms#skipping-incompatible-targets) for
|
||||
more information.
|
||||
|
||||
|
||||
<a id="#compatibility.all_of"></a>
|
||||
|
||||
## compatibility.all_of
|
||||
|
@ -10,11 +19,33 @@ Skylib module of convenience functions for `target_compatible_with`.
|
|||
compatibility.all_of(<a href="#compatibility.all_of-settings">settings</a>)
|
||||
</pre>
|
||||
|
||||
Create a `select()` which matches all of the given config_settings.
|
||||
Create a `select()` for `target_compatible_with` which matches all of the given settings.
|
||||
|
||||
All of the settings must be true to get an empty list. Failure to match will result
|
||||
in an incompatible constraint_value for the purpose of target skipping.
|
||||
|
||||
In other words, use this function to make a target incompatible unless all of the settings are
|
||||
true.
|
||||
|
||||
Example:
|
||||
|
||||
```build
|
||||
config_setting(
|
||||
name = "dbg",
|
||||
values = {"compilation_mode": "dbg"},
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "bin",
|
||||
srcs = ["bin.cc"],
|
||||
# This target can only be built for Linux in debug mode.
|
||||
target_compatible_with = compatibility.all_of([
|
||||
":dbg",
|
||||
"@platforms//os:linux",
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
See also: `selects.config_setting_group(match_all)`
|
||||
|
||||
|
||||
|
@ -23,11 +54,11 @@ See also: `selects.config_setting_group(match_all)`
|
|||
|
||||
| Name | Description | Default Value |
|
||||
| :------------- | :------------- | :------------- |
|
||||
| <a id="compatibility.all_of-settings"></a>settings | A list of <code>config_settings</code>. | none |
|
||||
| <a id="compatibility.all_of-settings"></a>settings | A list of <code>config_setting</code> or <code>constraint_value</code> targets. | none |
|
||||
|
||||
**RETURNS**
|
||||
|
||||
A native `select()` which is "incompatible" unless all `config_settings` are true.
|
||||
A native `select()` which is "incompatible" unless all settings are true.
|
||||
|
||||
|
||||
<a id="#compatibility.any_of"></a>
|
||||
|
@ -38,18 +69,33 @@ A native `select()` which is "incompatible" unless all `config_settings` are tru
|
|||
compatibility.any_of(<a href="#compatibility.any_of-settings">settings</a>)
|
||||
</pre>
|
||||
|
||||
Create a `select()` which matches any of the given config_settings.
|
||||
Create a `select()` for `target_compatible_with` which matches any of the given settings.
|
||||
|
||||
Any of the settings will resolve to an empty list, while the default condition will map to
|
||||
an incompatible constraint_value for the purpose of target skipping.
|
||||
|
||||
In other words, use this function to make target incompatible unless one or more of the
|
||||
settings are true.
|
||||
|
||||
```build
|
||||
cc_binary(
|
||||
name = "bin",
|
||||
srcs = ["bin.cc"],
|
||||
# This target can only be built for Linux or Mac.
|
||||
target_compatible_with = compatibility.any_of([
|
||||
"@platforms//os:linux",
|
||||
"@platforms//os:macos",
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
**PARAMETERS**
|
||||
|
||||
|
||||
| Name | Description | Default Value |
|
||||
| :------------- | :------------- | :------------- |
|
||||
| <a id="compatibility.any_of-settings"></a>settings | A list of <code>config_settings</code>. | none |
|
||||
| <a id="compatibility.any_of-settings"></a>settings | A list of <code>config_settings</code> or <code>constraint_value</code> targets. | none |
|
||||
|
||||
**RETURNS**
|
||||
|
||||
|
@ -64,18 +110,33 @@ A native `select()` which maps any of the settings an empty list.
|
|||
compatibility.none_of(<a href="#compatibility.none_of-settings">settings</a>)
|
||||
</pre>
|
||||
|
||||
Create a `select()` which matches none of the given config_settings.
|
||||
Create a `select()` for `target_compatible_with` which matches none of the given settings.
|
||||
|
||||
Any of the settings will resolve to an incompatible constraint_value for the
|
||||
purpose of target skipping.
|
||||
|
||||
In other words, use this function to make target incompatible if any of the settings are true.
|
||||
|
||||
```build
|
||||
cc_binary(
|
||||
name = "bin",
|
||||
srcs = ["bin.cc"],
|
||||
# This target cannot be built for Linux or Mac, but can be built for
|
||||
# everything else.
|
||||
target_compatible_with = compatibility.none_of([
|
||||
"@platforms//os:linux",
|
||||
"@platforms//os:macos",
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
**PARAMETERS**
|
||||
|
||||
|
||||
| Name | Description | Default Value |
|
||||
| :------------- | :------------- | :------------- |
|
||||
| <a id="compatibility.none_of-settings"></a>settings | A list of <code>config_settings</code>. | none |
|
||||
| <a id="compatibility.none_of-settings"></a>settings | A list of <code>config_setting</code> or <code>constraint_value</code> targets. | none |
|
||||
|
||||
**RETURNS**
|
||||
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
"""Skylib module of convenience functions for `target_compatible_with`."""
|
||||
"""Skylib module of convenience functions for `target_compatible_with`.
|
||||
|
||||
Load the macros as follows in your `BUILD` files:
|
||||
```build
|
||||
load("@bazel_skylib//lib:compatibility.bzl", "compatibility")
|
||||
```
|
||||
|
||||
See the [Platform docs](https://bazel.build/docs/platforms#skipping-incompatible-targets) for
|
||||
more information.
|
||||
"""
|
||||
|
||||
load(":selects.bzl", "selects")
|
||||
|
||||
_INCOMPATIBLE_SETTING="@platforms//:incompatible_setting"
|
||||
|
||||
def _get_name_from_target_list(targets, joiner=" or "):
|
||||
"""Join a list of strings into a string which is suitable as a target name.
|
||||
|
||||
|
@ -36,13 +43,28 @@ def _maybe_make_unique_incompatible_value(name):
|
|||
)
|
||||
|
||||
def _none_of(settings):
|
||||
"""Create a `select()` which matches none of the given settings.
|
||||
"""Create a `select()` for `target_compatible_with` which matches none of the given settings.
|
||||
|
||||
Any of the settings will resolve to an incompatible constraint_value for the
|
||||
purpose of target skipping.
|
||||
|
||||
In other words, use this function to make target incompatible if any of the settings are true.
|
||||
|
||||
```build
|
||||
cc_binary(
|
||||
name = "bin",
|
||||
srcs = ["bin.cc"],
|
||||
# This target cannot be built for Linux or Mac, but can be built for
|
||||
# everything else.
|
||||
target_compatible_with = compatibility.none_of([
|
||||
"@platforms//os:linux",
|
||||
"@platforms//os:macos",
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
Args:
|
||||
settings: A list of `config_settings`.
|
||||
settings: A list of `config_setting` or `constraint_value` targets.
|
||||
|
||||
Returns:
|
||||
A native `select()` which maps any of the settings to the incompatible target.
|
||||
|
@ -56,13 +78,28 @@ def _none_of(settings):
|
|||
})
|
||||
|
||||
def _any_of(settings):
|
||||
"""Create a `select()` which matches any of the given config_settings.
|
||||
"""Create a `select()` for `target_compatible_with` which matches any of the given settings.
|
||||
|
||||
Any of the settings will resolve to an empty list, while the default condition will map to
|
||||
an incompatible constraint_value for the purpose of target skipping.
|
||||
|
||||
In other words, use this function to make target incompatible unless one or more of the
|
||||
settings are true.
|
||||
|
||||
```build
|
||||
cc_binary(
|
||||
name = "bin",
|
||||
srcs = ["bin.cc"],
|
||||
# This target can only be built for Linux or Mac.
|
||||
target_compatible_with = compatibility.any_of([
|
||||
"@platforms//os:linux",
|
||||
"@platforms//os:macos",
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
Args:
|
||||
settings: A list of `config_settings`.
|
||||
settings: A list of `config_settings` or `constraint_value` targets.
|
||||
|
||||
Returns:
|
||||
A native `select()` which maps any of the settings an empty list.
|
||||
|
@ -76,18 +113,40 @@ def _any_of(settings):
|
|||
})
|
||||
|
||||
def _all_of(settings):
|
||||
"""Create a `select()` which matches all of the given config_settings.
|
||||
"""Create a `select()` for `target_compatible_with` which matches all of the given settings.
|
||||
|
||||
All of the settings must be true to get an empty list. Failure to match will result
|
||||
in an incompatible constraint_value for the purpose of target skipping.
|
||||
|
||||
In other words, use this function to make a target incompatible unless all of the settings are
|
||||
true.
|
||||
|
||||
Example:
|
||||
|
||||
```build
|
||||
config_setting(
|
||||
name = "dbg",
|
||||
values = {"compilation_mode": "dbg"},
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "bin",
|
||||
srcs = ["bin.cc"],
|
||||
# This target can only be built for Linux in debug mode.
|
||||
target_compatible_with = compatibility.all_of([
|
||||
":dbg",
|
||||
"@platforms//os:linux",
|
||||
]),
|
||||
)
|
||||
```
|
||||
|
||||
See also: `selects.config_setting_group(match_all)`
|
||||
|
||||
Args:
|
||||
settings: A list of `config_settings`.
|
||||
settings: A list of `config_setting` or `constraint_value` targets.
|
||||
|
||||
Returns:
|
||||
A native `select()` which is "incompatible" unless all `config_settings` are true.
|
||||
A native `select()` which is "incompatible" unless all settings are true.
|
||||
"""
|
||||
group_name = _get_name_from_target_list(settings, joiner=" and ")
|
||||
compat_name = " compatible with all of " + group_name
|
||||
|
|
Loading…
Reference in New Issue