Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions docs/common_settings_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ https://bazel.build/extending/config#user-defined-build-settings
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

bool_flag(<a href="#bool_flag-name">name</a>, <a href="#bool_flag-scope">scope</a>)
bool_flag(<a href="#bool_flag-name">name</a>, <a href="#bool_flag-on_leave_scope">on_leave_scope</a>, <a href="#bool_flag-scope">scope</a>)
</pre>

A bool-typed build setting that can be set on the command line
Expand All @@ -26,6 +26,7 @@ A bool-typed build setting that can be set on the command line
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="bool_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="bool_flag-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | Boolean | optional | `False` |
| <a id="bool_flag-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |


Expand All @@ -36,7 +37,7 @@ A bool-typed build setting that can be set on the command line
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")

bool_setting(<a href="#bool_setting-name">name</a>, <a href="#bool_setting-scope">scope</a>)
bool_setting(<a href="#bool_setting-name">name</a>, <a href="#bool_setting-on_leave_scope">on_leave_scope</a>, <a href="#bool_setting-scope">scope</a>)
</pre>

A bool-typed build setting that cannot be set on the command line
Expand All @@ -47,6 +48,7 @@ A bool-typed build setting that cannot be set on the command line
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="bool_setting-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="bool_setting-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | Boolean | optional | `False` |
| <a id="bool_setting-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |


Expand All @@ -57,7 +59,7 @@ A bool-typed build setting that cannot be set on the command line
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "int_flag")

int_flag(<a href="#int_flag-name">name</a>, <a href="#int_flag-make_variable">make_variable</a>, <a href="#int_flag-scope">scope</a>)
int_flag(<a href="#int_flag-name">name</a>, <a href="#int_flag-make_variable">make_variable</a>, <a href="#int_flag-on_leave_scope">on_leave_scope</a>, <a href="#int_flag-scope">scope</a>)
</pre>

An int-typed build setting that can be set on the command line
Expand All @@ -69,6 +71,7 @@ An int-typed build setting that can be set on the command line
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="int_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="int_flag-make_variable"></a>make_variable | If set, the build setting's value will be available as a Make variable with this name in the attributes of rules that list this build setting in their 'toolchains' attribute. | String | optional | `""` |
| <a id="int_flag-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | Integer | optional | `0` |
| <a id="int_flag-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |


Expand All @@ -79,7 +82,7 @@ An int-typed build setting that can be set on the command line
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "int_setting")

int_setting(<a href="#int_setting-name">name</a>, <a href="#int_setting-make_variable">make_variable</a>, <a href="#int_setting-scope">scope</a>)
int_setting(<a href="#int_setting-name">name</a>, <a href="#int_setting-make_variable">make_variable</a>, <a href="#int_setting-on_leave_scope">on_leave_scope</a>, <a href="#int_setting-scope">scope</a>)
</pre>

An int-typed build setting that cannot be set on the command line
Expand All @@ -91,6 +94,7 @@ An int-typed build setting that cannot be set on the command line
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="int_setting-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="int_setting-make_variable"></a>make_variable | If set, the build setting's value will be available as a Make variable with this name in the attributes of rules that list this build setting in their 'toolchains' attribute. | String | optional | `""` |
| <a id="int_setting-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | Integer | optional | `0` |
| <a id="int_setting-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |


Expand All @@ -101,7 +105,7 @@ An int-typed build setting that cannot be set on the command line
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "repeatable_string_flag")

repeatable_string_flag(<a href="#repeatable_string_flag-name">name</a>, <a href="#repeatable_string_flag-scope">scope</a>)
repeatable_string_flag(<a href="#repeatable_string_flag-name">name</a>, <a href="#repeatable_string_flag-on_leave_scope">on_leave_scope</a>, <a href="#repeatable_string_flag-scope">scope</a>)
</pre>

A build setting that accepts one or more string-typed settings on the command line, with the values concatenated into a single string list; for example, `--//my/setting=foo` `--//my/setting=bar` will be parsed as `['foo', 'bar']`. Contrast with `string_list_flag`
Expand All @@ -112,6 +116,7 @@ A build setting that accepts one or more string-typed settings on the command li
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="repeatable_string_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="repeatable_string_flag-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | List of strings | optional | `[]` |
| <a id="repeatable_string_flag-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |


Expand All @@ -122,7 +127,7 @@ A build setting that accepts one or more string-typed settings on the command li
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

string_flag(<a href="#string_flag-name">name</a>, <a href="#string_flag-make_variable">make_variable</a>, <a href="#string_flag-scope">scope</a>, <a href="#string_flag-values">values</a>)
string_flag(<a href="#string_flag-name">name</a>, <a href="#string_flag-make_variable">make_variable</a>, <a href="#string_flag-on_leave_scope">on_leave_scope</a>, <a href="#string_flag-scope">scope</a>, <a href="#string_flag-values">values</a>)
</pre>

A string-typed build setting that can be set on the command line
Expand All @@ -134,6 +139,7 @@ A string-typed build setting that can be set on the command line
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="string_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="string_flag-make_variable"></a>make_variable | If set, the build setting's value will be available as a Make variable with this name in the attributes of rules that list this build setting in their 'toolchains' attribute. | String | optional | `""` |
| <a id="string_flag-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | String | optional | `""` |
| <a id="string_flag-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |
| <a id="string_flag-values"></a>values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | `[]` |

Expand All @@ -145,7 +151,7 @@ A string-typed build setting that can be set on the command line
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "string_list_flag")

string_list_flag(<a href="#string_list_flag-name">name</a>, <a href="#string_list_flag-scope">scope</a>)
string_list_flag(<a href="#string_list_flag-name">name</a>, <a href="#string_list_flag-on_leave_scope">on_leave_scope</a>, <a href="#string_list_flag-scope">scope</a>)
</pre>

A string list-typed build setting that can be set on the command line
Expand All @@ -156,6 +162,7 @@ A string list-typed build setting that can be set on the command line
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="string_list_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="string_list_flag-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | List of strings | optional | `[]` |
| <a id="string_list_flag-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |


Expand All @@ -166,7 +173,7 @@ A string list-typed build setting that can be set on the command line
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "string_list_setting")

string_list_setting(<a href="#string_list_setting-name">name</a>, <a href="#string_list_setting-scope">scope</a>)
string_list_setting(<a href="#string_list_setting-name">name</a>, <a href="#string_list_setting-on_leave_scope">on_leave_scope</a>, <a href="#string_list_setting-scope">scope</a>)
</pre>

A string list-typed build setting which expects its value on the command line to be given in comma-separated format; for example, `--//my/setting=foo,bar` will be parsed as `['foo', 'bar']`. Contrast with `repeatable_string_flag`
Expand All @@ -177,6 +184,7 @@ A string list-typed build setting which expects its value on the command line to
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="string_list_setting-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="string_list_setting-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | List of strings | optional | `[]` |
| <a id="string_list_setting-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |


Expand All @@ -187,7 +195,7 @@ A string list-typed build setting which expects its value on the command line to
<pre>
load("@bazel_skylib//rules:common_settings.bzl", "string_setting")

string_setting(<a href="#string_setting-name">name</a>, <a href="#string_setting-make_variable">make_variable</a>, <a href="#string_setting-scope">scope</a>, <a href="#string_setting-values">values</a>)
string_setting(<a href="#string_setting-name">name</a>, <a href="#string_setting-make_variable">make_variable</a>, <a href="#string_setting-on_leave_scope">on_leave_scope</a>, <a href="#string_setting-scope">scope</a>, <a href="#string_setting-values">values</a>)
</pre>

A string-typed build setting that cannot be set on the command line
Expand All @@ -199,6 +207,7 @@ A string-typed build setting that cannot be set on the command line
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="string_setting-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="string_setting-make_variable"></a>make_variable | If set, the build setting's value will be available as a Make variable with this name in the attributes of rules that list this build setting in their 'toolchains' attribute. | String | optional | `""` |
| <a id="string_setting-on_leave_scope"></a>on_leave_scope | the value of the flag once it leaves the specified scope. | String | optional | `""` |
| <a id="string_setting-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |
| <a id="string_setting-values"></a>values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | `[]` |

Expand Down
27 changes: 27 additions & 0 deletions rules/common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ int_flag = rule(
attrs = {
"make_variable": _MAKE_VARIABLE_ATTR,
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.int(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "An int-typed build setting that can be set on the command line",
)
Expand All @@ -82,6 +85,9 @@ int_setting = rule(
attrs = {
"make_variable": _MAKE_VARIABLE_ATTR,
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.int(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "An int-typed build setting that cannot be set on the command line",
)
Expand All @@ -91,6 +97,9 @@ bool_flag = rule(
build_setting = config.bool(flag = True),
attrs = {
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.bool(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "A bool-typed build setting that can be set on the command line",
)
Expand All @@ -100,6 +109,9 @@ bool_setting = rule(
build_setting = config.bool(),
attrs = {
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.bool(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "A bool-typed build setting that cannot be set on the command line",
)
Expand All @@ -109,6 +121,9 @@ string_list_flag = rule(
build_setting = config.string_list(flag = True),
attrs = {
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.string_list(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "A string list-typed build setting that can be set on the command line",
)
Expand All @@ -124,6 +139,9 @@ repeatable_string_flag = rule(
),
attrs = {
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.string_list(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "A build setting that accepts one or more string-typed settings on the command line, with the values concatenated into a single string list; for example, `--//my/setting=foo` `--//my/setting=bar` will be parsed as `['foo', 'bar']`. Contrast with `string_list_flag`",
)
Expand All @@ -133,6 +151,9 @@ string_list_setting = rule(
build_setting = config.string_list(),
attrs = {
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.string_list(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "A string list-typed build setting which expects its value on the command line to be given in comma-separated format; for example, `--//my/setting=foo,bar` will be parsed as `['foo', 'bar']`. Contrast with `repeatable_string_flag`",
)
Expand Down Expand Up @@ -163,6 +184,9 @@ string_flag = rule(
),
"make_variable": _MAKE_VARIABLE_ATTR,
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.string(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "A string-typed build setting that can be set on the command line",
)
Expand All @@ -176,6 +200,9 @@ string_setting = rule(
),
"make_variable": _MAKE_VARIABLE_ATTR,
"scope": _SCOPE_ATTR,
"on_leave_scope": attr.string(
doc = "the value of the flag once it leaves the specified scope.",
),
},
doc = "A string-typed build setting that cannot be set on the command line",
)