Skip to content
Open
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
18 changes: 18 additions & 0 deletions docs/common_settings_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_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/concepts/labels#target-names">Name</a> | required | |


<a id="string_list_setting"></a>

## string_list_setting
Expand Down
6 changes: 6 additions & 0 deletions rules/common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ string_list_flag = rule(
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(
implementation = _impl,
build_setting = config.string_list(),
Expand Down
14 changes: 13 additions & 1 deletion tests/common_settings_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def _volcano_impl(ctx):
height = ctx.attr.height[BuildSettingInfo].value,
active = ctx.attr.active[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)

Expand All @@ -77,6 +78,7 @@ volcano = rule(
"active" : attr.label(),
"namer": attr.label(),
"nicknames": attr.label(),
"hazards": attr.label(),
}
)
EOF
Expand All @@ -89,6 +91,7 @@ load(
"bool_flag",
"string_flag",
"string_list_flag",
"string_list_repeatable_flag",
)
load("//volcano:rules.bzl", "volcano")

Expand All @@ -113,6 +116,11 @@ string_list_flag(
build_setting_default = ["loowit", "loowitiatkla", "lavelatla"]
)

string_list_repeatable_flag(
name = "hazards-flag",
build_setting_default = ["lava", "pyroclastic-flow", "ash"]
)

int_setting(
name = "height-setting",
build_setting_default = 9677
Expand All @@ -124,6 +132,7 @@ volcano(
active = ":active-flag",
namer = ":namer-flag",
nicknames = ":nicknames-flag",
hazards = ":hazards-flag",
)
EOF

Expand All @@ -136,12 +145,15 @@ function test_can_set_flags() {
bazel build volcano:mt-st-helens --//volcano:height-flag=8366 \
--//volcano:active-flag=False --//volcano:namer-flag=puyallup-tribe \
--//volcano:nicknames-flag=volcano-mc-volcanoface \
--//volcano:hazards-flag=lava \
--//volcano:hazards-flag=hydrogen-sulfide \
>"$TEST_log" 2>&1 || fail "Expected test to pass"

expect_log "active = False"
expect_log "height = 8366"
expect_log "namer = \"puyallup-tribe\""
expect_log "nicknames = \[\"volcano-mc-volcanoface\"\]"
expect_log "hazards = \[\"lava\"\, \"hydrogen-sulfide\"]"
}

function test_cannot_set_settings() {
Expand Down