Skip to content

Commit 668b9d1

Browse files
mchehabJonathan Corbet
authored andcommitted
docs: sphinx: kerneldoc: verbose kernel-doc command if V=1
It is useful to know what kernel-doc command was used during document build time, as it allows one to check the output the same way as Sphinx extension does. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/a2f01590814b111e138f278e8a721024fdf2d445.1744106242.git.mchehab+huawei@kernel.org
1 parent 02df8e3 commit 668b9d1

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Documentation/sphinx/kerneldoc.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@
4343

4444
__version__ = '1.0'
4545

46+
def cmd_str(cmd):
47+
"""
48+
Helper function to output a command line that can be used to produce
49+
the same records via command line. Helpful to debug troubles at the
50+
script.
51+
"""
52+
53+
cmd_line = ""
54+
55+
for w in cmd:
56+
if w == "" or " " in w:
57+
esc_cmd = "'" + w + "'"
58+
else:
59+
esc_cmd = w
60+
61+
if cmd_line:
62+
cmd_line += " " + esc_cmd
63+
continue
64+
else:
65+
cmd_line = esc_cmd
66+
67+
return cmd_line
68+
4669
class KernelDocDirective(Directive):
4770
"""Extract kernel-doc comments from the specified file"""
4871
required_argument = 1
@@ -57,6 +80,7 @@ class KernelDocDirective(Directive):
5780
}
5881
has_content = False
5982
logger = logging.getLogger('kerneldoc')
83+
verbose = 0
6084

6185
def run(self):
6286
env = self.state.document.settings.env
@@ -65,6 +89,13 @@ def run(self):
6589
filename = env.config.kerneldoc_srctree + '/' + self.arguments[0]
6690
export_file_patterns = []
6791

92+
verbose = os.environ.get("V")
93+
if verbose:
94+
try:
95+
self.verbose = int(verbose)
96+
except ValueError:
97+
pass
98+
6899
# Tell sphinx of the dependency
69100
env.note_dependency(os.path.abspath(filename))
70101

@@ -104,6 +135,9 @@ def run(self):
104135

105136
cmd += [filename]
106137

138+
if self.verbose >= 1:
139+
print(cmd_str(cmd))
140+
107141
try:
108142
self.logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd)))
109143

0 commit comments

Comments
 (0)