From nobody Thu Dec 18 10:37:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C53D273F9; Tue, 28 Jan 2025 00:06:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738022797; cv=none; b=YstaKXCEQCOFaN3sUeIqTrsuOGleDyyGJz/pUG+PMkWnkCLR7bQmNEwZHMXAKUyhlgm5HgcgBlYUkhDDot8q6z84MUmjJzBIIs3vLrDEE6qd6O5A4Ury0CWp7dARtuoPqZ49eCicAYvqK1N6ioQWj2l8TZ4s+ZUktWqnY4zpJes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738022797; c=relaxed/simple; bh=1eS0ENZhyS5NgGwt57b7o8bqQ+da8byhs9yHPVKsnog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kIZJ5s/L0VVTZgaSS8tkloxGn9+0DD9rkfCmd6pJKNkIAGDC9dm5HiB3HJnoQcJxTWeDESi8s6yupmvIBbwWLe9k5RmQgzxXfA9NSSAewERyzYL8OtTLkNFACKJP584xM+Wl7gDcf2egdkt+/XhifpXn1X91F6VS5SFRBykoqt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=plexcGaF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="plexcGaF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2E21C4CEFD; Tue, 28 Jan 2025 00:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738022796; bh=1eS0ENZhyS5NgGwt57b7o8bqQ+da8byhs9yHPVKsnog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=plexcGaFVSwfy7BhB/x//HcKHsPg94lIY0HZOOKZoYCMt99hwQVqQ3H703OKcL9QM k9eyIEjIgpkwGg4boxn4rQYCMrbqoOYxx3Y48TncY5DnQ/YNbgY7OLsevjg0int4WZ RhJjuameSzxtJlfokKKe4HG7+sPjJT88bWk/mHMj4Vsf4BGfWldgDUuUTft+krqOVV XZ3pgkUsufiH8sQVVy0stWeSx66rsAVVzCLlhwmByk007W712NWtk8tRxVO694E+lt mJaRFIHlJ4piukHEmnvgc8haQlADs3lBKlgcdUxkJGsMTRXmdtGQYHaGD5CmzW/ctQ jTdRw7qQCs9UQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98) (envelope-from ) id 1tcZ7i-0000000DRLr-0m6X; Tue, 28 Jan 2025 01:06:34 +0100 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet , Greg Kroah-Hartman Cc: Mauro Carvalho Chehab , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [RFC v2 23/38] docs: sphinx/kernel_abi: parse ABI files only once Date: Tue, 28 Jan 2025 01:06:12 +0100 Message-ID: <52b1fc2f56d6a2eee0d8da2ec08e133de8207402.1738020236.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" Right now, the logic parses ABI files on 4 steps, one for each directory. While this is fine in principle, by doing that, not all symbol cross-references will be created. Change the logic to do the parsing only once in order to get a global dictionary to be used when creating ABI cross-references. Signed-off-by: Mauro Carvalho Chehab --- Documentation/admin-guide/abi-obsolete.rst | 2 +- Documentation/admin-guide/abi-removed.rst | 2 +- Documentation/admin-guide/abi-stable.rst | 2 +- Documentation/admin-guide/abi-testing.rst | 2 +- Documentation/sphinx/kernel_abi.py | 115 ++++++++++++--------- scripts/get_abi.py | 22 ++-- 6 files changed, 81 insertions(+), 64 deletions(-) diff --git a/Documentation/admin-guide/abi-obsolete.rst b/Documentation/adm= in-guide/abi-obsolete.rst index 6d4d9ab7b8c3..bdef91d2cea4 100644 --- a/Documentation/admin-guide/abi-obsolete.rst +++ b/Documentation/admin-guide/abi-obsolete.rst @@ -9,4 +9,4 @@ marked to be removed at some later point in time. The description of the interface will document the reason why it is obsolete and when it can be expected to be removed. =20 -.. kernel-abi:: ABI/obsolete +.. kernel-abi:: obsolete diff --git a/Documentation/admin-guide/abi-removed.rst b/Documentation/admi= n-guide/abi-removed.rst index 9fc78af6f077..bea0608b8442 100644 --- a/Documentation/admin-guide/abi-removed.rst +++ b/Documentation/admin-guide/abi-removed.rst @@ -3,4 +3,4 @@ ABI removed symbols =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -.. kernel-abi:: ABI/removed +.. kernel-abi:: removed diff --git a/Documentation/admin-guide/abi-stable.rst b/Documentation/admin= -guide/abi-stable.rst index c47c2a295865..33637c0d4fd5 100644 --- a/Documentation/admin-guide/abi-stable.rst +++ b/Documentation/admin-guide/abi-stable.rst @@ -12,4 +12,4 @@ for at least 2 years. Most interfaces (like syscalls) are expected to never change and always be available. =20 -.. kernel-abi:: ABI/stable +.. kernel-abi:: stable diff --git a/Documentation/admin-guide/abi-testing.rst b/Documentation/admi= n-guide/abi-testing.rst index 40b31985e587..55054985a8ff 100644 --- a/Documentation/admin-guide/abi-testing.rst +++ b/Documentation/admin-guide/abi-testing.rst @@ -18,4 +18,4 @@ Programs that use these interfaces are strongly encourage= d to add their name to the description of these interfaces, so that the kernel developers can easily notify them if any changes occur. =20 -.. kernel-abi:: ABI/testing +.. kernel-abi:: testing diff --git a/Documentation/sphinx/kernel_abi.py b/Documentation/sphinx/kern= el_abi.py index 2408ba7a3981..6d1b34e44d46 100644 --- a/Documentation/sphinx/kernel_abi.py +++ b/Documentation/sphinx/kernel_abi.py @@ -49,6 +49,13 @@ from get_abi import AbiParser =20 __version__ =3D "1.0" =20 +logger =3D logging.getLogger('kernel_abi') +path =3D os.path.join(srctree, "Documentation/ABI") + +# Parse ABI symbols only once +kernel_abi =3D AbiParser(path, logger=3Dlogger) +kernel_abi.parse_abi() +kernel_abi.check_issues() =20 def setup(app): =20 @@ -64,14 +71,15 @@ class KernelCmd(Directive): u"""KernelABI (``kernel-abi``) directive""" =20 required_arguments =3D 1 - optional_arguments =3D 2 + optional_arguments =3D 3 has_content =3D False final_argument_whitespace =3D True - logger =3D logging.getLogger('kernel_abi') parser =3D None =20 option_spec =3D { "debug": directives.flag, + "no-symbols": directives.flag, + "no-files": directives.flag, } =20 def run(self): @@ -79,62 +87,67 @@ class KernelCmd(Directive): if not doc.settings.file_insertion_enabled: raise self.warning("docutils: file insertion disabled") =20 - path =3D os.path.join(srctree, "Documentation", self.arguments[0]) - self.parser =3D AbiParser(path, logger=3Dself.logger) - self.parser.parse_abi() - self.parser.check_issues() - - node =3D self.nested_parse(None, self.arguments[0]) - return node - - def nested_parse(self, data, fname): env =3D self.state.document.settings.env content =3D ViewList() node =3D nodes.section() =20 - if data is not None: - # Handles the .rst file - for line in data.split("\n"): - content.append(line, fname, 0) + abi_type =3D self.arguments[0] =20 - self.do_parse(content, node) + if "no-symbols" in self.options: + show_symbols =3D False + else: + show_symbols =3D True =20 + if "no-files" in self.options: + show_file =3D False + else: + show_file =3D True + + tab_width =3D self.options.get('tab-width', + self.state.document.settings.tab_widt= h) + + old_f =3D None + n =3D 0 + n_sym =3D 0 + for msg, f, ln in kernel_abi.doc(show_file=3Dshow_file, + show_symbols=3Dshow_symbols, + filter_path=3Dabi_type): + n_sym +=3D 1 + msg_list =3D statemachine.string2lines(msg, tab_width, + convert_whitespace=3DTrue) + if "debug" in self.options: + lines =3D [ + "", "", ".. code-block:: rst", + " :linenos:", "" + ] + for m in msg_list: + lines.append(" " + m) + else: + lines =3D msg_list + + for line in lines: + # sphinx counts lines from 0 + content.append(line, f, ln - 1) + n +=3D 1 + + if f !=3D old_f: + # Add the file to Sphinx build dependencies + env.note_dependency(os.path.abspath(f)) + + old_f =3D f + + # Sphinx doesn't like to parse big messages. So, let's + # add content symbol by symbol + if content: + self.do_parse(content, node) + content =3D ViewList() + + if show_symbols and not show_file: + logger.verbose("%s ABI: %i symbols (%i ReST lines)" % (abi_typ= e, n_sym, n)) + elif not show_symbols and show_file: + logger.verbose("%s ABI: %i files (%i ReST lines)" % (abi_type,= n_sym, n)) else: - # Handles the ABI parser content, symbol by symbol - - old_f =3D fname - n =3D 0 - for msg, f, ln in self.parser.doc(): - msg_list =3D statemachine.string2lines(msg, tab_width, - convert_whitespace=3D= True) - if "debug" in self.options: - lines =3D [ - "", "", ".. code-block:: rst", - " :linenos:", "" - ] - for m in msg_list: - lines.append(" " + m) - else: - lines =3D msg_list - - for line in lines: - # sphinx counts lines from 0 - content.append(line, f, ln - 1) - n +=3D 1 - - if f !=3D old_f: - # Add the file to Sphinx build dependencies - env.note_dependency(os.path.abspath(f)) - - old_f =3D f - - # Sphinx doesn't like to parse big messages. So, let's - # add content symbol by symbol - if content: - self.do_parse(content, node) - content =3D ViewList() - - self.logger.info("%s: parsed %i lines" % (fname, n)) + logger.verbose("%s ABI: %i data (%i ReST lines)" % (abi_type, = n_sym, n)) =20 return node.children =20 diff --git a/scripts/get_abi.py b/scripts/get_abi.py index 3cde278b8e4c..7435ed1071b8 100755 --- a/scripts/get_abi.py +++ b/scripts/get_abi.py @@ -279,12 +279,20 @@ class AbiParser: def parse_readme(self, nametag, fname): """Parse ABI README file""" =20 + nametag["what"] =3D ["ABI file contents"] + nametag["path"] =3D "README" with open(fname, "r", encoding=3D"utf8", errors=3D"backslashreplac= e") as fp: - nametag["description"] =3D "```\n" for line in fp: - nametag["description"] +=3D " " + line + match =3D self.re_tag.match(line) + if match: + new =3D match.group(1).lower() =20 - nametag["description"] +=3D "```\n" + match =3D self.re_valid.search(new) + if match: + nametag["description"] +=3D "\n:" + line + continue + + nametag["description"] +=3D line =20 def parse_file(self, fname, path, basename): """Parse a single file""" @@ -473,12 +481,8 @@ class AbiParser: continue =20 if filter_path: - if filter_path =3D=3D "README": - if not names[0].endswith("README"): - continue - else: - if v.get("path") !=3D filter_path: - continue + if v.get("path") !=3D filter_path: + continue =20 msg =3D "" =20 --=20 2.48.1