Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp588675ybd; Sat, 22 Jun 2019 10:02:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwz1nNUneba6+CnD440lhRodv6fcDUWHYgwpcKZlybaQ/+82qjv/FbIDZiXpmC+rUTr2C3N X-Received: by 2002:a17:90a:1951:: with SMTP id 17mr14027973pjh.79.1561222935062; Sat, 22 Jun 2019 10:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561222935; cv=none; d=google.com; s=arc-20160816; b=KYyxtC4/1edn4p9VTO1HsMA1YMx4xVi9VqFIMC0lCCHyLIODqWMZb7R8xHR5R2Iw9s EsUMSwMBMhl/asZcb9xo54Ci/WcZaRWlmmvW6DhhSUCLZg7G25iz1AU8NFB9K7i3jh/N lTjJoVV2CynKAtFy3StSSnWeR7a4bfG8UnlBteZC7m85AL8zXAk3yPLMR1y67A3lmLNa st5CN3+74Dzf5BGFDj8h/uOADqtfkXqU66j2NsbQjjkZJQNHISs9se8dMLbvjXfD85K5 bpZfsWAt3ll/QLiEtNP7ag/f6eTQqj/5pFE1m0V+h8AY2cmzYkk6ScPf7xL80MWzPXL3 NHDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PIAs7lJjyaQE53dcQ6QY9JIHl8hWEaQxmoiFris3yfc=; b=mv22tdVqzOzIZtgHLuxNzKbkngbWLWYFgEtCvT31oBkWGNNjOIHPKk1uCVUuHGw2F0 4voRvZehtK9GttoMdtLfwWce8wBw0Km7OzDTPPWRQgJ7HvjL5TzkxyemlNn+ARaQxwp7 yxwaPstSE6q5FPvn86qBWMy0z0gwW+LdKLPGhaTvtPnBU/XpaOo6ZXsOgUPLgaeLSQYB BKgp5XDiQQwwE02EjFULrU07Sdhq9AVgNpdRMYbpep4418cakzf44tCsCH4DfYytEi/z cW62lbivqhRbJF/IOMIDXXo6YWUCETGakd2jPFQahFMGGbRyNVvZ6QabMbE4gLgipXaU l64A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=RNZueuof; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o63si6017254pjo.94.2019.06.22.10.01.57; Sat, 22 Jun 2019 10:02:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=RNZueuof; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726386AbfFVQ67 (ORCPT + 99 others); Sat, 22 Jun 2019 12:58:59 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:42798 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbfFVQ67 (ORCPT ); Sat, 22 Jun 2019 12:58:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PIAs7lJjyaQE53dcQ6QY9JIHl8hWEaQxmoiFris3yfc=; b=RNZueuofP4rWNEkgKeRA6Qp5b6 yHz/3qXs+pJBMtsYXbeK7lv17sFFpExKcm9GKo48Is6R1fdqVOECyBkQ9VMyVFUPZtmjwAVSciyso 6x/CX9LaYfRwzDY/d1IeGe8CPWkuM2ASuQoQ1n/qojxT83QeYWwd9u+y1axrZYVLJnCk0wPMg1Z7R nUtjXCEY3D16NCpnGZtQS9RNoD7MpB4CLOzfIFxytTbGdwr2hO0Ci40bq9O7PpokUJuWeMjrYDu7d vlZ3U8BmzMT/HdD/CKCDNFoJ7BkJmhXRUfisZOjbCQ84TFfjJURuYoK72tfUGdcoBHTI4GHUMR1N+ zOR7TcHA==; Received: from [179.95.45.115] (helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hejLu-00054o-GY; Sat, 22 Jun 2019 16:58:58 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1hejLr-0000vP-U0; Sat, 22 Jun 2019 13:58:55 -0300 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , gregkh@linuxfoundation.org, Jonathan Corbet Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH 05/12] docs: kernel_abi.py: add a script to parse ABI documentation Date: Sat, 22 Jun 2019 13:58:46 -0300 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ABI documentation is special: it is not plain text files, but, instead, files with an strict format, as specified by Documentation/ABI/README. Add a parser for it. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/kernel_abi.py | 155 +++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 Documentation/sphinx/kernel_abi.py diff --git a/Documentation/sphinx/kernel_abi.py b/Documentation/sphinx/kernel_abi.py new file mode 100644 index 000000000000..32ce90775d96 --- /dev/null +++ b/Documentation/sphinx/kernel_abi.py @@ -0,0 +1,155 @@ +# -*- coding: utf-8; mode: python -*- +u""" + kernel-abi + ~~~~~~~~~~ + + Implementation of the ``kernel-abi`` reST-directive. + + :copyright: Copyright (C) 2016 Markus Heiser + :copyright: Copyright (C) 2016 Mauro Carvalho Chehab + :license: GPL Version 2, June 1991 see Linux/COPYING for details. + + The ``kernel-abi`` (:py:class:`KernelCmd`) directive calls the + scripts/get_abi.pl script to parse the Kernel ABI files. + + Overview of directive's argument and options. + + .. code-block:: rst + + .. kernel-abi:: + :debug: + + The argument ```` is required. It contains the + location of the ABI files to be parsed. + + ``debug`` + Inserts a code-block with the *raw* reST. Sometimes it is helpful to see + what reST is generated. + +""" + +import sys +import os +from os import path +import subprocess + +from sphinx.ext.autodoc import AutodocReporter + +from docutils import nodes +from docutils.parsers.rst import Directive, directives +from docutils.statemachine import ViewList +from docutils.utils.error_reporting import ErrorString + + +__version__ = '1.0' + +# We can't assume that six is installed +PY3 = sys.version_info[0] == 3 +PY2 = sys.version_info[0] == 2 +if PY3: + # pylint: disable=C0103, W0622 + unicode = str + basestring = str + +def setup(app): + + app.add_directive("kernel-abi", KernelCmd) + return dict( + version = __version__ + , parallel_read_safe = True + , parallel_write_safe = True + ) + +class KernelCmd(Directive): + + u"""KernelABI (``kernel-abi``) directive""" + + required_arguments = 1 + optional_arguments = 0 + has_content = False + final_argument_whitespace = True + + option_spec = { + "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 + if not doc.settings.file_insertion_enabled: + raise self.warning("docutils: file insertion disabled") + + env = doc.settings.env + cwd = path.dirname(doc.current_source) + cmd = "get_abi.pl rest --dir " + cmd += self.arguments[0] + + srctree = path.abspath(os.environ["srctree"]) + + fname = cmd + + # extend PATH with $(srctree)/scripts + path_env = os.pathsep.join([ + srctree + os.sep + "scripts", + os.environ["PATH"] + ]) + shell_env = os.environ.copy() + shell_env["PATH"] = path_env + shell_env["srctree"] = srctree + + lines = self.runCmd(cmd, shell=True, cwd=cwd, env=shell_env) + nodeList = self.nestedParse(lines, fname) + return nodeList + + def runCmd(self, cmd, **kwargs): + u"""Run command ``cmd`` and return it's stdout as unicode.""" + + try: + proc = subprocess.Popen( + cmd + , stdout = subprocess.PIPE + , stderr = subprocess.PIPE + , universal_newlines = True + , **kwargs + ) + out, err = proc.communicate() + if err: + self.warn(err) + if proc.returncode != 0: + raise self.severe( + u"command '%s' failed with return code %d" + % (cmd, proc.returncode) + ) + except OSError as exc: + raise self.severe(u"problems with '%s' directive: %s." + % (self.name, ErrorString(exc))) + return unicode(out) + + def nestedParse(self, lines, fname): + content = ViewList() + node = nodes.section() + + if "debug" in self.options: + code_block = "\n\n.. code-block:: rst\n :linenos:\n" + for l in lines.split("\n"): + code_block += "\n " + l + lines = code_block + "\n\n" + + for c, l in enumerate(lines.split("\n")): + content.append(l, fname, c) + + 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) + try: + 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