mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-13 14:24:11 +08:00
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 sys
|
||||
import re
|
||||
import kernellog
|
||||
|
||||
from os import path
|
||||
|
||||
@ -80,12 +81,6 @@ class KernelCmd(Directive):
|
||||
"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):
|
||||
|
||||
doc = self.state.document
|
||||
@ -111,7 +106,7 @@ class KernelCmd(Directive):
|
||||
shell_env["srctree"] = srctree
|
||||
|
||||
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
|
||||
|
||||
def runCmd(self, cmd, **kwargs):
|
||||
@ -138,9 +133,9 @@ class KernelCmd(Directive):
|
||||
% (self.name, ErrorString(exc)))
|
||||
return out
|
||||
|
||||
def nestedParse(self, lines, f):
|
||||
def nestedParse(self, lines, fname):
|
||||
content = ViewList()
|
||||
node = nodes.section()
|
||||
node = nodes.section()
|
||||
|
||||
if "debug" in self.options:
|
||||
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]+)$")
|
||||
ln = 0
|
||||
n = 0
|
||||
f = fname
|
||||
|
||||
for line in lines.split("\n"):
|
||||
n = n + 1
|
||||
match = line_regex.search(line)
|
||||
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
|
||||
ln = int(match.group(2)) - 1
|
||||
else:
|
||||
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:
|
||||
with switch_source_input(self.state, content):
|
||||
self.state.nested_parse(content, 0, node, match_titles=1)
|
||||
else:
|
||||
buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter
|
||||
|
||||
self.state.memo.title_styles = []
|
||||
self.state.memo.section_level = 0
|
||||
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)
|
||||
finally:
|
||||
self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf
|
||||
|
||||
return node.children
|
||||
|
Loading…
Reference in New Issue
Block a user