diff options
| -rw-r--r-- | kconfiglib.py | 39 | ||||
| -rw-r--r-- | tests/Kreferenced | 43 | ||||
| -rw-r--r-- | testsuite.py | 28 |
3 files changed, 110 insertions, 0 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 56f9efa..6abb4e6 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4150,6 +4150,45 @@ class MenuNode(object): "ranges" ) + def referenced(self): + """ + Returns a set() of all symbols and choices referenced in the properties + and property conditions of this menu node. + + Also includes dependencies inherited from surrounding menus and if's. + Choices appear in the dependencies of choice symbols. + """ + res = set() + + if self.prompt: + res |= expr_items(self.prompt[1]) + + if self.item == MENU: + res |= expr_items(self.visibility) + + for value, cond in self.defaults: + res |= expr_items(value) + res |= expr_items(cond) + + for value, cond in self.selects: + res.add(value) + res |= expr_items(cond) + + for value, cond in self.implies: + res.add(value) + res |= expr_items(cond) + + for low, high, cond in self.ranges: + res.add(low) + res.add(high) + res |= expr_items(cond) + + # Need this to catch dependencies from a lone 'depends on' when there + # are no properties to propagate it to + res |= expr_items(self.dep) + + return res + def __repr__(self): """ Returns a string with information about the menu node when it is diff --git a/tests/Kreferenced b/tests/Kreferenced new file mode 100644 index 0000000..8dda5a2 --- /dev/null +++ b/tests/Kreferenced @@ -0,0 +1,43 @@ +config NO_REFS + bool + +config JUST_DEPENDS_ON_REFS + bool + depends on A && B + +if A + +menu "menu" + depends on B + visible if C + visible if D + +config LOTS_OF_REFS + bool "lots" if C || D + default E || F if G || H + default I || J if K || L + select M if N || O + select P if Q || R + imply S if T || U + imply V if W || X + depends on Y || Z + +endmenu + +endif + +config INT_REFS + int "int" + range A B if C && D + range E F if G && H + +choice CHOICE + bool "choice" + +config CHOICE_REF + bool "choice ref" + +endchoice + +comment "comment" + depends on A || B diff --git a/testsuite.py b/testsuite.py index 1f1bc32..5c12bc0 100644 --- a/testsuite.py +++ b/testsuite.py @@ -1009,8 +1009,36 @@ g ) + print("Testing MenuNode.referenced()") + + c = Kconfig("Kconfiglib/tests/Kreferenced", warn=False) + + def verify_deps(item, *dep_names): + verify_equal(tuple(sorted(item.name for item in item.referenced())), + dep_names) + + verify_deps(c.syms["NO_REFS"].nodes[0], "y") + + verify_deps(c.syms["JUST_DEPENDS_ON_REFS"].nodes[0], "A", "B") + + verify_deps(c.syms["LOTS_OF_REFS"].nodes[0], + *(chr(n) for n in range(ord('A'), ord('Z') + 1))) + + verify_deps(c.syms["INT_REFS"].nodes[0], + "A", "B", "C", "D", "E", "F", "G", "H", "y") + + verify_deps(c.syms["CHOICE_REF"].nodes[0], "CHOICE") + + verify_deps(c.menus[0], "A", "B", "C", "D") + + verify_deps(c.comments[0], "A", "B") + + print("Testing split_expr()") + c = Kconfig("Kconfiglib/tests/empty") + c.disable_warnings() + def verify_split(to_split, op, operand_strs): # The same hackage as in Kconfig.eval_string() c._line = "if " + to_split |
