From nobody Wed Dec 17 03:15:19 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 D9EFB1CC89D; Mon, 10 Feb 2025 10:18:24 +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=1739182704; cv=none; b=TvH2BfRCD9mIg+2wzg18yjj8L9rjjTNzIlWdbJoXLkOv+oUPGMA6wGG35pm8gNlJffqn/KOmx0Rt/mUKL9TsvCwWq0LoyeDUaW/cZWg4B6oINV0RYqkDRdY+HNK73s9bSJ7jSskeJa82VNfSUaTAZAthnhGipaLD4LLB3srLUL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739182704; c=relaxed/simple; bh=bfKfMaG0D1WbSBuzEfJe/4GnAC91X+Ok5ClCL/aAjU0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EeoiBykLLA/SveLcbmUKgmM90ISTwAsbnp4wuM6ze1deiTyR9VAvzStfGN0tpPLHCj88tVhe96y47izKQQCxpC2wcUui/VKdwjH+w805VOYY4VN3wvht1FfVfJ5eDvAQZiG/3EdtzN40HApkLXV4P5ptLayg+EuJAbKXOnfa+fo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gFb6k2Rq; 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="gFb6k2Rq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 239F6C4CED1; Mon, 10 Feb 2025 10:18:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739182704; bh=bfKfMaG0D1WbSBuzEfJe/4GnAC91X+Ok5ClCL/aAjU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gFb6k2Rqcz7UnLmVJH59Cly+ky8GaUG/RbvfnUykDVKMowdtyASr67XsRCoA0q0e2 bMStNL3LLwyHPjI0HZBAHkLeXdJsX0RAQT/nhf3Bjm3zfq29s/DgqcLI6vI1E1JnnQ 3YrEyg18Z6XQ1M1J5ieiYo2hHEAQXM4OiB0tOSddVZeCc0cda6KFuLVuL91d1pDYCf Oc59PuylGd4Y97426E+2WCMfQxlCXGFNGwfDjH41xGo54RWb6rBqPyDvBV8rVjvTLn vQPse6LMjp3jId5jfhzG1CJWL8xs/vHgwuvDpkluxm1RUF5RhTD16KMTENiYq+0maT CxtPy6U3vMBDA== Received: from mchehab by mail.kernel.org with local (Exim 4.98) (envelope-from ) id 1thQru-00000006CjA-1CQh; Mon, 10 Feb 2025 11:18:22 +0100 From: Mauro Carvalho Chehab To: Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Jonathan Corbet" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH 16/27] docs: sphinx/kernel_abi: reduce buffer usage for ABI messages Date: Mon, 10 Feb 2025 11:18:05 +0100 Message-ID: <15be22955e3c6df49d7256c8fd24f62b397ad0ff.1739182025.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" Instead of producing a big message with all ABI contents and then parse as a whole, simplify the code by handling each ABI symbol in separate. As an additional benefit, there's no need to place file/line nubers inlined at the data and use a regex to convert them. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/kernel_abi.py | 76 +++++++++++++++--------------- scripts/get_abi.py | 7 ++- scripts/lib/abi/abi_parser.py | 10 ++-- 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/Documentation/sphinx/kernel_abi.py b/Documentation/sphinx/kern= el_abi.py index f7b22abebcf4..742ebd35454f 100644 --- a/Documentation/sphinx/kernel_abi.py +++ b/Documentation/sphinx/kernel_abi.py @@ -68,6 +68,7 @@ class KernelCmd(Directive): 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, @@ -79,59 +80,60 @@ class KernelCmd(Directive): raise self.warning("docutils: file insertion disabled") =20 path =3D os.path.join(srctree, "Documentation", self.arguments[0]) - parser =3D AbiParser(path, logger=3Dself.logger) - parser.parse_abi() - parser.check_issues() + self.parser =3D AbiParser(path, logger=3Dself.logger) + self.parser.parse_abi() + self.parser.check_issues() =20 - msg =3D "" - for m in parser.doc(enable_lineno=3DTrue, show_file=3DTrue): - msg +=3D m - - node =3D self.nested_parse(msg, self.arguments[0]) + node =3D self.nested_parse(None, self.arguments[0]) return node =20 - def nested_parse(self, lines, fname): + def nested_parse(self, data, fname): env =3D self.state.document.settings.env content =3D ViewList() node =3D nodes.section() =20 - if "debug" in self.options: - code_block =3D "\n\n.. code-block:: rst\n :linenos:\n" - for line in lines.split("\n"): - code_block +=3D "\n " + line - lines =3D code_block + "\n\n" + if data is not None: + # Handles the .rst file + for line in data.split("\n"): + content.append(line, fname, 0) =20 - line_regex =3D re.compile(r"^\.\. LINENO (\S+)\#([0-9]+)$") - ln =3D 0 - n =3D 0 - f =3D fname + self.do_parse(content, node) =20 - for line in lines.split("\n"): - n =3D n + 1 - match =3D line_regex.search(line) - if match: - new_f =3D match.group(1) + else: + # Handles the ABI parser content, symbol by symbol =20 - # 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 !=3D f and content: - self.do_parse(content, node) - content =3D ViewList() + old_f =3D fname + n =3D 0 + for msg, f, ln in self.parser.doc(): + msg_list =3D msg.split("\n") + if "debug" in self.options: + lines =3D [ + "", "", ".. code-block:: rst", + " :linenos:", "" + ] + for m in msg_list: + lines.append(" " + m) + else: + lines =3D msg_list =20 + 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)) =20 - f =3D new_f + old_f =3D f =20 - # sphinx counts lines from 0 - ln =3D int(match.group(2)) - 1 - else: - content.append(line, f, ln) + # 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() =20 - self.logger.info("%s: parsed %i lines" % (fname, n)) - - if content: - self.do_parse(content, node) + self.logger.info("%s: parsed %i lines" % (fname, n)) =20 return node.children =20 diff --git a/scripts/get_abi.py b/scripts/get_abi.py index 93b973bc07ed..19f78d6aa407 100755 --- a/scripts/get_abi.py +++ b/scripts/get_abi.py @@ -63,8 +63,11 @@ class AbiRest: parser.parse_abi() parser.check_issues() =20 - for msg in parser.doc(args.enable_lineno, args.raw, not args.no_fi= le): - print(msg) + for t in parser.doc(args.raw, not args.no_file): + if args.enable_lineno: + print (f".. LINENO {t[1]}#{t[2]}\n\n") + + print(t[0]) =20 class AbiValidate: """Initialize an argparse subparser for ABI validation""" diff --git a/scripts/lib/abi/abi_parser.py b/scripts/lib/abi/abi_parser.py index 57c125fd40a5..1db6c54fc65a 100644 --- a/scripts/lib/abi/abi_parser.py +++ b/scripts/lib/abi/abi_parser.py @@ -427,7 +427,7 @@ class AbiParser: =20 return new_desc + "\n\n" =20 - def doc(self, enable_lineno, output_in_txt=3DFalse, show_file=3DFalse): + def doc(self, output_in_txt=3DFalse, show_file=3DTrue): """Print ABI at stdout""" =20 part =3D None @@ -444,10 +444,6 @@ class AbiParser: =20 msg =3D "" =20 - if enable_lineno: - ln =3D v.get("line_no", 1) - msg +=3D f".. LINENO {file_ref[0][0]}#{ln}\n\n" - if wtype !=3D "File": cur_part =3D names[0] if cur_part.find("/") >=3D 0: @@ -508,7 +504,9 @@ class AbiParser: if users and users.strip(" \t\n"): msg +=3D f"Users:\n\t{users.strip("\n").replace('\n', '\n\= t')}\n\n" =20 - yield msg + ln =3D v.get("line_no", 1) + + yield (msg, file_ref[0][0], ln) =20 def check_issues(self): """Warn about duplicated ABI entries""" --=20 2.48.1