Skip to content

Commit 3c543d2

Browse files
mchehabgregkh
authored andcommitted
docs: kernel_abi.py: Handle with a lazy Sphinx parser
The Sphinx docutils parser is lazy: if the content is bigger than a certain number of lines, it silenlty stops parsing it, producing an incomplete content. This seems to be worse on newer Sphinx versions, like 2.0. So, change the logic to parse the contents per input file. Acked-by: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Link: https://lore.kernel.org/r/4659b60795739308e34d2d00c57ee0742a9cd2ab.1604042072.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 997b7c8 commit 3c543d2

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

Documentation/sphinx/kernel_abi.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import subprocess
3838
import sys
3939
import re
40+
import kernellog
4041

4142
from os import path
4243

@@ -80,12 +81,6 @@ class KernelCmd(Directive):
8081
"debug" : directives.flag
8182
}
8283

83-
def warn(self, message, **replace):
84-
replace["fname"] = self.state.document.current_source
85-
replace["line_no"] = replace.get("line_no", self.lineno)
86-
message = ("%(fname)s:%(line_no)s: [kernel-abi WARN] : " + message) % replace
87-
self.state.document.settings.env.app.warn(message, prefix="")
88-
8984
def run(self):
9085

9186
doc = self.state.document
@@ -111,7 +106,7 @@ def run(self):
111106
shell_env["srctree"] = srctree
112107

113108
lines = self.runCmd(cmd, shell=True, cwd=cwd, env=shell_env)
114-
nodeList = self.nestedParse(lines, fname)
109+
nodeList = self.nestedParse(lines, self.arguments[0])
115110
return nodeList
116111

117112
def runCmd(self, cmd, **kwargs):
@@ -138,9 +133,9 @@ def runCmd(self, cmd, **kwargs):
138133
% (self.name, ErrorString(exc)))
139134
return out
140135

141-
def nestedParse(self, lines, f):
136+
def nestedParse(self, lines, fname):
142137
content = ViewList()
143-
node = nodes.section()
138+
node = nodes.section()
144139

145140
if "debug" in self.options:
146141
code_block = "\n\n.. code-block:: rst\n :linenos:\n"
@@ -150,28 +145,46 @@ def nestedParse(self, lines, f):
150145

151146
line_regex = re.compile("^#define LINENO (\S+)\#([0-9]+)$")
152147
ln = 0
148+
n = 0
149+
f = fname
153150

154151
for line in lines.split("\n"):
152+
n = n + 1
155153
match = line_regex.search(line)
156154
if match:
157-
f = match.group(1)
155+
new_f = match.group(1)
156+
157+
# Sphinx parser is lazy: it stops parsing contents in the
158+
# middle, if it is too big. So, handle it per input file
159+
if new_f != f and content:
160+
self.do_parse(content, node)
161+
content = ViewList()
162+
163+
f = new_f
164+
158165
# sphinx counts lines from 0
159166
ln = int(match.group(2)) - 1
160167
else:
161168
content.append(line, f, ln)
162169

163-
buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter
170+
kernellog.info(self.state.document.settings.env.app, "%s: parsed %i lines" % (fname, n))
171+
172+
if content:
173+
self.do_parse(content, node)
164174

175+
return node.children
176+
177+
def do_parse(self, content, node):
165178
if Use_SSI:
166179
with switch_source_input(self.state, content):
167180
self.state.nested_parse(content, 0, node, match_titles=1)
168181
else:
182+
buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter
183+
169184
self.state.memo.title_styles = []
170185
self.state.memo.section_level = 0
171186
self.state.memo.reporter = AutodocReporter(content, self.state.memo.reporter)
172187
try:
173188
self.state.nested_parse(content, 0, node, match_titles=1)
174189
finally:
175190
self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf
176-
177-
return node.children

0 commit comments

Comments
 (0)