From a247f3f5815f42e8f1b616e311d38f41587cef64 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 10 Oct 2018 13:45:42 +0200 Subject: menuconfig: Improve/fix promptless choice handling The code assumed that all parent (interface) menus always have a prompt, which is false for items in promptless choices. This lead to a crash e.g. when viewing the symbol information for a symbol within a promptless choice. Promptless choices with children can show up "legitimately" when people define choices in multiple locations to add symbols, though this is broken in the C tools. Use standard_sc_expr_str(node.item) instead of the non-existing prompt for promptless choices. That way they show up as )>, which is consistent with how they're shown elsewhere. This commit also changes how choices names are displayed in show-name/show-all mode, to the standard_sc_expr_str() format. --- menuconfig.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'menuconfig.py') diff --git a/menuconfig.py b/menuconfig.py index 14edb83..d5cac8f 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -1190,7 +1190,11 @@ def _draw_main(): menu = _cur_menu while menu is not _kconf.top_node: - menu_prompts.append(menu.prompt[0]) + # Promptless choices can be entered in show-all mode. Use + # standard_sc_expr_str() for them, so they show up as + # . + menu_prompts.append(menu.prompt[0] if menu.prompt else + standard_sc_expr_str(menu.item)) menu = _parent_menu(menu) menu_prompts.append("(top menu)") menu_prompts.reverse() @@ -2489,7 +2493,11 @@ def _menu_path_info(node): node = _parent_menu(node) while node is not _kconf.top_node: - path = " -> " + node.prompt[0] + path + # Promptless choices might appear among the parents. Use + # standard_sc_expr_str() for them, so that they show up as + # . + path = " -> " + (node.prompt[0] if node.prompt else + standard_sc_expr_str(node.item)) + path node = _parent_menu(node) return "(top menu)" + path @@ -2645,13 +2653,13 @@ def _node_str(node): # This approach gives nice alignment for empty string symbols ("() Foo") s = "{:{}}".format(_value_str(node), 3 + indent) - # 'not node.prompt' can only be True in show-all mode - if not node.prompt or \ - (_show_name and - (isinstance(node.item, Symbol) or - (isinstance(node.item, Choice) and node.item.name))): - - s += " <{}>".format(node.item.name) + if _should_show_name(node): + if isinstance(node.item, Symbol): + s += " <{}>".format(node.item.name) + else: + # For choices, use standard_sc_expr_str(). That way they show up as + # . + s += " " + standard_sc_expr_str(node.item) if node.prompt: s += " " @@ -2687,6 +2695,15 @@ def _node_str(node): return s +def _should_show_name(node): + # Returns True if 'node' is a symbol or choice whose name should shown (if + # any, as names are optional for choices) + + # The 'not node.prompt' case only hits in show-all mode, for promptless + # symbols and choices + return not node.prompt or \ + (_show_name and isinstance(node.item, (Symbol, Choice))) + def _value_str(node): # Returns the value part ("[*]", "", "(foo)" etc.) of a menu node -- cgit v1.2.3