From 5d2041a9a72e52f6e4b8ea83b00d72c1bfb78688 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 28 Jan 2018 13:16:34 +0100 Subject: Add more choice type and prompt sanity checks - Choices should have type bool or tristate - Choice values should have a prompt Also fix indentation mess-up. --- kconfiglib.py | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index 297e39b..f38ddca 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4191,28 +4191,38 @@ def _check_sym_sanity(sym): .format(_name_and_loc_str(sym))) def _check_choice_sanity(choice): - if choice.orig_type == UNKNOWN: - choice.kconfig._warn("{} defined without a type" - .format(_name_and_loc_str(choice))) - - for node in choice.nodes: - if node.prompt: - break - else: - choice.kconfig._warn("{} defined without a prompt" - .format(_name_and_loc_str(choice))) - - for default, _ in choice.defaults: - if not isinstance(default, Symbol): - raise KconfigSyntaxError( - "{} has a malformed default {}" - .format(_name_and_loc_str(choice), expr_str(default))) - - if default.choice is not choice: - choice.kconfig._warn("the default selection {} of {} is not " - "contained in the choice" - .format(_name_and_loc_str(default), - _name_and_loc_str(choice))) + if choice.orig_type not in (BOOL, TRISTATE): + choice.kconfig._warn("{} defined with type {}" + .format(_name_and_loc_str(choice), + TYPE_TO_STR[choice.orig_type])) + + for node in choice.nodes: + if node.prompt: + break + else: + choice.kconfig._warn("{} defined without a prompt" + .format(_name_and_loc_str(choice))) + + for default, _ in choice.defaults: + if not isinstance(default, Symbol): + raise KconfigSyntaxError( + "{} has a malformed default {}" + .format(_name_and_loc_str(choice), expr_str(default))) + + if default.choice is not choice: + choice.kconfig._warn("the default selection {} of {} is not " + "contained in the choice" + .format(_name_and_loc_str(default), + _name_and_loc_str(choice))) + + for sym in choice.syms: + for node in sym.nodes: + if node.prompt: + break + else: + choice.kconfig._warn("the choice symbol {} has no prompt" + .format(_name_and_loc_str(sym))) + # # Public global constants -- cgit v1.2.3