From 63a44186137e2706afec0aef278cd5d123fc98dc Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 14 May 2018 14:48:22 +0200 Subject: Record which MenuNode has each property This allows accurate documentation to be generated for symbols and choices defined in multiple locations. There are now MenuNode.defaults, MenuNode.selects, etc., lists that mirror the corresponding Symbol/Choice lists. Symbol/Choice.__str__() now correctly show property locations as well, by simply concatenating the strings returned by MenuNode.__str__() for each node. _parse_properties() was modified to add all properties directly to the menu node instead of adding them to the contained symbol or choice. The properties are then copied up to symbols and choices in _finalize_tree(). Dependency propagation is handled at the same time. As a side effect, this cleans up the code a bit and de-bloats _parse_properties(). Update the menuconfig implementation to use the new functionality. It now lists the menu nodes for symbols and choices with the correct properties for each node (previously, all defaults, selects, implies, and ranges appeared on the first definition). --- menuconfig.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'menuconfig.py') diff --git a/menuconfig.py b/menuconfig.py index 9385b03..31fe4f2 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -91,7 +91,7 @@ import textwrap import kconfiglib from kconfiglib import Kconfig, \ - Symbol, Choice, MENU, COMMENT, \ + Symbol, Choice, MENU, COMMENT, MenuNode, \ BOOL, TRISTATE, STRING, INT, HEX, UNKNOWN, \ AND, OR, NOT, \ expr_value, split_expr, \ @@ -1758,7 +1758,6 @@ def _info_str(node): _direct_dep_info(sym) + _defaults_info(sym) + _select_imply_info(sym) + - _loc_info(sym) + _kconfig_def_info(sym) ) @@ -1773,7 +1772,6 @@ def _info_str(node): _choice_syms_info(choice) + _direct_dep_info(choice) + _defaults_info(choice) + - _loc_info(choice) + _kconfig_def_info(choice) ) @@ -1916,24 +1914,22 @@ def _select_imply_info(sym): return s -def _loc_info(sc): - # Returns a string with information about where 'sc' (Symbol or Choice) is - # defined in the Kconfig files. Also includes the menu path leading up to - # it. +def _kconfig_def_info(item): + # Returns a string with the definition of 'item' in Kconfig syntax, + # together with the definition location(s) - s = "Definition location{}:\n".format("s" if len(sc.nodes) > 1 else "") + nodes = [item] if isinstance(item, MenuNode) else item.nodes - for node in sc.nodes: - s += " - {}:{}\n Menu: {}\n" \ - .format(node.filename, node.linenr, _menu_path_info(node)) + s = "Kconfig definition{}, with propagated dependencies\n" \ + .format("s" if len(nodes) > 1 else "") + s += (len(s) - 1)*"=" + "\n\n" - return s + "\n" + s += "\n\n".join("At {}:{}, in menu {}:\n\n{}".format( + node.filename, node.linenr, _menu_path_info(node), + textwrap.indent(str(node), " ")) + for node in nodes) -def _kconfig_def_info(item): - # Returns a string with the definition of 'item' in Kconfig syntax - - return "Kconfig definition (with propagated dependencies):\n\n" + \ - textwrap.indent(str(item).expandtabs(), " ") + return s def _menu_path_info(node): # Returns a string describing the menu path leading up to 'node' -- cgit v1.2.3