Skip to content

Commit fe2ebad

Browse files
committed
Add a repeatable string list flag rule to skylib
1 parent 505e1bc commit fe2ebad

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

rules/common_settings.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ string_list_flag = rule(
123123
doc = "A string list-typed build setting that can be set on the command line",
124124
)
125125

126+
string_list_repeatable_flag = rule(
127+
implementation = _impl,
128+
build_setting = config.string_list(flag = True, repeatable = True),
129+
doc = "A string list-typed build setting that can be accumulated on the command line",
130+
)
131+
126132
string_list_setting = rule(
127133
implementation = _impl,
128134
build_setting = config.string_list(),

tests/common_settings_test.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def _volcano_impl(ctx):
6666
height = ctx.attr.height[BuildSettingInfo].value,
6767
active = ctx.attr.active[BuildSettingInfo].value,
6868
namer = ctx.attr.namer[BuildSettingInfo].value,
69-
nicknames = ctx.attr.nicknames[BuildSettingInfo].value
69+
nicknames = ctx.attr.nicknames[BuildSettingInfo].value,
70+
hazards = ctx.attr.hazards[BuildSettingInfo].value
7071
)
7172
print(description)
7273
@@ -77,6 +78,7 @@ volcano = rule(
7778
"active" : attr.label(),
7879
"namer": attr.label(),
7980
"nicknames": attr.label(),
81+
"hazards": attr.label(),
8082
}
8183
)
8284
EOF
@@ -89,6 +91,7 @@ load(
8991
"bool_flag",
9092
"string_flag",
9193
"string_list_flag",
94+
"string_list_repeatable_flag",
9295
)
9396
load("//volcano:rules.bzl", "volcano")
9497
@@ -113,6 +116,11 @@ string_list_flag(
113116
build_setting_default = ["loowit", "loowitiatkla", "lavelatla"]
114117
)
115118
119+
string_list_repeatable_flag(
120+
name = "hazards-flag",
121+
build_setting_default = ["lava", "pyroclastic-flow", "ash"]
122+
)
123+
116124
int_setting(
117125
name = "height-setting",
118126
build_setting_default = 9677
@@ -124,6 +132,7 @@ volcano(
124132
active = ":active-flag",
125133
namer = ":namer-flag",
126134
nicknames = ":nicknames-flag",
135+
hazards = ":hazards-flag",
127136
)
128137
EOF
129138

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

141152
expect_log "active = False"
142153
expect_log "height = 8366"
143154
expect_log "namer = \"puyallup-tribe\""
144155
expect_log "nicknames = \[\"volcano-mc-volcanoface\"\]"
156+
expect_log "hazards = \[\"lava\"\, \"hydrogen-sulfide\"]"
145157
}
146158

147159
function test_cannot_set_settings() {

0 commit comments

Comments
 (0)