Skip to content

Commit 9f488cc

Browse files
author
Jonathan Corbet
committed
Merge branch 'mauro' into docs-mw
Mauro says: This changeset contains the kernel-doc.py script to replace the verable kernel-doc originally written in Perl. It replaces the first version and the second series I sent on the top of it. I tried to stay as close as possible of the original Perl implementation on the first patch introducing kernel-doc.py, as it helps to double check if each function was properly translated to Python. This have been helpful debugging troubles that happened during the conversion. I worked hard to make it bug-compatible with the original one. Still, its output has a couple of differences from the original one: - The tab expansion works better with the Python script. With that, some outputs that contain tabs at kernel-doc markups are now different; - The new script works better stripping blank lines. So, there are a couple of empty new lines that are now stripped with this version; - There is a buggy logic at kernel-doc to strip empty description and return sections. I was not able to replicate the exact behavior. So, I ended adding an extra logic to strip empty sections with a different algorithm. Yet, on my tests, the results are compatible with the venerable script output for all .. kernel-doc tags found in Documentation/. I double-checked this by adding support to output the kernel-doc commands when V=1, and then I ran a diff between kernel-doc.pl and kernel-doc.py for the same command lines. The only patch that doesn't belong to this series is a patch dropping kernel-doc.pl. I opted to keep it for now, as it can help to better test the new tools. With such changes, if one wants to build docs with the old script, all it is needed is to use KERNELDOC parameter, e.g.: $ make KERNELDOC=scripts/kernel-doc.pl htmldocs
2 parents 0af2f6b + de258fa commit 9f488cc

File tree

11 files changed

+5868
-2441
lines changed

11 files changed

+5868
-2441
lines changed

.pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[MASTER]
2+
init-hook='import sys; sys.path += ["scripts/lib/kdoc", "scripts/lib/abi"]'

Documentation/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ endif #HAVE_LATEXMK
6060
# Internal variables.
6161
PAPEROPT_a4 = -D latex_paper_size=a4
6262
PAPEROPT_letter = -D latex_paper_size=letter
63-
KERNELDOC = $(srctree)/scripts/kernel-doc
63+
KERNELDOC = $(srctree)/scripts/kernel-doc.py
6464
KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
6565
ALLSPHINXOPTS = $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
6666
ifneq ($(wildcard $(srctree)/.config),)

Documentation/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def get_cline_version():
540540
# kernel-doc extension configuration for running Sphinx directly (e.g. by Read
541541
# the Docs). In a normal build, these are supplied from the Makefile via command
542542
# line arguments.
543-
kerneldoc_bin = '../scripts/kernel-doc'
543+
kerneldoc_bin = '../scripts/kernel-doc.py'
544544
kerneldoc_srctree = '..'
545545

546546
# ------------------------------------------------------------------------------

Documentation/sphinx/kerneldoc.py

Lines changed: 46 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

@@ -87,6 +118,10 @@ def run(self):
87118
identifiers = self.options.get('identifiers').split()
88119
if identifiers:
89120
for i in identifiers:
121+
i = i.rstrip("\\").strip()
122+
if not i:
123+
continue
124+
90125
cmd += ['-function', i]
91126
else:
92127
cmd += ['-no-doc-sections']
@@ -95,15 +130,26 @@ def run(self):
95130
no_identifiers = self.options.get('no-identifiers').split()
96131
if no_identifiers:
97132
for i in no_identifiers:
133+
i = i.rstrip("\\").strip()
134+
if not i:
135+
continue
136+
98137
cmd += ['-nosymbol', i]
99138

100139
for pattern in export_file_patterns:
140+
pattern = pattern.rstrip("\\").strip()
141+
if not pattern:
142+
continue
143+
101144
for f in glob.glob(env.config.kerneldoc_srctree + '/' + pattern):
102145
env.note_dependency(os.path.abspath(f))
103146
cmd += ['-export-file', f]
104147

105148
cmd += [filename]
106149

150+
if self.verbose >= 1:
151+
print(cmd_str(cmd))
152+
107153
try:
108154
self.logger.verbose("calling kernel-doc '%s'" % (" ".join(cmd)))
109155

0 commit comments

Comments
 (0)