summaryrefslogtreecommitdiff
path: root/examples/find_symbol.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-09-15 02:19:34 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-09-15 03:07:11 +0200
commit35a60b786c646c846d9bad6a5f15711acc9a62c6 (patch)
treee0848683c8b4f39d1f0959fb6b9a95c14ca2a3f0 /examples/find_symbol.py
parentf861c271dcbb06e0101c01add3d07006c2d3a09c (diff)
Update some examples to use node_iter()
Simplifies the code. Should promote new APIs. Also fix list_undefined.py for recent kernels. More environment variables are referenced now.
Diffstat (limited to 'examples/find_symbol.py')
-rw-r--r--examples/find_symbol.py30
1 files changed, 6 insertions, 24 deletions
diff --git a/examples/find_symbol.py b/examples/find_symbol.py
index 0d3c968..132d45f 100644
--- a/examples/find_symbol.py
+++ b/examples/find_symbol.py
@@ -79,43 +79,25 @@ import sys
import kconfiglib
-def referencing_nodes(node, sym):
- # Returns a list of all menu nodes that reference 'sym' in any of their
- # properties or property conditions
-
- res = []
-
- while node:
- if sym in node.referenced:
- res.append(node)
-
- if node.list:
- res.extend(referencing_nodes(node.list, sym))
-
- node = node.next
-
- return res
-
-
if len(sys.argv) < 3:
sys.exit('Pass symbol name (without "CONFIG_" prefix) with SCRIPT_ARG=<name>')
kconf = kconfiglib.Kconfig(sys.argv[1])
sym_name = sys.argv[2]
-
if sym_name not in kconf.syms:
print("No symbol {} exists in the configuration".format(sym_name))
sys.exit(0)
-nodes = referencing_nodes(kconf.top_node, kconf.syms[sym_name])
-if not nodes:
- print("No reference to {} found".format(sym_name))
+referencing = [node for node in kconf.node_iter()
+ if kconf.syms[sym_name] in node.referenced]
+if not referencing:
+ print("No references to {} found".format(sym_name))
sys.exit(0)
print("Found {} locations that reference {}:\n"
- .format(len(nodes), sym_name))
+ .format(len(referencing), sym_name))
-for i, node in enumerate(nodes, 1):
+for i, node in enumerate(referencing, 1):
print("========== Location {} ({}:{}) ==========\n\n{}"
.format(i, node.filename, node.linenr, node))