All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
To: gregkh@linuxfoundation.org
Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org
Subject: [PATCH v4 09/15] docs: kernel_abi.py: Sphinx has a lazy parser... workaround it
Date: Wed, 17 Jul 2019 09:28:13 -0300	[thread overview]
Message-ID: <4a5e7955ff0a7621284bcf784d242dcb3ec3452d.1563365880.git.mchehab+samsung@kernel.org> (raw)
In-Reply-To: <cover.1563365880.git.mchehab+samsung@kernel.org>

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
---
 Documentation/sphinx/kernel_abi.py | 39 ++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/Documentation/sphinx/kernel_abi.py b/Documentation/sphinx/kernel_abi.py
index 30cac84e18f5..6d2f56500197 100644
--- a/Documentation/sphinx/kernel_abi.py
+++ b/Documentation/sphinx/kernel_abi.py
@@ -36,6 +36,7 @@ import os
 import subprocess
 import sys
 import re
+import kernellog
 
 from os import path
 
@@ -80,12 +81,6 @@ class KernelCmd(Directive):
         "rst"       : directives.unchanged
     }
 
-    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
@@ -114,7 +109,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):
@@ -141,9 +136,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"
@@ -153,22 +148,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)
@@ -176,5 +191,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
-- 
2.21.0


  parent reply	other threads:[~2019-07-17 12:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1563365880.git.mchehab+samsung@kernel.org>
2019-07-17 12:28 ` [PATCH v4 03/15] docs: kernellog.py: add support for info() Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 04/15] docs: kernel_abi.py: add a script to parse ABI documentation Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 05/15] docs: kernel_abi.py: fix UTF-8 support Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 06/15] docs: kernel_abi.py: make it compatible with Sphinx 1.7+ Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 07/15] docs: kernel_abi.py: use --enable-lineno for get_abi.pl Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 08/15] docs: kernel_abi.py: allow passing ABI files in a transparent way Mauro Carvalho Chehab
2019-07-17 12:28 ` Mauro Carvalho Chehab [this message]
2019-07-17 12:28 ` [PATCH v4 10/15] docs: add ABI documentation to the admin-guide book Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 12/15] docs: ABI: stable: make files ReST compatible Mauro Carvalho Chehab
2019-07-17 12:28   ` [Xen-devel] " Mauro Carvalho Chehab
2019-07-17 12:28   ` Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 13/15] docs: ABI: testing: make the files compatible with ReST output Mauro Carvalho Chehab
2019-07-17 12:28   ` [Xen-devel] " Mauro Carvalho Chehab
2019-07-17 12:28   ` Mauro Carvalho Chehab
2019-07-17 16:13   ` Jonathan Cameron
2019-07-17 16:13     ` [Xen-devel] " Jonathan Cameron
2019-07-17 16:13     ` Jonathan Cameron
2019-07-17 16:13     ` Jonathan Cameron
2019-07-17 12:28 ` [PATCH v4 14/15] docs: ABI: obsolete, removed: don't escape ReST-incompatible chars Mauro Carvalho Chehab
2019-07-17 12:28 ` [PATCH v4 15/15] docs: Kconfig/Makefile: add a check for broken ABI files Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a5e7955ff0a7621284bcf784d242dcb3ec3452d.1563365880.git.mchehab+samsung@kernel.org \
    --to=mchehab+samsung@kernel.org \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-doc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.