Add a repeatable string list flag rule to skylib
This commit is contained in:
parent
505e1bc3aa
commit
74a0a527b4
|
@ -126,6 +126,24 @@ A string list-typed build setting that can be set on the command line
|
||||||
| <a id="string_list_flag-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |
|
| <a id="string_list_flag-scope"></a>scope | The scope indicates where a flag can propagate to | String | optional | `"universal"` |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="#string_list_repeatable_flag"></a>
|
||||||
|
|
||||||
|
## string_list_repeatable_flag
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
string_list_repeatable_flag(<a href="#string_list_repeatable_flag-name">name</a>)
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
A string list-typed build setting that can be accumulated on the command line
|
||||||
|
|
||||||
|
**ATTRIBUTES**
|
||||||
|
|
||||||
|
|
||||||
|
| Name | Description | Type | Mandatory | Default |
|
||||||
|
| :------------- | :------------- | :------------- | :------------- | :------------- |
|
||||||
|
| <a id="string_list_repeatable_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
|
||||||
|
|
||||||
|
|
||||||
<a id="string_list_setting"></a>
|
<a id="string_list_setting"></a>
|
||||||
|
|
||||||
## string_list_setting
|
## string_list_setting
|
||||||
|
|
|
@ -123,6 +123,12 @@ string_list_flag = rule(
|
||||||
doc = "A string list-typed build setting that can be set on the command line",
|
doc = "A string list-typed build setting that can be set on the command line",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
string_list_repeatable_flag = rule(
|
||||||
|
implementation = _impl,
|
||||||
|
build_setting = config.string_list(flag = True, repeatable = True),
|
||||||
|
doc = "A string list-typed build setting that can be accumulated on the command line",
|
||||||
|
)
|
||||||
|
|
||||||
string_list_setting = rule(
|
string_list_setting = rule(
|
||||||
implementation = _impl,
|
implementation = _impl,
|
||||||
build_setting = config.string_list(),
|
build_setting = config.string_list(),
|
||||||
|
|
|
@ -66,7 +66,8 @@ def _volcano_impl(ctx):
|
||||||
height = ctx.attr.height[BuildSettingInfo].value,
|
height = ctx.attr.height[BuildSettingInfo].value,
|
||||||
active = ctx.attr.active[BuildSettingInfo].value,
|
active = ctx.attr.active[BuildSettingInfo].value,
|
||||||
namer = ctx.attr.namer[BuildSettingInfo].value,
|
namer = ctx.attr.namer[BuildSettingInfo].value,
|
||||||
nicknames = ctx.attr.nicknames[BuildSettingInfo].value
|
nicknames = ctx.attr.nicknames[BuildSettingInfo].value,
|
||||||
|
hazards = ctx.attr.hazards[BuildSettingInfo].value
|
||||||
)
|
)
|
||||||
print(description)
|
print(description)
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ volcano = rule(
|
||||||
"active" : attr.label(),
|
"active" : attr.label(),
|
||||||
"namer": attr.label(),
|
"namer": attr.label(),
|
||||||
"nicknames": attr.label(),
|
"nicknames": attr.label(),
|
||||||
|
"hazards": attr.label(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
EOF
|
EOF
|
||||||
|
@ -89,6 +91,7 @@ load(
|
||||||
"bool_flag",
|
"bool_flag",
|
||||||
"string_flag",
|
"string_flag",
|
||||||
"string_list_flag",
|
"string_list_flag",
|
||||||
|
"string_list_repeatable_flag",
|
||||||
)
|
)
|
||||||
load("//volcano:rules.bzl", "volcano")
|
load("//volcano:rules.bzl", "volcano")
|
||||||
|
|
||||||
|
@ -113,6 +116,11 @@ string_list_flag(
|
||||||
build_setting_default = ["loowit", "loowitiatkla", "lavelatla"]
|
build_setting_default = ["loowit", "loowitiatkla", "lavelatla"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
string_list_repeatable_flag(
|
||||||
|
name = "hazards-flag",
|
||||||
|
build_setting_default = ["lava", "pyroclastic-flow", "ash"]
|
||||||
|
)
|
||||||
|
|
||||||
int_setting(
|
int_setting(
|
||||||
name = "height-setting",
|
name = "height-setting",
|
||||||
build_setting_default = 9677
|
build_setting_default = 9677
|
||||||
|
@ -124,6 +132,7 @@ volcano(
|
||||||
active = ":active-flag",
|
active = ":active-flag",
|
||||||
namer = ":namer-flag",
|
namer = ":namer-flag",
|
||||||
nicknames = ":nicknames-flag",
|
nicknames = ":nicknames-flag",
|
||||||
|
hazards = ":hazards-flag",
|
||||||
)
|
)
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -136,12 +145,15 @@ function test_can_set_flags() {
|
||||||
bazel build volcano:mt-st-helens --//volcano:height-flag=8366 \
|
bazel build volcano:mt-st-helens --//volcano:height-flag=8366 \
|
||||||
--//volcano:active-flag=False --//volcano:namer-flag=puyallup-tribe \
|
--//volcano:active-flag=False --//volcano:namer-flag=puyallup-tribe \
|
||||||
--//volcano:nicknames-flag=volcano-mc-volcanoface \
|
--//volcano:nicknames-flag=volcano-mc-volcanoface \
|
||||||
|
--//volcano:hazards-flag=lava \
|
||||||
|
--//volcano:hazards-flag=hydrogen-sulfide \
|
||||||
>"$TEST_log" 2>&1 || fail "Expected test to pass"
|
>"$TEST_log" 2>&1 || fail "Expected test to pass"
|
||||||
|
|
||||||
expect_log "active = False"
|
expect_log "active = False"
|
||||||
expect_log "height = 8366"
|
expect_log "height = 8366"
|
||||||
expect_log "namer = \"puyallup-tribe\""
|
expect_log "namer = \"puyallup-tribe\""
|
||||||
expect_log "nicknames = \[\"volcano-mc-volcanoface\"\]"
|
expect_log "nicknames = \[\"volcano-mc-volcanoface\"\]"
|
||||||
|
expect_log "hazards = \[\"lava\"\, \"hydrogen-sulfide\"]"
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_cannot_set_settings() {
|
function test_cannot_set_settings() {
|
||||||
|
|
Loading…
Reference in New Issue