Skip to content

Commit c1f54cc

Browse files
ulfalizernashif
authored andcommitted
Kconfig: Show include paths in menuconfig and documentation
Update Kconfiglib and menuconfig to upstream revision a28bc4da9762e, which adds include path information to menuconfig, showing how the Kconfig file of the symbol got 'source'd in addition to showing the definition location. Add include path information to the auto-generated Kconfig documentation too. Some small Kconfiglib bugs are fixed to, like error reporting for recursive 'source's being broken (crashing instead of printing the error), a minor file descriptor leak, and syntax checking not catching extra trailing tokens after 'if <expr>' and 'depends on <expr>'. Signed-off-by: Ulf Magnusson <[email protected]>
1 parent 845fdbb commit c1f54cc

File tree

3 files changed

+228
-137
lines changed

3 files changed

+228
-137
lines changed

doc/scripts/genrest.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,8 @@ def write_kconfig_rst():
9090
# String with the RST for the index page
9191
index_rst = INDEX_RST_HEADER
9292

93-
# - Sort the symbols by name so that they end up in sorted order in
94-
# index.rst
95-
#
96-
# - Use set() to get rid of duplicates for symbols defined in multiple
97-
# locations.
98-
for sym in sorted(set(kconf.defined_syms), key=lambda sym: sym.name):
93+
# Sort the symbols by name so that they end up in sorted order in index.rst
94+
for sym in sorted(kconf.unique_defined_syms, key=lambda sym: sym.name):
9995
# Write an RST file for the symbol
10096
write_sym_rst(sym, out_dir)
10197

@@ -107,7 +103,7 @@ def write_kconfig_rst():
107103
" / ".join(node.prompt[0]
108104
for node in sym.nodes if node.prompt))
109105

110-
for choice in kconf.choices:
106+
for choice in kconf.unique_choices:
111107
# Write an RST file for the choice
112108
write_choice_rst(choice, out_dir)
113109

@@ -328,8 +324,21 @@ def add_selecting_implying_rst(type_str, expr):
328324

329325

330326
def kconfig_definition_rst(sc):
331-
# Returns RST that lists the Kconfig definition(s) of 'sc' (symbol or
332-
# choice)
327+
# Returns RST that lists the Kconfig definition location, include path,
328+
# menu path, and Kconfig definition for each node (definition location) of
329+
# 'sc' (symbol or choice)
330+
331+
# Fancy Unicode arrow. Added in '93, so ought to be pretty safe.
332+
arrow = " \N{RIGHTWARDS ARROW} "
333+
334+
def include_path(node):
335+
if not node.include_path:
336+
# In the top-level Kconfig file
337+
return ""
338+
339+
return "Included via {}\n\n".format(
340+
arrow.join("``{}:{}``".format(filename, linenr)
341+
for filename, linenr in node.include_path))
333342

334343
def menu_path(node):
335344
path = ""
@@ -347,23 +356,30 @@ def menu_path(node):
347356
if node is node.kconfig.top_node:
348357
break
349358

350-
# Fancy Unicode arrow. Added in '93, so ought to be pretty safe.
351-
path = " → " + node.prompt[0] + path
359+
path = arrow + node.prompt[0] + path
352360

353361
return "(top menu)" + path
354362

355363
heading = "Kconfig definition"
356364
if len(sc.nodes) > 1: heading += "s"
357365
rst = "{}\n{}\n\n".format(heading, len(heading)*"=")
358366

359-
rst += ".. highlight:: kconfig\n\n"
367+
rst += ".. highlight:: kconfig"
360368

361-
rst += "\n\n".join(
362-
"At ``{}:{}``, in menu ``{}``:\n\n"
363-
".. parsed-literal::\n\n"
364-
"{}".format(node.filename, node.linenr, menu_path(node),
365-
textwrap.indent(node.custom_str(rst_link), " "*4))
366-
for node in sc.nodes)
369+
for node in sc.nodes:
370+
rst += "\n\n" \
371+
"At ``{}:{}``\n\n" \
372+
"{}" \
373+
"Menu path: {}\n\n" \
374+
".. parsed-literal::\n\n{}" \
375+
.format(node.filename, node.linenr,
376+
include_path(node), menu_path(node),
377+
textwrap.indent(node.custom_str(rst_link), 4*" "))
378+
379+
# Not the last node?
380+
if node is not sc.nodes[-1]:
381+
# Add a horizontal line between multiple definitions
382+
rst += "\n\n----"
367383

368384
rst += "\n\n*(Definitions include propagated dependencies, " \
369385
"including from if's and menus.)*"

0 commit comments

Comments
 (0)