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>
This commit is contained in:
parent
997b7c8b4a
commit
3c543d2989
|
@ -37,6 +37,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
import kernellog
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
@ -80,12 +81,6 @@ class KernelCmd(Directive):
|
||||||
"debug" : directives.flag
|
"debug" : directives.flag
|
||||||
}
|
}
|
||||||
|
|
||||||
def warn(self, message, **replace):
|
|
||||||
replace["fname"] = self.state.document.current_source
|
|
||||||
replace["line_no"] = replace.get("line_no", self.lineno)
|
|
||||||
message = ("%(fname)s:%(line_no)s: [kernel-abi WARN] : " + message) % replace
|
|
||||||
self.state.document.settings.env.app.warn(message, prefix="")
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
doc = self.state.document
|
doc = self.state.document
|
||||||
|
@ -111,7 +106,7 @@ class KernelCmd(Directive):
|
||||||
shell_env["srctree"] = srctree
|
shell_env["srctree"] = srctree
|
||||||
|
|
||||||
lines = self.runCmd(cmd, shell=True, cwd=cwd, env=shell_env)
|
lines = self.runCmd(cmd, shell=True, cwd=cwd, env=shell_env)
|
||||||
nodeList = self.nestedParse(lines, fname)
|
nodeList = self.nestedParse(lines, self.arguments[0])
|
||||||
return nodeList
|
return nodeList
|
||||||
|
|
||||||
def runCmd(self, cmd, **kwargs):
|
def runCmd(self, cmd, **kwargs):
|
||||||
|
@ -138,9 +133,9 @@ class KernelCmd(Directive):
|
||||||
% (self.name, ErrorString(exc)))
|
% (self.name, ErrorString(exc)))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def nestedParse(self, lines, f):
|
def nestedParse(self, lines, fname):
|
||||||
content = ViewList()
|
content = ViewList()
|
||||||
node = nodes.section()
|
node = nodes.section()
|
||||||
|
|
||||||
if "debug" in self.options:
|
if "debug" in self.options:
|
||||||
code_block = "\n\n.. code-block:: rst\n :linenos:\n"
|
code_block = "\n\n.. code-block:: rst\n :linenos:\n"
|
||||||
|
@ -150,22 +145,42 @@ class KernelCmd(Directive):
|
||||||
|
|
||||||
line_regex = re.compile("^#define LINENO (\S+)\#([0-9]+)$")
|
line_regex = re.compile("^#define LINENO (\S+)\#([0-9]+)$")
|
||||||
ln = 0
|
ln = 0
|
||||||
|
n = 0
|
||||||
|
f = fname
|
||||||
|
|
||||||
for line in lines.split("\n"):
|
for line in lines.split("\n"):
|
||||||
|
n = n + 1
|
||||||
match = line_regex.search(line)
|
match = line_regex.search(line)
|
||||||
if match:
|
if match:
|
||||||
f = match.group(1)
|
new_f = match.group(1)
|
||||||
|
|
||||||
|
# Sphinx parser is lazy: it stops parsing contents in the
|
||||||
|
# middle, if it is too big. So, handle it per input file
|
||||||
|
if new_f != f and content:
|
||||||
|
self.do_parse(content, node)
|
||||||
|
content = ViewList()
|
||||||
|
|
||||||
|
f = new_f
|
||||||
|
|
||||||
# sphinx counts lines from 0
|
# sphinx counts lines from 0
|
||||||
ln = int(match.group(2)) - 1
|
ln = int(match.group(2)) - 1
|
||||||
else:
|
else:
|
||||||
content.append(line, f, ln)
|
content.append(line, f, ln)
|
||||||
|
|
||||||
buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter
|
kernellog.info(self.state.document.settings.env.app, "%s: parsed %i lines" % (fname, n))
|
||||||
|
|
||||||
|
if content:
|
||||||
|
self.do_parse(content, node)
|
||||||
|
|
||||||
|
return node.children
|
||||||
|
|
||||||
|
def do_parse(self, content, node):
|
||||||
if Use_SSI:
|
if Use_SSI:
|
||||||
with switch_source_input(self.state, content):
|
with switch_source_input(self.state, content):
|
||||||
self.state.nested_parse(content, 0, node, match_titles=1)
|
self.state.nested_parse(content, 0, node, match_titles=1)
|
||||||
else:
|
else:
|
||||||
|
buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter
|
||||||
|
|
||||||
self.state.memo.title_styles = []
|
self.state.memo.title_styles = []
|
||||||
self.state.memo.section_level = 0
|
self.state.memo.section_level = 0
|
||||||
self.state.memo.reporter = AutodocReporter(content, self.state.memo.reporter)
|
self.state.memo.reporter = AutodocReporter(content, self.state.memo.reporter)
|
||||||
|
@ -173,5 +188,3 @@ class KernelCmd(Directive):
|
||||||
self.state.nested_parse(content, 0, node, match_titles=1)
|
self.state.nested_parse(content, 0, node, match_titles=1)
|
||||||
finally:
|
finally:
|
||||||
self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf
|
self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf
|
||||||
|
|
||||||
return node.children
|
|
||||||
|
|
Loading…
Reference in New Issue