summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2017-09-25 20:24:11 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2017-09-25 20:42:44 +0200
commit5f3d307155f4db035b652738e9fc49ad8be0c792 (patch)
tree3c5d4d3322a7d8bf0e2c5a7f9f7f0243b8860cfb
parent58e05c00ab0a762866e3719974d5b74096df233c (diff)
Fix 'default' on non-visible choice symbols
Previously, 'default CHOICE_SYM [if <cond>]' in a choice would skip any following 'default' properties if <cond> was non-'n'. However, those other defaults should still be considered if CHOICE_SYM has visibility 'n'. Previously, we'd immediately fall back to selecting the first visible symbol in the choice in that case. get_selection_from_defaults() now exactly mirrors sym_choice_default() from the C implementation, and got less convoluted too. Nothing in the kernel defconfigs triggered this. Add a new test case too.
-rw-r--r--kconfiglib.py20
-rw-r--r--tests/Kchoice20
-rw-r--r--testsuite.py13
3 files changed, 38 insertions, 15 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 0cab18f..0865176 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -2872,23 +2872,19 @@ class Choice(Item):
"""Like Choice.get_selection(), but acts as if no symbol has been
selected by the user and no 'optional' flag is in effect."""
- if not self._actual_symbols:
- return None
-
- for symbol, cond_expr in self._def_exprs:
- if self._config._eval_expr(cond_expr) != "n":
- chosen_symbol = symbol
- break
- else:
- chosen_symbol = self._actual_symbols[0]
+ # Does any 'default SYM [if <cond>]' property apply?
+ for sym, cond_expr in self._def_exprs:
+ if (self._config._eval_expr(cond_expr) != "n" and
+ # Must be visible too
+ _get_visibility(sym) != "n"):
+ return sym
- # Is the chosen symbol visible?
- if _get_visibility(chosen_symbol) != "n":
- return chosen_symbol
# Otherwise, pick the first visible symbol
for sym in self._actual_symbols:
if _get_visibility(sym) != "n":
return sym
+
+ # Couldn't find a default
return None
def get_user_selection(self):
diff --git a/tests/Kchoice b/tests/Kchoice
index 1e841ca..e80e222 100644
--- a/tests/Kchoice
+++ b/tests/Kchoice
@@ -75,6 +75,26 @@ config OPT_4
tristate "OPT_4"
endchoice
+choice DEFAULTS_NOT_VISIBLE
+ bool "defaults not visible"
+ # Skipped due to condition
+ default OPT_6 if n
+ # Skipped because OPT_7 is not visible
+ default OPT_7
+ # This one should apply
+ default OPT_8
+config OPT_5
+ tristate "OPT_5"
+config OPT_6
+ tristate "OPT_6"
+config OPT_7
+ tristate "OPT_7" if n
+config OPT_8
+ tristate "OPT_8"
+config OPT_9
+ tristate "OPT_9"
+endchoice
+
# Choices without an explicitly specified type should get the type of the first
# symbol with a type
diff --git a/testsuite.py b/testsuite.py
index 9d364c8..870195f 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -1825,9 +1825,9 @@ def run_selftests():
choice_bool, choice_bool_opt, choice_tristate, choice_tristate_opt, \
choice_bool_m, choice_tristate_m, choice_defaults, \
- choice_no_type_bool, choice_no_type_tristate, \
- choice_missing_member_type_1, choice_missing_member_type_2, \
- choice_weird_syms = c.get_choices()
+ choice_defaults_not_visible, choice_no_type_bool, \
+ choice_no_type_tristate, choice_missing_member_type_1, \
+ choice_missing_member_type_2, choice_weird_syms = c.get_choices()
for choice in (choice_bool, choice_bool_opt, choice_bool_m,
choice_defaults):
@@ -1901,6 +1901,13 @@ def run_selftests():
verify(choice_defaults.get_selection() is c["OPT_1"],
"User selection should override defaults")
+ verify(choice_defaults_not_visible.get_selection_from_defaults()
+ is c["OPT_8"] and
+ choice_defaults_not_visible.get_selection()
+ is c["OPT_8"],
+ "Non-visible choice symbols should cause the next default to be "
+ "considered")
+
# Test "y" mode selection
c["MODULES"].set_user_value("y")