diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-05-27 23:58:47 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-05-27 23:58:47 +0200 |
| commit | fc73c461f1a8acf3e09670e8f9429c7ef9d0b71f (patch) | |
| tree | fed01e7cc8e5caca2c790d0b14d3665887e91961 | |
| parent | 94020beb311eb8a9db9e3b841e36c96b1b0f72dd (diff) | |
Provide lists with all menus and comments
Handy e.g. when implementing advanced search features.
| -rw-r--r-- | kconfiglib.py | 17 | ||||
| -rw-r--r-- | tests/Kitemlists | 32 | ||||
| -rw-r--r-- | testsuite.py | 23 |
3 files changed, 71 insertions, 1 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index d8dc271..d69da5b 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -420,6 +420,14 @@ class Kconfig(object): A list with all choices, in the same order as they appear in the Kconfig files + menus: + A list with all menus, in the same order as they appear in the Kconfig + files + + comments: + A list with all comments, in the same order as they appear in the Kconfig + files + n/m/y: The predefined constant symbols n/m/y. Also available in const_syms. @@ -514,11 +522,13 @@ class Kconfig(object): "_warn_to_stderr", "_warnings_enabled", "choices", + "comments", "config_prefix", "const_syms", "defconfig_list", "defined_syms", "m", + "menus", "modules", "n", "named_choices", @@ -635,6 +645,9 @@ class Kconfig(object): self.named_choices = {} self.choices = [] + self.menus = [] + self.comments = [] + for nmy in "n", "m", "y": sym = Symbol() sym.kconfig = self @@ -1993,6 +2006,8 @@ class Kconfig(object): node.filename = self._filename node.linenr = self._linenr + self.menus.append(node) + self._parse_properties(node) self._parse_block(_T_ENDMENU, node, node) node.list = node.next @@ -2010,6 +2025,8 @@ class Kconfig(object): node.filename = self._filename node.linenr = self._linenr + self.comments.append(node) + self._parse_properties(node) prev.next = prev = node diff --git a/tests/Kitemlists b/tests/Kitemlists new file mode 100644 index 0000000..fc72e5c --- /dev/null +++ b/tests/Kitemlists @@ -0,0 +1,32 @@ +comment "comment 1" + +choice + bool "choice 1" +endchoice + +menu "menu 1" + +choice NAMED + bool "choice 2" +endchoice + +menu "menu 2" +menu "menu 3" +comment "comment 2" +endmenu + +choice + bool "choice 3" +endchoice + +endmenu + +menu "menu 4" +endmenu + +comment "comment 3" + +endmenu + +menu "menu 5" +endmenu diff --git a/testsuite.py b/testsuite.py index 9909e1e..1f0ef64 100644 --- a/testsuite.py +++ b/testsuite.py @@ -41,7 +41,7 @@ # All tests should pass. Report regressions to ulfalizer a.t Google's email # service. -from kconfiglib import Kconfig, Symbol, Choice, COMMENT, MENU, \ +from kconfiglib import Kconfig, Symbol, Choice, COMMENT, MENU, MenuNode, \ BOOL, TRISTATE, HEX, STRING, \ TRI_TO_STR, \ escape, unescape, \ @@ -957,6 +957,27 @@ g fail("recursive 'source' did not raise exception") + print("Testing Kconfig.choices/menus/comments") + + c = Kconfig("Kconfiglib/tests/Kitemlists") + + def verify_prompts(items, *expected_prompts): + verify(len(items) == len(expected_prompts), + "Wrong number of prompts for {}".format(items)) + + for item, expected_prompt in zip(items, expected_prompts): + if not isinstance(item, MenuNode): + item = item.nodes[0] + + verify(item.prompt[0] == expected_prompt, + "Wrong prompt for {}, expected '{}'" + .format(repr(item), expected_prompt)) + + verify_prompts(c.choices, "choice 1", "choice 2", "choice 3") + verify_prompts(c.menus, "menu 1", "menu 2", "menu 3", "menu 4", "menu 5") + verify_prompts(c.comments, "comment 1", "comment 2", "comment 3") + + print("Testing Symbol/Choice.direct_dep") c = Kconfig("Kconfiglib/tests/Kdirdep") |
