From 5f3d307155f4db035b652738e9fc49ad8be0c792 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 25 Sep 2017 20:24:11 +0200 Subject: Fix 'default' on non-visible choice symbols Previously, 'default CHOICE_SYM [if ]' in a choice would skip any following 'default' properties if 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. --- kconfiglib.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'kconfiglib.py') 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 ]' 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): -- cgit v1.2.3