From nobody Thu Oct 2 11:48:27 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 E67453233E0; Wed, 17 Sep 2025 12:15:55 +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=1758111356; cv=none; b=TF0qTqpTscJ5h3J5rRQde1o/sGke7NloQDFj77QzNXF1euR/65FSjKDTZTjvJ8bZkqOsHImXG8ontsT50vvy14WrYO8vUkdRlvmwSDHWJBYp9Nse8LpsOLRmj4bAerojQjuX6huiTYuD6dA28WzSwqhzQE2RGCNMsV3SPQ/fW6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111356; c=relaxed/simple; bh=AiE/HI6OagdGD9ZL2nK8qpA5ue5A1dovU9+3kLCIiqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jyr9z5Fy8TaE2jx4whSOGV8kfO55Zo0QGwvnwwn2FAmRwK+Vts+HXgNux3/c2H6hgBbKYgqg+hvdHlHC0HLYp3MSpMO7M2J2qCnGq0lzNIH9P5P1Ic0wz3Va+FoYIgCf9ehVokIlw2cH1+o0MS3pxsrdRMYKg6SyvuJnvymr0sI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KKWNkpTO; 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="KKWNkpTO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D5F8C16AAE; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=AiE/HI6OagdGD9ZL2nK8qpA5ue5A1dovU9+3kLCIiqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KKWNkpTOyWNkvfM+6FxuOUCKB9KTSn6beElyv5jX/TMgCN7oMudEE17FONO9eNqPZ 5w1ebEq2F9ZTJUt7L4j7nEik7EdM1CgQYiw0jbeVOcCAVCgknIMByb167gNF46wJRr lArFAIAzWiSU2+ze0ZcE16N5pi1djvZWXVOl/4XZ1u0zJEPaHr9BBNz6xhDWHpfpc/ D4uFEsMTifovnkUbncW/zXQ+3AYMERU3hi9vIDaeC2GDW8RPCZpoJ6wDJR8vxtvr5E reoinLaPDmHJmT+O2aWOPCvwHrcV8BSo+y3HpoqupYz0xM/RyceoE9E3+gfgbJwBYr jDjcT1C4r3CMg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdE-0G1l; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 01/24] scripts/jobserver-exec: move the code to a class Date: Wed, 17 Sep 2025 14:14:55 +0200 Message-ID: <79700002248605fa9ad45ade0165e67b04d457b0.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" Convert the code inside jobserver-exec to a class and properly document it. Using a class allows reusing the jobserver logic on other scripts. While the main code remains unchanged, being compatible with Python 2.6 and 3.0+, its coding style now follows a more modern standard, having tabs replaced by a 4-spaces indent, passing autopep8, black and pylint. The code now allows allows using a pythonic way to enter/exit a python code, e.g. it now supports: with JobserverExec() as jobserver: jobserver.run(sys.argv[1:]) With the new code, the __exit__() function should ensure that the jobserver slot will be closed at the end, even if something bad happens somewhere. Signed-off-by: Mauro Carvalho Chehab --- scripts/jobserver-exec | 218 ++++++++++++++++++++++++++++------------- 1 file changed, 151 insertions(+), 67 deletions(-) diff --git a/scripts/jobserver-exec b/scripts/jobserver-exec index 7eca035472d3..b386b1a845de 100755 --- a/scripts/jobserver-exec +++ b/scripts/jobserver-exec @@ -1,77 +1,161 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0+ # +# pylint: disable=3DC0103,C0209 +# # This determines how many parallel tasks "make" is expecting, as it is # not exposed via an special variables, reserves them all, runs a subproce= ss # with PARALLELISM environment variable set, and releases the jobs back ag= ain. # # https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html#= POSIX-Jobserver -from __future__ import print_function -import os, sys, errno + +""" +Interacts with the POSIX jobserver during the Kernel build time. + +A "normal" jobserver task, like the one initiated by a make subrocess woul= d do: + + - open read/write file descriptors to communicate with the job server; + - ask for one slot by calling: + claim =3D os.read(reader, 1) + - when the job finshes, call: + os.write(writer, b"+") # os.write(writer, claim) + +Here, the goal is different: This script aims to get the remaining number +of slots available, using all of them to run a command which handle tasks = in +parallel. To to that, it has a loop that ends only after there are no +slots left. It then increments the number by one, in order to allow a +call equivalent to make -j$((claim+1)), e.g. having a parent make creating +$claim child to do the actual work. + +The end goal here is to keep the total number of build tasks under the +limit established by the initial make -j$n_proc call. +""" + +import errno +import os import subprocess +import sys =20 -# Extract and prepare jobserver file descriptors from environment. -claim =3D 0 -jobs =3D b"" -try: - # Fetch the make environment options. - flags =3D os.environ['MAKEFLAGS'] - - # Look for "--jobserver=3DR,W" - # Note that GNU Make has used --jobserver-fds and --jobserver-auth - # so this handles all of them. - opts =3D [x for x in flags.split(" ") if x.startswith("--jobserver")] - - # Parse out R,W file descriptor numbers and set them nonblocking. - # If the MAKEFLAGS variable contains multiple instances of the - # --jobserver-auth=3D option, the last one is relevant. - fds =3D opts[-1].split("=3D", 1)[1] - - # Starting with GNU Make 4.4, named pipes are used for reader and writer. - # Example argument: --jobserver-auth=3Dfifo:/tmp/GMfifo8134 - _, _, path =3D fds.partition('fifo:') - - if path: - reader =3D os.open(path, os.O_RDONLY | os.O_NONBLOCK) - writer =3D os.open(path, os.O_WRONLY) - else: - reader, writer =3D [int(x) for x in fds.split(",", 1)] - # Open a private copy of reader to avoid setting nonblocking - # on an unexpecting process with the same reader fd. - reader =3D os.open("/proc/self/fd/%d" % (reader), - os.O_RDONLY | os.O_NONBLOCK) - - # Read out as many jobserver slots as possible. - while True: - try: - slot =3D os.read(reader, 8) - jobs +=3D slot - except (OSError, IOError) as e: - if e.errno =3D=3D errno.EWOULDBLOCK: - # Stop at the end of the jobserver queue. - break - # If something went wrong, give back the jobs. - if len(jobs): - os.write(writer, jobs) - raise e - # Add a bump for our caller's reserveration, since we're just going - # to sit here blocked on our child. - claim =3D len(jobs) + 1 -except (KeyError, IndexError, ValueError, OSError, IOError) as e: - # Any missing environment strings or bad fds should result in just - # not being parallel. - pass - -# We can only claim parallelism if there was a jobserver (i.e. a top-level -# "-jN" argument) and there were no other failures. Otherwise leave out the -# environment variable and let the child figure out what is best. -if claim > 0: - os.environ['PARALLELISM'] =3D '%d' % (claim) - -rc =3D subprocess.call(sys.argv[1:]) - -# Return all the reserved slots. -if len(jobs): - os.write(writer, jobs) - -sys.exit(rc) + +class JobserverExec: + """ + Claim all slots from make using POSIX Jobserver. + + The main methods here are: + - open(): reserves all slots; + - close(): method returns all used slots back to make; + - run(): executes a command setting PARALLELISM=3D + """ + + def __init__(self): + """Initialize internal vars""" + self.claim =3D 0 + self.jobs =3D b"" + self.reader =3D None + self.writer =3D None + self.is_open =3D False + + def open(self): + """Reserve all available slots to be claimed later on""" + + if self.is_open: + return + + try: + # Fetch the make environment options. + flags =3D os.environ["MAKEFLAGS"] + # Look for "--jobserver=3DR,W" + # Note that GNU Make has used --jobserver-fds and --jobserver-= auth + # so this handles all of them. + opts =3D [x for x in flags.split(" ") if x.startswith("--jobse= rver")] + + # Parse out R,W file descriptor numbers and set them nonblocki= ng. + # If the MAKEFLAGS variable contains multiple instances of the + # --jobserver-auth=3D option, the last one is relevant. + fds =3D opts[-1].split("=3D", 1)[1] + + # Starting with GNU Make 4.4, named pipes are used for reader + # and writer. + # Example argument: --jobserver-auth=3Dfifo:/tmp/GMfifo8134 + _, _, path =3D fds.partition("fifo:") + + if path: + self.reader =3D os.open(path, os.O_RDONLY | os.O_NONBLOCK) + self.writer =3D os.open(path, os.O_WRONLY) + else: + self.reader, self.writer =3D [int(x) for x in fds.split(",= ", 1)] + # Open a private copy of reader to avoid setting nonblocki= ng + # on an unexpecting process with the same reader fd. + self.reader =3D os.open("/proc/self/fd/%d" % (self.reader), + os.O_RDONLY | os.O_NONBLOCK) + + # Read out as many jobserver slots as possible + while True: + try: + slot =3D os.read(self.reader, 8) + self.jobs +=3D slot + except (OSError, IOError) as e: + if e.errno =3D=3D errno.EWOULDBLOCK: + # Stop at the end of the jobserver queue. + break + # If something went wrong, give back the jobs. + if self.jobs: + os.write(self.writer, self.jobs) + raise e + + # Add a bump for our caller's reserveration, since we're just = going + # to sit here blocked on our child. + self.claim =3D len(self.jobs) + 1 + + except (KeyError, IndexError, ValueError, OSError, IOError): + # Any missing environment strings or bad fds should result in = just + # not being parallel. + self.claim =3D None + + self.is_open =3D True + + def close(self): + """Return all reserved slots to Jobserver""" + + if not self.is_open: + return + + # Return all the reserved slots. + if len(self.jobs): + os.write(self.writer, self.jobs) + + self.is_open =3D False + + def __enter__(self): + self.open() + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + self.close() + + def run(self, cmd): + """ + Run a command setting PARALLELISM env variable to the number of + available job slots (claim) + 1, e.g. it will reserve claim slots + to do the actual build work, plus one to monitor its childs. + """ + self.open() # Ensure that self.claim is set + + # We can only claim parallelism if there was a jobserver (i.e. a + # top-level "-jN" argument) and there were no other failures. Othe= rwise + # leave out the environment variable and let the child figure out = what + # is best. + if self.claim: + os.environ["PARALLELISM"] =3D str(self.claim) + + return subprocess.call(cmd) + + +def main(): + """Main program""" + with JobserverExec() as jobserver: + jobserver.run(sys.argv[1:]) + + +if __name__ =3D=3D "__main__": + main() --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 7F485323418; Wed, 17 Sep 2025 12:15:56 +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=1758111356; cv=none; b=GFZ84fdr/C8DnCmkppbxBClLIkIHQTRdA+AfLnJrpOFSUq2bpWiLhCne4hDXt6OhXTh7ldLJ9tvICqv81LuoFSw50VJfZmkO/oewKbhiyiy03xpdRAI03IyKIyQpdkfqBVm/cyUSCSZMjOfoi7TL76Ld2RFNzlPfTezDarwLOHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111356; c=relaxed/simple; bh=RnTLGaGUuMOKF6PxxwxnFcuRL48slw9WnQakpfhYXJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QZWv9NBTYybOOSkUIz2DxVUiPHbiT+zZQ5Pwwea8wg6e663us+tliAWilvg+HMWfhqk1wQa/5Wv1FXSsv07JM9mRX0mVe3x8pebr4GC/g1Xv1POywFc0oO1WGvZI02mIRJvLqefXNburHhmwspc9c+PfWDliFH0hsZy5J/6Vbk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UbRPRP5P; 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="UbRPRP5P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD274C113D0; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111356; bh=RnTLGaGUuMOKF6PxxwxnFcuRL48slw9WnQakpfhYXJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UbRPRP5P4qxcO69Ju+PuhxQHoWZ3DW0fuOtxRFrn995IFqbWmE+7dXzmfKerHQmLl 9WWZhGwaSmXwzqSOiL5xY4hJZOrWpvh1ktqdPOh1eYj9N865xDkUUUGlKjLGTGFiBj R9uyNizH7MKj9y4zoP59hP1N0rZkNdgyjGy+UnwXm22Yal1TX6Uq/B6k43SFUOj71m 0JyACGIQfFEMCgOJOGQ2nBl5epP9T0XGa4BNgVUY/Be7e5zLDucTJB1hfnwSoGeD8f VraiiAN+3wvaSRxEs/+s47WQecRiYddrDiCbYE12GC5Xg6O5HCjMRD+fvvJ7VlnrYR mQ8+T4F0kj/cw== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdI-0N12; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 02/24] scripts/jobserver-exec: move its class to the lib directory Date: Wed, 17 Sep 2025 14:14:56 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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" To make it easier to be re-used, move the JobserverExec class to the library directory. Signed-off-by: Mauro Carvalho Chehab --- scripts/jobserver-exec | 152 +++------------------------------------ scripts/lib/jobserver.py | 149 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 141 deletions(-) create mode 100755 scripts/lib/jobserver.py diff --git a/scripts/jobserver-exec b/scripts/jobserver-exec index b386b1a845de..40a0f0058733 100755 --- a/scripts/jobserver-exec +++ b/scripts/jobserver-exec @@ -1,155 +1,25 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0+ -# -# pylint: disable=3DC0103,C0209 -# -# This determines how many parallel tasks "make" is expecting, as it is -# not exposed via an special variables, reserves them all, runs a subproce= ss -# with PARALLELISM environment variable set, and releases the jobs back ag= ain. -# -# https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html#= POSIX-Jobserver =20 -""" -Interacts with the POSIX jobserver during the Kernel build time. - -A "normal" jobserver task, like the one initiated by a make subrocess woul= d do: - - - open read/write file descriptors to communicate with the job server; - - ask for one slot by calling: - claim =3D os.read(reader, 1) - - when the job finshes, call: - os.write(writer, b"+") # os.write(writer, claim) - -Here, the goal is different: This script aims to get the remaining number -of slots available, using all of them to run a command which handle tasks = in -parallel. To to that, it has a loop that ends only after there are no -slots left. It then increments the number by one, in order to allow a -call equivalent to make -j$((claim+1)), e.g. having a parent make creating -$claim child to do the actual work. - -The end goal here is to keep the total number of build tasks under the -limit established by the initial make -j$n_proc call. -""" - -import errno import os -import subprocess import sys =20 +LIB_DIR =3D "lib" +SRC_DIR =3D os.path.dirname(os.path.realpath(__file__)) =20 -class JobserverExec: - """ - Claim all slots from make using POSIX Jobserver. +sys.path.insert(0, os.path.join(SRC_DIR, LIB_DIR)) =20 - The main methods here are: - - open(): reserves all slots; - - close(): method returns all used slots back to make; - - run(): executes a command setting PARALLELISM=3D - """ +from jobserver import JobserverExec # pylint: disable=3DC= 0415 =20 - def __init__(self): - """Initialize internal vars""" - self.claim =3D 0 - self.jobs =3D b"" - self.reader =3D None - self.writer =3D None - self.is_open =3D False =20 - def open(self): - """Reserve all available slots to be claimed later on""" - - if self.is_open: - return - - try: - # Fetch the make environment options. - flags =3D os.environ["MAKEFLAGS"] - # Look for "--jobserver=3DR,W" - # Note that GNU Make has used --jobserver-fds and --jobserver-= auth - # so this handles all of them. - opts =3D [x for x in flags.split(" ") if x.startswith("--jobse= rver")] - - # Parse out R,W file descriptor numbers and set them nonblocki= ng. - # If the MAKEFLAGS variable contains multiple instances of the - # --jobserver-auth=3D option, the last one is relevant. - fds =3D opts[-1].split("=3D", 1)[1] - - # Starting with GNU Make 4.4, named pipes are used for reader - # and writer. - # Example argument: --jobserver-auth=3Dfifo:/tmp/GMfifo8134 - _, _, path =3D fds.partition("fifo:") - - if path: - self.reader =3D os.open(path, os.O_RDONLY | os.O_NONBLOCK) - self.writer =3D os.open(path, os.O_WRONLY) - else: - self.reader, self.writer =3D [int(x) for x in fds.split(",= ", 1)] - # Open a private copy of reader to avoid setting nonblocki= ng - # on an unexpecting process with the same reader fd. - self.reader =3D os.open("/proc/self/fd/%d" % (self.reader), - os.O_RDONLY | os.O_NONBLOCK) - - # Read out as many jobserver slots as possible - while True: - try: - slot =3D os.read(self.reader, 8) - self.jobs +=3D slot - except (OSError, IOError) as e: - if e.errno =3D=3D errno.EWOULDBLOCK: - # Stop at the end of the jobserver queue. - break - # If something went wrong, give back the jobs. - if self.jobs: - os.write(self.writer, self.jobs) - raise e - - # Add a bump for our caller's reserveration, since we're just = going - # to sit here blocked on our child. - self.claim =3D len(self.jobs) + 1 - - except (KeyError, IndexError, ValueError, OSError, IOError): - # Any missing environment strings or bad fds should result in = just - # not being parallel. - self.claim =3D None - - self.is_open =3D True - - def close(self): - """Return all reserved slots to Jobserver""" - - if not self.is_open: - return - - # Return all the reserved slots. - if len(self.jobs): - os.write(self.writer, self.jobs) - - self.is_open =3D False - - def __enter__(self): - self.open() - return self - - def __exit__(self, exc_type, exc_value, exc_traceback): - self.close() - - def run(self, cmd): - """ - Run a command setting PARALLELISM env variable to the number of - available job slots (claim) + 1, e.g. it will reserve claim slots - to do the actual build work, plus one to monitor its childs. - """ - self.open() # Ensure that self.claim is set - - # We can only claim parallelism if there was a jobserver (i.e. a - # top-level "-jN" argument) and there were no other failures. Othe= rwise - # leave out the environment variable and let the child figure out = what - # is best. - if self.claim: - os.environ["PARALLELISM"] =3D str(self.claim) - - return subprocess.call(cmd) +""" +Determines how many parallel tasks "make" is expecting, as it is +not exposed via an special variables, reserves them all, runs a subprocess +with PARALLELISM environment variable set, and releases the jobs back agai= n. =20 +See: + https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.htm= l#POSIX-Jobserver +""" =20 def main(): """Main program""" diff --git a/scripts/lib/jobserver.py b/scripts/lib/jobserver.py new file mode 100755 index 000000000000..98d8b0ff0c89 --- /dev/null +++ b/scripts/lib/jobserver.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0+ +# +# pylint: disable=3DC0103,C0209 +# +# + +""" +Interacts with the POSIX jobserver during the Kernel build time. + +A "normal" jobserver task, like the one initiated by a make subrocess woul= d do: + + - open read/write file descriptors to communicate with the job server; + - ask for one slot by calling: + claim =3D os.read(reader, 1) + - when the job finshes, call: + os.write(writer, b"+") # os.write(writer, claim) + +Here, the goal is different: This script aims to get the remaining number +of slots available, using all of them to run a command which handle tasks = in +parallel. To to that, it has a loop that ends only after there are no +slots left. It then increments the number by one, in order to allow a +call equivalent to make -j$((claim+1)), e.g. having a parent make creating +$claim child to do the actual work. + +The end goal here is to keep the total number of build tasks under the +limit established by the initial make -j$n_proc call. + +See: + https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.htm= l#POSIX-Jobserver +""" + +import errno +import os +import subprocess +import sys + +class JobserverExec: + """ + Claim all slots from make using POSIX Jobserver. + + The main methods here are: + - open(): reserves all slots; + - close(): method returns all used slots back to make; + - run(): executes a command setting PARALLELISM=3D + """ + + def __init__(self): + """Initialize internal vars""" + self.claim =3D 0 + self.jobs =3D b"" + self.reader =3D None + self.writer =3D None + self.is_open =3D False + + def open(self): + """Reserve all available slots to be claimed later on""" + + if self.is_open: + return + + try: + # Fetch the make environment options. + flags =3D os.environ["MAKEFLAGS"] + # Look for "--jobserver=3DR,W" + # Note that GNU Make has used --jobserver-fds and --jobserver-= auth + # so this handles all of them. + opts =3D [x for x in flags.split(" ") if x.startswith("--jobse= rver")] + + # Parse out R,W file descriptor numbers and set them nonblocki= ng. + # If the MAKEFLAGS variable contains multiple instances of the + # --jobserver-auth=3D option, the last one is relevant. + fds =3D opts[-1].split("=3D", 1)[1] + + # Starting with GNU Make 4.4, named pipes are used for reader + # and writer. + # Example argument: --jobserver-auth=3Dfifo:/tmp/GMfifo8134 + _, _, path =3D fds.partition("fifo:") + + if path: + self.reader =3D os.open(path, os.O_RDONLY | os.O_NONBLOCK) + self.writer =3D os.open(path, os.O_WRONLY) + else: + self.reader, self.writer =3D [int(x) for x in fds.split(",= ", 1)] + # Open a private copy of reader to avoid setting nonblocki= ng + # on an unexpecting process with the same reader fd. + self.reader =3D os.open("/proc/self/fd/%d" % (self.reader), + os.O_RDONLY | os.O_NONBLOCK) + + # Read out as many jobserver slots as possible + while True: + try: + slot =3D os.read(self.reader, 8) + self.jobs +=3D slot + except (OSError, IOError) as e: + if e.errno =3D=3D errno.EWOULDBLOCK: + # Stop at the end of the jobserver queue. + break + # If something went wrong, give back the jobs. + if self.jobs: + os.write(self.writer, self.jobs) + raise e + + # Add a bump for our caller's reserveration, since we're just = going + # to sit here blocked on our child. + self.claim =3D len(self.jobs) + 1 + + except (KeyError, IndexError, ValueError, OSError, IOError): + # Any missing environment strings or bad fds should result in = just + # not being parallel. + self.claim =3D None + + self.is_open =3D True + + def close(self): + """Return all reserved slots to Jobserver""" + + if not self.is_open: + return + + # Return all the reserved slots. + if len(self.jobs): + os.write(self.writer, self.jobs) + + self.is_open =3D False + + def __enter__(self): + self.open() + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + self.close() + + def run(self, cmd, *args, **pwargs): + """ + Run a command setting PARALLELISM env variable to the number of + available job slots (claim) + 1, e.g. it will reserve claim slots + to do the actual build work, plus one to monitor its childs. + """ + self.open() # Ensure that self.claim is set + + # We can only claim parallelism if there was a jobserver (i.e. a + # top-level "-jN" argument) and there were no other failures. Othe= rwise + # leave out the environment variable and let the child figure out = what + # is best. + if self.claim: + os.environ["PARALLELISM"] =3D str(self.claim) + + return subprocess.call(cmd, *args, **pwargs) --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 E3BE031BCBC; Wed, 17 Sep 2025 12:15:55 +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=1758111356; cv=none; b=DfEvyGdfQwW17NgK94bDvAhhUvz/SWytEm0ABBYe2tfvI6ew0anCFfwD1IeEa5pt6ujlO3hkaYE2llK2mEEZvfNWCWJeTxUNCjHPjsK/tK9oxypfUXc+95vsoHotcYAkEuE9s6fRpswkpaW/y5oGrDEId6r7c6L4VEQYKY81GIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111356; c=relaxed/simple; bh=jlol1TuhVNcZDXlNqsLBvYWROc27W0iXgTQpgdIUTbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AGuqbGtGe6PQBpFK2SwFW3+aGmDCBfbWUOHjRWBHfUZ50aJPzkEWqBYMZRdCsoivnk0yfLFV3vE5JozHzh7l06IEp6f3UmfdlqCjPVOOOXfVF21R0YsfDYQS2Kg7jNXxrZakQXciBZwVkkYmd5rcpPugUr5yaNTlQnSw+nFKZfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eO1nP3vg; 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="eO1nP3vg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E87BC4CEFA; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=jlol1TuhVNcZDXlNqsLBvYWROc27W0iXgTQpgdIUTbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eO1nP3vgZcBN0PFJ1WsBVBVikAoR58lAtSZf05IqGO+LxsUA/yV8CxVE5f2VM38wF t88aW82Q7xc+55m++oeYNi7oy4FLYP7W/kaaH0b8ijREQSNgCKq2hTIA7ru5Me+4fc P3FQumb2iuem4VLcx1srENMrE4fyzQKbwGOUNoADtJaR5bjQs55PvRC0lonAOod2LY fAo16jXql7ndhmr9zSEmDW7PQXLbPrm+R8GXZ1VPnR69QQa9T/2bze283miY29uoUs 6DlH60ItBAN4vvGVb/dMez1OFmUt7IAbBPPgmsxb1TUJluQp8PurTR37QXndZ72wkP m7Hyp7nYrWmpA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdM-0Tq4; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 03/24] scripts/jobserver-exec: add a help message Date: Wed, 17 Sep 2025 14:14:57 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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" Currently, calling it without an argument shows an ugly error message. Instead, print a message using pythondoc as description. Signed-off-by: Mauro Carvalho Chehab --- scripts/jobserver-exec | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/jobserver-exec b/scripts/jobserver-exec index 40a0f0058733..ae23afd344ec 100755 --- a/scripts/jobserver-exec +++ b/scripts/jobserver-exec @@ -1,6 +1,15 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0+ =20 +""" +Determines how many parallel tasks "make" is expecting, as it is +not exposed via any special variables, reserves them all, runs a subprocess +with PARALLELISM environment variable set, and releases the jobs back agai= n. + +See: + https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.htm= l#POSIX-Jobserver +""" + import os import sys =20 @@ -12,17 +21,12 @@ sys.path.insert(0, os.path.join(SRC_DIR, LIB_DIR)) from jobserver import JobserverExec # pylint: disable=3DC= 0415 =20 =20 -""" -Determines how many parallel tasks "make" is expecting, as it is -not exposed via an special variables, reserves them all, runs a subprocess -with PARALLELISM environment variable set, and releases the jobs back agai= n. - -See: - https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.htm= l#POSIX-Jobserver -""" - def main(): """Main program""" + if len(sys.argv) < 2: + name =3D os.path.basename(__file__) + sys.exit("usage: " + name +" command [args ...]\n" + __doc__) + with JobserverExec() as jobserver: jobserver.run(sys.argv[1:]) =20 --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 58DA0334CD3; Wed, 17 Sep 2025 12:16:02 +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=1758111363; cv=none; b=dymNeMn6ALd4yQtmjSP3meIrNGQUslmmQdSzZ8K3g4t0Ln6KNho2GcMCeJeIlmNWtGc73kE9KWvSxG6C+Wi4YZiPKsbVnt3inefNa7O9EyQH3dBOJxHrA9Yj2maK1PaMaxCkjWWGwAlVEGQwbi/5plu9a/RKDI73rQJ1it9u+OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111363; c=relaxed/simple; bh=2lAZ64n7wyH76UFbNF5vqE4iJt8/QZ2U45Bxr8ZIkP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UKK7EHjT0cCvb87UIF/erAs8lhTOK4KxZC2Vd7rTJ6l2eRB/qbI2fw5LoTVjBN52WUt6VEmjBPXrN7+1Q4X4qwS1LdwBMby0GFEkO9z+aD9wpzmUy/c3aAzia6SBmVLVSct2Di9GjaLr92hHP6ROyS13BEJc56/hS+rVrVX0pa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cX1c/wht; 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="cX1c/wht" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC563C4CEF0; Wed, 17 Sep 2025 12:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111361; bh=2lAZ64n7wyH76UFbNF5vqE4iJt8/QZ2U45Bxr8ZIkP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cX1c/whtUh0tqFNSiZEgU0+iXz1XQ0YfduYvVcuS0TYM9ADz3Z4CkBzpFIu6qIe4G 74gBV9m5aMge/3FI8NM4fZH19DOC2yBo+SIj94wZaVDxzIIMicMUQHmDzZmwAdBBNL rhN7OY+AMvqLM8Df276Qpen450W63uNayTJbkW2I8LjQU+guLO/qQ6qazYsFd2yhxQ AxBc9vulqO5xvmwro92teOorEOx6ezoY9MOx5v+n3Y0qbcQtUSkhQte+tj5EeMkdkj QLY3D0YsumkFp352nz3XWc9dXsOvAq90ZwX0VSseUBHsLxjbI+oLjx/wVQj42TFCym HOp5ZFPQrIOLQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdQ-0aiz; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 04/24] scripts: check-variable-fonts.sh: convert to Python Date: Wed, 17 Sep 2025 14:14:58 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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" This script handle errors when trying to build translations with make pdfdocs. As part of our cleanup work to remove hacks from docs Makefile, convert this to python, preparing it to be part of a library to be called by sphinx-build-wrapper. Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 2 +- MAINTAINERS | 2 +- ...iable-fonts.sh =3D> check-variable-fonts.py} | 104 +++++++++++++----- 3 files changed, 79 insertions(+), 29 deletions(-) rename scripts/{check-variable-fonts.sh =3D> check-variable-fonts.py} (61%) diff --git a/Documentation/Makefile b/Documentation/Makefile index 5c20c68be89a..d5e436435eab 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -146,7 +146,7 @@ pdfdocs: DENY_VF =3D XDG_CONFIG_HOME=3D$(FONTS_CONF_DEN= Y_VF) pdfdocs: latexdocs @$(srctree)/scripts/sphinx-pre-install --version-check $(foreach var,$(SPHINXDIRS), \ - $(MAKE) PDFLATEX=3D"$(PDFLATEX)" LATEXOPTS=3D"$(LATEXOPTS)" $(DENY_VF)= -C $(BUILDDIR)/$(var)/latex || sh $(srctree)/scripts/check-variable-fonts.= sh || exit; \ + $(MAKE) PDFLATEX=3D"$(PDFLATEX)" LATEXOPTS=3D"$(LATEXOPTS)" $(DENY_VF)= -C $(BUILDDIR)/$(var)/latex || $(PYTHON3) $(srctree)/scripts/check-variabl= e-fonts.py || exit; \ mkdir -p $(BUILDDIR)/$(var)/pdf; \ mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUI= LDDIR)/$(var)/pdf/; \ ) diff --git a/MAINTAINERS b/MAINTAINERS index ef87548b8f88..88d8f7435e6d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7301,7 +7301,7 @@ S: Maintained P: Documentation/doc-guide/maintainer-profile.rst T: git git://git.lwn.net/linux.git docs-next F: Documentation/ -F: scripts/check-variable-fonts.sh +F: scripts/check-variable-fonts.py F: scripts/checktransupdate.py F: scripts/documentation-file-ref-check F: scripts/get_abi.py diff --git a/scripts/check-variable-fonts.sh b/scripts/check-variable-fonts= .py similarity index 61% rename from scripts/check-variable-fonts.sh rename to scripts/check-variable-fonts.py index ce63f0acea5f..71b88b680a73 100755 --- a/scripts/check-variable-fonts.sh +++ b/scripts/check-variable-fonts.py @@ -1,7 +1,9 @@ -#!/bin/sh +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only # Copyright (C) Akira Yokosawa, 2024 # +# Ported to Python by (c) Mauro Carvalho Chehab, 2025 +# # For "make pdfdocs", reports of build errors of translations.pdf started # arriving early 2024 [1, 2]. It turned out that Fedora and openSUSE # tumbleweed have started deploying variable-font [3] format of "Noto CJK" @@ -87,29 +89,77 @@ # Denylisting should be less invasive, as it is effective only while # XeLaTeX runs in "make pdfdocs". =20 -# Default per-user fontconfig path (overridden by env variable) -: ${FONTS_CONF_DENY_VF:=3D$HOME/deny-vf} - -export XDG_CONFIG_HOME=3D${FONTS_CONF_DENY_VF} - -notocjkvffonts=3D`fc-list : file family variable | \ - grep 'variable=3DTrue' | \ - grep -E -e 'Noto (Sans|Sans Mono|Serif) CJK' | \ - sed -e 's/^/ /' -e 's/: Noto S.*$//' | sort | uniq` - -if [ "x$notocjkvffonts" !=3D "x" ] ; then - echo '=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D' - echo 'XeTeX is confused by "variable font" files listed below:' - echo "$notocjkvffonts" - echo - echo 'For CJK pages in PDF, they need to be hidden from XeTeX by denylist= ing.' - echo 'Or, CJK pages can be skipped by uninstalling texlive-xecjk.' - echo - echo 'For more info on denylisting, other options, and variable font, see= header' - echo 'comments of scripts/check-variable-fonts.sh.' - echo '=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D' -fi - -# As this script is invoked from Makefile's error path, always error exit -# regardless of whether any variable font is discovered or not. -exit 1 +import os +import re +import subprocess +import sys +import textwrap + +class LatexFontChecker: + """ + Detect problems with CJK variable fonts that affect PDF builds for + translations. + """ + + def __init__(self): + deny_vf =3D os.environ.get('FONTS_CONF_DENY_VF', "~/deny-vf") + + self.environ =3D os.environ.copy() + self.environ['XDG_CONFIG_HOMEF'] =3D os.path.expanduser(deny_vf) + + self.re_cjk =3D re.compile(r"([^:]+):\s*Noto\s+(Sans|Sans Mono|Ser= if) CJK") + + def get_noto_cjk_vf_fonts(self): + """Get Noto CJK fonts""" + + cjk_fonts =3D set() + cmd =3D ["fc-list", ":", "file", "family", "variable"] + try: + result =3D subprocess.run(cmd,stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.PIPE, + universal_newlines=3DTrue, + env=3Dself.environ, + check=3DTrue) + + except subprocess.CalledProcessError as exc: + sys.exit(f"Error running fc-list: {repr(exc)}") + + for line in result.stdout.splitlines(): + if 'variable=3DTrue' not in line: + continue + + match =3D self.re_cjk.search(line) + if match: + cjk_fonts.add(match.group(1)) + + return sorted(cjk_fonts) + + def check(self): + """Check for problems with CJK fonts""" + + fonts =3D textwrap.indent("\n".join(self.get_noto_cjk_vf_fonts()),= " ") + if not fonts: + return None + + rel_file =3D os.path.relpath(__file__, os.getcwd()) + + msg =3D "=3D" * 77 + "\n" + msg +=3D 'XeTeX is confused by "variable font" files listed below:= \n' + msg +=3D fonts + "\n" + msg +=3D textwrap.dedent(f""" + For CJK pages in PDF, they need to be hidden from XeTeX by= denylisting. + Or, CJK pages can be skipped by uninstalling texlive-xecjk. + + For more info on denylisting, other options, and variable = font, see header + comments of {rel_file}. + """) + msg +=3D "=3D" * 77 + + return msg + +if __name__ =3D=3D "__main__": + msg =3D LatexFontChecker().check() + if msg: + print(msg) + + sys.exit(1) --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 A8D9734F481; Wed, 17 Sep 2025 12:15:56 +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=1758111356; cv=none; b=d/3/zRPra3CSdO+8OOEzotw1/QGx3lTZAASf+Wlm698K9oWxlYRBunQGCjV46+/NnDRh/CbkFXtsbqJnHIu2qYU/dPOu7xEtJh+v5W3FPlVkB9XP1uAkIq8XQ/oCpVmBwgKxGOOIn7QxJ+FnsxJXkfRDuXs66WCkkrhopKziN1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111356; c=relaxed/simple; bh=NmlkZhJdqEVCzp/MdJNPQBv63GpQxSHusELMOU7NpKE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S2dMlJtv+vyTc6hOORBrT1X9tIX5V2xoyJZr0p45vO9wab7Ie0CvejLEFCrO6W5giTtI/mAHmJwdvgth1+wbxMC3vQrLTihUkazzb/CubbBdTc72hcP8mCwnKcHi62hAH650XlwpMrAOTJj/Ofj2yGoWjb116NhhrrHAV+8u8og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sjA5RzFs; 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="sjA5RzFs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 273CDC4CEF7; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111356; bh=NmlkZhJdqEVCzp/MdJNPQBv63GpQxSHusELMOU7NpKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sjA5RzFs1V+vTse9leKlB/Bpcp3V/o6sqjut72HxLh29RQLP6u8DHhyjestFLi7J0 I1LItvcLhWovvBuFtNyLQQmlIYsZoctCmq+C16Dl047Yt53HqOO799HhmVmxgMIsA2 Aj4IDEzVmGGguoksUuLKKBfnvJChuoSP/pTqB2mFT/2LNADDEbEVz2Ls+wTkXEjpFv pzejf/Hhp5FK9Zf4aRbBby0ASd47Dhp8JblMehaGBcbj9snPwEvfINLXrLPngMof0F VRqqjVF89lA4UP23RzW/eAI7DbuS+c1SvYW61K+SB4BKopyD6uOS/C47lPPkV3Z+4a 8q2hOIexb5wtg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdU-0hxP; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 05/24] tools/docs: check-variable-fonts.py: split into a lib and an exec file Date: Wed, 17 Sep 2025 14:14:59 +0200 Message-ID: <1905cdc59d36213c6e0ab8c5e2a3b02250e8053f.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" As we'll be using the actual code inside sphinx-build-wrapper, split the library from the executable, placing the exec at the new place we've been using: tools/docs No functional changes. Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 2 +- MAINTAINERS | 1 - scripts/check-variable-fonts.py | 165 ----------------------------- tools/docs/check-variable-fonts.py | 23 ++++ tools/docs/lib/latex_fonts.py | 162 ++++++++++++++++++++++++++++ 5 files changed, 186 insertions(+), 167 deletions(-) delete mode 100755 scripts/check-variable-fonts.py create mode 100755 tools/docs/check-variable-fonts.py create mode 100755 tools/docs/lib/latex_fonts.py diff --git a/Documentation/Makefile b/Documentation/Makefile index d5e436435eab..6e11d0593742 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -146,7 +146,7 @@ pdfdocs: DENY_VF =3D XDG_CONFIG_HOME=3D$(FONTS_CONF_DEN= Y_VF) pdfdocs: latexdocs @$(srctree)/scripts/sphinx-pre-install --version-check $(foreach var,$(SPHINXDIRS), \ - $(MAKE) PDFLATEX=3D"$(PDFLATEX)" LATEXOPTS=3D"$(LATEXOPTS)" $(DENY_VF)= -C $(BUILDDIR)/$(var)/latex || $(PYTHON3) $(srctree)/scripts/check-variabl= e-fonts.py || exit; \ + $(MAKE) PDFLATEX=3D"$(PDFLATEX)" LATEXOPTS=3D"$(LATEXOPTS)" $(DENY_VF)= -C $(BUILDDIR)/$(var)/latex || $(PYTHON3) $(srctree)/tools/docs/check-vari= able-fonts.py || exit; \ mkdir -p $(BUILDDIR)/$(var)/pdf; \ mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUI= LDDIR)/$(var)/pdf/; \ ) diff --git a/MAINTAINERS b/MAINTAINERS index 88d8f7435e6d..76dd823bfcc4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7301,7 +7301,6 @@ S: Maintained P: Documentation/doc-guide/maintainer-profile.rst T: git git://git.lwn.net/linux.git docs-next F: Documentation/ -F: scripts/check-variable-fonts.py F: scripts/checktransupdate.py F: scripts/documentation-file-ref-check F: scripts/get_abi.py diff --git a/scripts/check-variable-fonts.py b/scripts/check-variable-fonts= .py deleted file mode 100755 index 71b88b680a73..000000000000 --- a/scripts/check-variable-fonts.py +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0-only -# Copyright (C) Akira Yokosawa, 2024 -# -# Ported to Python by (c) Mauro Carvalho Chehab, 2025 -# -# For "make pdfdocs", reports of build errors of translations.pdf started -# arriving early 2024 [1, 2]. It turned out that Fedora and openSUSE -# tumbleweed have started deploying variable-font [3] format of "Noto CJK" -# fonts [4, 5]. For PDF, a LaTeX package named xeCJK is used for CJK -# (Chinese, Japanese, Korean) pages. xeCJK requires XeLaTeX/XeTeX, which -# does not (and likely never will) understand variable fonts for historical -# reasons. -# -# The build error happens even when both of variable- and non-variable-for= mat -# fonts are found on the build system. To make matters worse, Fedora enli= sts -# variable "Noto CJK" fonts in the requirements of langpacks-ja, -ko, -zh_= CN, -# -zh_TW, etc. Hence developers who have interest in CJK pages are more -# likely to encounter the build errors. -# -# This script is invoked from the error path of "make pdfdocs" and emits -# suggestions if variable-font files of "Noto CJK" fonts are in the list of -# fonts accessible from XeTeX. -# -# References: -# [1]: https://lore.kernel.org/r/8734tqsrt7.fsf@meer.lwn.net/ -# [2]: https://lore.kernel.org/r/1708585803.600323099@f111.i.mail.ru/ -# [3]: https://en.wikipedia.org/wiki/Variable_font -# [4]: https://fedoraproject.org/wiki/Changes/Noto_CJK_Variable_Fonts -# [5]: https://build.opensuse.org/request/show/1157217 -# -#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D -# Workarounds for building translations.pdf -#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D -# -# * Denylist "variable font" Noto CJK fonts. -# - Create $HOME/deny-vf/fontconfig/fonts.conf from template below, with -# tweaks if necessary. Remove leading "# ". -# - Path of fontconfig/fonts.conf can be overridden by setting an env -# variable FONTS_CONF_DENY_VF. -# -# * Template: -# ----------------------------------------------------------------- -# -# -# -# -# -# -# -# /usr/share/fonts/google-noto-*-cjk-vf-fonts -# -# /usr/share/fonts/truetype/Noto*CJK*-VF.otf -# -# -# -# ----------------------------------------------------------------- -# -# The denylisting is activated for "make pdfdocs". -# -# * For skipping CJK pages in PDF -# - Uninstall texlive-xecjk. -# Denylisting is not needed in this case. -# -# * For printing CJK pages in PDF -# - Need non-variable "Noto CJK" fonts. -# * Fedora -# - google-noto-sans-cjk-fonts -# - google-noto-serif-cjk-fonts -# * openSUSE tumbleweed -# - Non-variable "Noto CJK" fonts are not available as distro packag= es -# as of April, 2024. Fetch a set of font files from upstream Noto -# CJK Font released at: -# https://github.com/notofonts/noto-cjk/tree/main/Sans#super-otc -# and at: -# https://github.com/notofonts/noto-cjk/tree/main/Serif#super-otc -# , then uncompress and deploy them. -# - Remember to update fontconfig cache by running fc-cache. -# -# !!! Caution !!! -# Uninstalling "variable font" packages can be dangerous. -# They might be depended upon by other packages important for your wor= k. -# Denylisting should be less invasive, as it is effective only while -# XeLaTeX runs in "make pdfdocs". - -import os -import re -import subprocess -import sys -import textwrap - -class LatexFontChecker: - """ - Detect problems with CJK variable fonts that affect PDF builds for - translations. - """ - - def __init__(self): - deny_vf =3D os.environ.get('FONTS_CONF_DENY_VF', "~/deny-vf") - - self.environ =3D os.environ.copy() - self.environ['XDG_CONFIG_HOMEF'] =3D os.path.expanduser(deny_vf) - - self.re_cjk =3D re.compile(r"([^:]+):\s*Noto\s+(Sans|Sans Mono|Ser= if) CJK") - - def get_noto_cjk_vf_fonts(self): - """Get Noto CJK fonts""" - - cjk_fonts =3D set() - cmd =3D ["fc-list", ":", "file", "family", "variable"] - try: - result =3D subprocess.run(cmd,stdout=3Dsubprocess.PIPE, - stderr=3Dsubprocess.PIPE, - universal_newlines=3DTrue, - env=3Dself.environ, - check=3DTrue) - - except subprocess.CalledProcessError as exc: - sys.exit(f"Error running fc-list: {repr(exc)}") - - for line in result.stdout.splitlines(): - if 'variable=3DTrue' not in line: - continue - - match =3D self.re_cjk.search(line) - if match: - cjk_fonts.add(match.group(1)) - - return sorted(cjk_fonts) - - def check(self): - """Check for problems with CJK fonts""" - - fonts =3D textwrap.indent("\n".join(self.get_noto_cjk_vf_fonts()),= " ") - if not fonts: - return None - - rel_file =3D os.path.relpath(__file__, os.getcwd()) - - msg =3D "=3D" * 77 + "\n" - msg +=3D 'XeTeX is confused by "variable font" files listed below:= \n' - msg +=3D fonts + "\n" - msg +=3D textwrap.dedent(f""" - For CJK pages in PDF, they need to be hidden from XeTeX by= denylisting. - Or, CJK pages can be skipped by uninstalling texlive-xecjk. - - For more info on denylisting, other options, and variable = font, see header - comments of {rel_file}. - """) - msg +=3D "=3D" * 77 - - return msg - -if __name__ =3D=3D "__main__": - msg =3D LatexFontChecker().check() - if msg: - print(msg) - - sys.exit(1) diff --git a/tools/docs/check-variable-fonts.py b/tools/docs/check-variable= -fonts.py new file mode 100755 index 000000000000..79b28f0f7d85 --- /dev/null +++ b/tools/docs/check-variable-fonts.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) Akira Yokosawa, 2024 +# +# Ported to Python by (c) Mauro Carvalho Chehab, 2025 +# +# pylint: disable=3DC0103 + +""" +Detect problematic Noto CJK variable fonts. + +or more details, see lib/latex_fonts.py. +""" + +import sys + +from lib.latex_fonts import LatexFontChecker + +msg =3D LatexFontChecker().check() +if msg: + print(msg) + +sys.exit(1) diff --git a/tools/docs/lib/latex_fonts.py b/tools/docs/lib/latex_fonts.py new file mode 100755 index 000000000000..e03412e3947e --- /dev/null +++ b/tools/docs/lib/latex_fonts.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) Akira Yokosawa, 2024 +# +# Ported to Python by (c) Mauro Carvalho Chehab, 2025 + +""" +Detect problematic Noto CJK variable fonts. + +For "make pdfdocs", reports of build errors of translations.pdf started +arriving early 2024 [1, 2]. It turned out that Fedora and openSUSE +tumbleweed have started deploying variable-font [3] format of "Noto CJK" +fonts [4, 5]. For PDF, a LaTeX package named xeCJK is used for CJK +(Chinese, Japanese, Korean) pages. xeCJK requires XeLaTeX/XeTeX, which +does not (and likely never will) understand variable fonts for historical +reasons. + +The build error happens even when both of variable- and non-variable-format +fonts are found on the build system. To make matters worse, Fedora enlists +variable "Noto CJK" fonts in the requirements of langpacks-ja, -ko, -zh_CN, +-zh_TW, etc. Hence developers who have interest in CJK pages are more +likely to encounter the build errors. + +This script is invoked from the error path of "make pdfdocs" and emits +suggestions if variable-font files of "Noto CJK" fonts are in the list of +fonts accessible from XeTeX. + +References: +[1]: https://lore.kernel.org/r/8734tqsrt7.fsf@meer.lwn.net/ +[2]: https://lore.kernel.org/r/1708585803.600323099@f111.i.mail.ru/ +[3]: https://en.wikipedia.org/wiki/Variable_font +[4]: https://fedoraproject.org/wiki/Changes/Noto_CJK_Variable_Fonts +[5]: https://build.opensuse.org/request/show/1157217 + +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D +Workarounds for building translations.pdf +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +* Denylist "variable font" Noto CJK fonts. + - Create $HOME/deny-vf/fontconfig/fonts.conf from template below, with + tweaks if necessary. Remove leading "". + - Path of fontconfig/fonts.conf can be overridden by setting an env + variable FONTS_CONF_DENY_VF. + + * Template: +----------------------------------------------------------------- + + + + + + + + /usr/share/fonts/google-noto-*-cjk-vf-fonts + + /usr/share/fonts/truetype/Noto*CJK*-VF.otf + + + +----------------------------------------------------------------- + + The denylisting is activated for "make pdfdocs". + +* For skipping CJK pages in PDF + - Uninstall texlive-xecjk. + Denylisting is not needed in this case. + +* For printing CJK pages in PDF + - Need non-variable "Noto CJK" fonts. + * Fedora + - google-noto-sans-cjk-fonts + - google-noto-serif-cjk-fonts + * openSUSE tumbleweed + - Non-variable "Noto CJK" fonts are not available as distro packages + as of April, 2024. Fetch a set of font files from upstream Noto + CJK Font released at: + https://github.com/notofonts/noto-cjk/tree/main/Sans#super-otc + and at: + https://github.com/notofonts/noto-cjk/tree/main/Serif#super-otc + , then uncompress and deploy them. + - Remember to update fontconfig cache by running fc-cache. + +!!! Caution !!! + Uninstalling "variable font" packages can be dangerous. + They might be depended upon by other packages important for your work. + Denylisting should be less invasive, as it is effective only while + XeLaTeX runs in "make pdfdocs". +""" + +import os +import re +import subprocess +import textwrap +import sys + +class LatexFontChecker: + """ + Detect problems with CJK variable fonts that affect PDF builds for + translations. + """ + + def __init__(self): + deny_vf =3D os.environ.get('FONTS_CONF_DENY_VF', "~/deny-vf") + + self.environ =3D os.environ.copy() + self.environ['XDG_CONFIG_HOMEF'] =3D os.path.expanduser(deny_vf) + + self.re_cjk =3D re.compile(r"([^:]+):\s*Noto\s+(Sans|Sans Mono|Ser= if) CJK") + + def get_noto_cjk_vf_fonts(self): + """Get Noto CJK fonts""" + + cjk_fonts =3D set() + cmd =3D ["fc-list", ":", "file", "family", "variable"] + try: + result =3D subprocess.run(cmd,stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.PIPE, + universal_newlines=3DTrue, + env=3Dself.environ, + check=3DTrue) + + except subprocess.CalledProcessError as exc: + sys.exit(f"Error running fc-list: {repr(exc)}") + + for line in result.stdout.splitlines(): + if 'variable=3DTrue' not in line: + continue + + match =3D self.re_cjk.search(line) + if match: + cjk_fonts.add(match.group(1)) + + return sorted(cjk_fonts) + + def check(self): + """Check for problems with CJK fonts""" + + fonts =3D textwrap.indent("\n".join(self.get_noto_cjk_vf_fonts()),= " ") + if not fonts: + return None + + rel_file =3D os.path.relpath(__file__, os.getcwd()) + + msg =3D "=3D" * 77 + "\n" + msg +=3D 'XeTeX is confused by "variable font" files listed below:= \n' + msg +=3D fonts + "\n" + msg +=3D textwrap.dedent(f""" + For CJK pages in PDF, they need to be hidden from XeTeX by= denylisting. + Or, CJK pages can be skipped by uninstalling texlive-xecjk. + + For more info on denylisting, other options, and variable = font, see header + comments of {rel_file}. + """) + msg +=3D "=3D" * 77 + + return msg --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 3AD2F3728B6; Wed, 17 Sep 2025 12:16:05 +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=1758111366; cv=none; b=TyNdT0louXDpvCPGRIrLlkzjVoxQ4Dz98c3YnnThihkXLyrOX0jQHqqoghaAwt9IYkde5XJJAbendzAbkAOFm0p12tEcso3rAwQd2o21/POEZ+Op5oWpI/XNbOyL/sU4Kxmqm6daw7QDt22CeiD1agz0nhsQtbnYdIigjCS9qWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111366; c=relaxed/simple; bh=A/mf0CcSEJehu2LuWr/6DS5gyCiq40ED/oENXVKsyyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hPhqCjbRO/XsY6SQmoA5Om/DcaOQi1UcJC89fnV9+XStPQhzxXdCPyW+PoxROSyBHWaKuKXq1GPePWYa592CEGoD9/h6EVsFrjD5rwwhURMRwfRrHYKnG+D3UGyKWcB9CRqIgwdqVcbLz3OWd/8MILOktCMY45ldXHqQYJEifvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pX5OBAUP; 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="pX5OBAUP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2998C4CEF7; Wed, 17 Sep 2025 12:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111365; bh=A/mf0CcSEJehu2LuWr/6DS5gyCiq40ED/oENXVKsyyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pX5OBAUPlIkX5kaDxF1ugGX2UqYv04/liVXoIYRCjCya45IS43F20lZ3JljqXq4in DjaaO4dgSKVnauKWctItiPHSbJloFfwkwdc3PbTzcDjSwjlAsUw5tsnemGIUvQZybT ulVgD0394hbwlysJAdWIgWpkPtlMLdjLyPz0fbhFK8w0ZggPYIcUZIImSIjAtRqd1m KyPeYdBAalAOSvNoLpCQwDWdpbbmxoPxUWTrlZ+CFUduEIIamgWNqhqN/09Iqp1z5a W1BnHE7saKCRaUcDqfCrGO+UFcgpPFXdr9DJCC5fcYQ5VsjuRxC4uMmmuqYPn3gKzi bFzV5Kq0ziF7A== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdY-0ogy; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 06/24] check-variable-fonts.py: add a helper to display instructions Date: Wed, 17 Sep 2025 14:15:00 +0200 Message-ID: <32f8ebfaf2062dda9c23ac9744b66e782ea989eb.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" Use lib docstring to output the comments via --help/-h. With that, update the default instructions to recomment it instead of asking the user to read the source code. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/check-variable-fonts.py | 7 +++++++ tools/docs/lib/latex_fonts.py | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/docs/check-variable-fonts.py b/tools/docs/check-variable= -fonts.py index 79b28f0f7d85..ae274e7fbbb7 100755 --- a/tools/docs/check-variable-fonts.py +++ b/tools/docs/check-variable-fonts.py @@ -12,10 +12,17 @@ Detect problematic Noto CJK variable fonts. or more details, see lib/latex_fonts.py. """ =20 +import argparse import sys =20 from lib.latex_fonts import LatexFontChecker =20 +checker =3D LatexFontChecker() + +parser=3Dargparse.ArgumentParser(description=3Dchecker.description(), + formatter_class=3Dargparse.RawTextHelpForma= tter) +_=3Dparser.parse_args() + msg =3D LatexFontChecker().check() if msg: print(msg) diff --git a/tools/docs/lib/latex_fonts.py b/tools/docs/lib/latex_fonts.py index e03412e3947e..0a3ad4995e79 100755 --- a/tools/docs/lib/latex_fonts.py +++ b/tools/docs/lib/latex_fonts.py @@ -113,6 +113,9 @@ class LatexFontChecker: =20 self.re_cjk =3D re.compile(r"([^:]+):\s*Noto\s+(Sans|Sans Mono|Ser= if) CJK") =20 + def description(self): + return __doc__ + def get_noto_cjk_vf_fonts(self): """Get Noto CJK fonts""" =20 @@ -154,8 +157,9 @@ class LatexFontChecker: For CJK pages in PDF, they need to be hidden from XeTeX by= denylisting. Or, CJK pages can be skipped by uninstalling texlive-xecjk. =20 - For more info on denylisting, other options, and variable = font, see header - comments of {rel_file}. + For more info on denylisting, other options, and variable = font, run: + + tools/docs/check-variable-fonts.py -h """) msg +=3D "=3D" * 77 =20 --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 DD4E830CB47; Wed, 17 Sep 2025 12:15:54 +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=1758111355; cv=none; b=JOVa3nwm73g7VPEOcfEGVM8NI6/JhY2/Yiz2lOu3A429JUEfW0Yif59RBB7NgIOOWCvkS0GrO0VABMZG2BKSZB7ZMLyKcScNwGadxPxu3uUU7BjXolwoEDCEecXYaOHoN+kQ8IMVxRDvr4qGxfCX9oMecqGH8rI8+E14ioOaCpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=tyTIqAnvcS4UX09dEZuAJBcwACv9raN6toXoVwiSVjI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jBdGNJTM880oAPcrmRfTTx8OQn5/I/TEt0VsCSaGpNkumF3evSdJmSwMbYImLubjHFHiGt5KryEOYko78oIO7uq0HYkpfjarNECeYBkB+ot3dnqvx/X5wmJl1hvIjr07Wmvn8XvydTTAAxl4cY97V8qoAdMB6jPefuQUJ93szrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=InbIIX79; 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="InbIIX79" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1808EC4CEFA; Wed, 17 Sep 2025 12:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111354; bh=tyTIqAnvcS4UX09dEZuAJBcwACv9raN6toXoVwiSVjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=InbIIX79JHQqEnZMGS+mHyktei9bFHW7pileQVUpInJSxfuliD+8CFSQLuDHz4ZNc EigA04A6RKyiGaCMA1oWWBuWqsaI/7Hfgbm9/oRandI6Djy0XoKniYgPOkNFEYYBFA XvEG/b2duRTqeibJ6JPyacPTx//xYIziUEwlrGmWKwyk9ehrsLPt8MwaTT6XcsLdL6 ZELeAG/gZcUdMTm2eOmSf8L/rYfOTg82eSkyus5sEwJMuhAFJVBJ0QCVj7mmiryw8N krsA15H1TmVS8+M/Y7ayibsYvvJJjtl+IHa0/CWml6DeY6RLV9XICHXFIjAz3BwAnY of1i30BKQVU3w== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdc-0vkp; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , Alex Shi , Dongliang Mu , Federico Vaga , Randy Dunlap , Yanteng Si , linux-kernel@vger.kernel.org Subject: [PATCH v7 07/24] scripts: sphinx-pre-install: move it to tools/docs Date: Wed, 17 Sep 2025 14:15:01 +0200 Message-ID: <3069b4cdc1cfdc8dfafe2998c4a69235203b855d.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab As we're reorganizing the place where doc scripts are located, move this one to tools/docs. No functional changes. Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 14 +++++++------- Documentation/doc-guide/sphinx.rst | 4 ++-- Documentation/sphinx/kerneldoc-preamble.sty | 2 +- .../translations/it_IT/doc-guide/sphinx.rst | 4 ++-- .../translations/zh_CN/doc-guide/sphinx.rst | 4 ++-- Documentation/translations/zh_CN/how-to.rst | 2 +- MAINTAINERS | 3 +-- {scripts =3D> tools/docs}/sphinx-pre-install | 0 8 files changed, 16 insertions(+), 17 deletions(-) rename {scripts =3D> tools/docs}/sphinx-pre-install (100%) diff --git a/Documentation/Makefile b/Documentation/Makefile index 6e11d0593742..fd6399c79fab 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -46,7 +46,7 @@ ifeq ($(HAVE_SPHINX),0) .DEFAULT: $(warning The '$(SPHINXBUILD)' command was not found. Make sure you have = Sphinx installed and in PATH, or set the SPHINXBUILD make variable to point= to the full path of the '$(SPHINXBUILD)' executable.) @echo - @$(srctree)/scripts/sphinx-pre-install + @$(srctree)/tools/docs/sphinx-pre-install @echo " SKIP Sphinx $@ target." =20 else # HAVE_SPHINX @@ -105,7 +105,7 @@ quiet_cmd_sphinx =3D SPHINX $@ --> file://$(abspath $(= BUILDDIR)/$3/$4) fi =20 htmldocs: - @$(srctree)/scripts/sphinx-pre-install --version-check + @$(srctree)/tools/docs/sphinx-pre-install --version-check @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var))) =20 # If Rust support is available and .config exists, add rustdoc generated c= ontents. @@ -119,7 +119,7 @@ endif endif =20 texinfodocs: - @$(srctree)/scripts/sphinx-pre-install --version-check + @$(srctree)/tools/docs/sphinx-pre-install --version-check @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,texinfo,$(var),texin= fo,$(var))) =20 # Note: the 'info' Make target is generated by sphinx itself when @@ -131,7 +131,7 @@ linkcheckdocs: @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(v= ar))) =20 latexdocs: - @$(srctree)/scripts/sphinx-pre-install --version-check + @$(srctree)/tools/docs/sphinx-pre-install --version-check @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$= (var))) =20 ifeq ($(HAVE_PDFLATEX),0) @@ -144,7 +144,7 @@ else # HAVE_PDFLATEX =20 pdfdocs: DENY_VF =3D XDG_CONFIG_HOME=3D$(FONTS_CONF_DENY_VF) pdfdocs: latexdocs - @$(srctree)/scripts/sphinx-pre-install --version-check + @$(srctree)/tools/docs/sphinx-pre-install --version-check $(foreach var,$(SPHINXDIRS), \ $(MAKE) PDFLATEX=3D"$(PDFLATEX)" LATEXOPTS=3D"$(LATEXOPTS)" $(DENY_VF)= -C $(BUILDDIR)/$(var)/latex || $(PYTHON3) $(srctree)/tools/docs/check-vari= able-fonts.py || exit; \ mkdir -p $(BUILDDIR)/$(var)/pdf; \ @@ -154,11 +154,11 @@ pdfdocs: latexdocs endif # HAVE_PDFLATEX =20 epubdocs: - @$(srctree)/scripts/sphinx-pre-install --version-check + @$(srctree)/tools/docs/sphinx-pre-install --version-check @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(v= ar))) =20 xmldocs: - @$(srctree)/scripts/sphinx-pre-install --version-check + @$(srctree)/tools/docs/sphinx-pre-install --version-check @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var= ))) =20 endif # HAVE_SPHINX diff --git a/Documentation/doc-guide/sphinx.rst b/Documentation/doc-guide/s= phinx.rst index 607589592bfb..932f68c53075 100644 --- a/Documentation/doc-guide/sphinx.rst +++ b/Documentation/doc-guide/sphinx.rst @@ -106,7 +106,7 @@ There's a script that automatically checks for Sphinx d= ependencies. If it can recognize your distribution, it will also give a hint about the install command line options for your distro:: =20 - $ ./scripts/sphinx-pre-install + $ ./tools/docs/sphinx-pre-install Checking if the needed tools for Fedora release 26 (Twenty Six) are avail= able Warning: better to also install "texlive-luatex85". You should run: @@ -116,7 +116,7 @@ command line options for your distro:: . sphinx_2.4.4/bin/activate pip install -r Documentation/sphinx/requirements.txt =20 - Can't build as 1 mandatory dependency is missing at ./scripts/sphinx-pre-= install line 468. + Can't build as 1 mandatory dependency is missing at ./tools/docs/sphinx-p= re-install line 468. =20 By default, it checks all the requirements for both html and PDF, including the requirements for images, math expressions and LaTeX build, and assumes diff --git a/Documentation/sphinx/kerneldoc-preamble.sty b/Documentation/sp= hinx/kerneldoc-preamble.sty index 5d68395539fe..16d9ff46fdf6 100644 --- a/Documentation/sphinx/kerneldoc-preamble.sty +++ b/Documentation/sphinx/kerneldoc-preamble.sty @@ -220,7 +220,7 @@ If you want them, please install non-variable ``Noto Sans CJK'' font families along with the texlive-xecjk package by following instructions from - \sphinxcode{./scripts/sphinx-pre-install}. + \sphinxcode{./tools/docs/sphinx-pre-install}. Having optional non-variable ``Noto Serif CJK'' font families will improve the looks of those translations. \end{sphinxadmonition}} diff --git a/Documentation/translations/it_IT/doc-guide/sphinx.rst b/Docume= ntation/translations/it_IT/doc-guide/sphinx.rst index 1f513bc33618..a5c5d935febf 100644 --- a/Documentation/translations/it_IT/doc-guide/sphinx.rst +++ b/Documentation/translations/it_IT/doc-guide/sphinx.rst @@ -109,7 +109,7 @@ Sphinx. Se lo script riesce a riconoscere la vostra dis= tribuzione, allora sar=C3=A0 in grado di darvi dei suggerimenti su come procedere per complet= are l'installazione:: =20 - $ ./scripts/sphinx-pre-install + $ ./tools/docs/sphinx-pre-install Checking if the needed tools for Fedora release 26 (Twenty Six) are avail= able Warning: better to also install "texlive-luatex85". You should run: @@ -119,7 +119,7 @@ l'installazione:: . sphinx_2.4.4/bin/activate pip install -r Documentation/sphinx/requirements.txt =20 - Can't build as 1 mandatory dependency is missing at ./scripts/sphinx-pre-= install line 468. + Can't build as 1 mandatory dependency is missing at ./tools/docs/sphinx-p= re-install line 468. =20 L'impostazione predefinita prevede il controllo dei requisiti per la gener= azione di documenti html e PDF, includendo anche il supporto per le immagini, le diff --git a/Documentation/translations/zh_CN/doc-guide/sphinx.rst b/Docume= ntation/translations/zh_CN/doc-guide/sphinx.rst index 23eac67fbc30..3375c6f3a811 100644 --- a/Documentation/translations/zh_CN/doc-guide/sphinx.rst +++ b/Documentation/translations/zh_CN/doc-guide/sphinx.rst @@ -84,7 +84,7 @@ PDF=E5=92=8CLaTeX=E6=9E=84=E5=BB=BA =E8=BF=99=E6=9C=89=E4=B8=80=E4=B8=AA=E8=84=9A=E6=9C=AC=E5=8F=AF=E4=BB=A5= =E8=87=AA=E5=8A=A8=E6=A3=80=E6=9F=A5Sphinx=E4=BE=9D=E8=B5=96=E9=A1=B9=E3=80= =82=E5=A6=82=E6=9E=9C=E5=AE=83=E8=AE=A4=E5=BE=97=E6=82=A8=E7=9A=84=E5=8F=91= =E8=A1=8C=E7=89=88=EF=BC=8C=E8=BF=98=E4=BC=9A=E6=8F=90=E7=A4=BA=E6=82=A8=E6= =89=80=E7=94=A8=E5=8F=91=E8=A1=8C =E7=89=88=E7=9A=84=E5=AE=89=E8=A3=85=E5=91=BD=E4=BB=A4:: =20 - $ ./scripts/sphinx-pre-install + $ ./tools/docs/sphinx-pre-install Checking if the needed tools for Fedora release 26 (Twenty Six) are avail= able Warning: better to also install "texlive-luatex85". You should run: @@ -94,7 +94,7 @@ PDF=E5=92=8CLaTeX=E6=9E=84=E5=BB=BA . sphinx_2.4.4/bin/activate pip install -r Documentation/sphinx/requirements.txt =20 - Can't build as 1 mandatory dependency is missing at ./scripts/sphinx-pre-= install line 468. + Can't build as 1 mandatory dependency is missing at ./tools/docs/sphinx-p= re-install line 468. =20 =E9=BB=98=E8=AE=A4=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E5=AE=83=E4=BC=9A= =E6=A3=80=E6=9F=A5html=E5=92=8CPDF=E7=9A=84=E6=89=80=E6=9C=89=E4=BE=9D=E8= =B5=96=E9=A1=B9=EF=BC=8C=E5=8C=85=E6=8B=AC=E5=9B=BE=E5=83=8F=E3=80=81=E6=95= =B0=E5=AD=A6=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=92=8CLaTeX=E6=9E=84=E5=BB=BA=E7= =9A=84 =E9=9C=80=E6=B1=82=EF=BC=8C=E5=B9=B6=E5=81=87=E8=AE=BE=E5=B0=86=E4=BD=BF= =E7=94=A8=E8=99=9A=E6=8B=9FPython=E7=8E=AF=E5=A2=83=E3=80=82html=E6=9E=84= =E5=BB=BA=E6=89=80=E9=9C=80=E7=9A=84=E4=BE=9D=E8=B5=96=E9=A1=B9=E8=A2=AB=E8= =AE=A4=E4=B8=BA=E6=98=AF=E5=BF=85=E9=9C=80=E7=9A=84=EF=BC=8C=E5=85=B6=E4=BB= =96=E4=BE=9D diff --git a/Documentation/translations/zh_CN/how-to.rst b/Documentation/tr= anslations/zh_CN/how-to.rst index ddd99c0f9b4d..714664fec308 100644 --- a/Documentation/translations/zh_CN/how-to.rst +++ b/Documentation/translations/zh_CN/how-to.rst @@ -64,7 +64,7 @@ Linux =E5=8F=91=E8=A1=8C=E7=89=88=E5=92=8C=E7=AE=80=E5=8D= =95=E5=9C=B0=E4=BD=BF=E7=94=A8 Linux =E5=91=BD=E4=BB=A4=E8=A1=8C=EF=BC=8C= =E9=82=A3=E4=B9=88=E5=8F=AF=E4=BB=A5=E8=BF=85=E9=80=9F=E5=BC=80=E5=A7=8B=E4= =BA=86 :: =20 cd linux - ./scripts/sphinx-pre-install + ./tools/docs/sphinx-pre-install =20 =E4=BB=A5 Fedora =E4=B8=BA=E4=BE=8B=EF=BC=8C=E5=AE=83=E7=9A=84=E8=BE=93=E5= =87=BA=E6=98=AF=E8=BF=99=E6=A0=B7=E7=9A=84:: =20 diff --git a/MAINTAINERS b/MAINTAINERS index 76dd823bfcc4..16a5d6ab627d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7309,7 +7309,6 @@ F: scripts/lib/abi/* F: scripts/lib/kdoc/* F: tools/docs/* F: tools/net/ynl/pyynl/lib/doc_generator.py -F: scripts/sphinx-pre-install X: Documentation/ABI/ X: Documentation/admin-guide/media/ X: Documentation/devicetree/ @@ -7344,7 +7343,7 @@ L: linux-doc@vger.kernel.org S: Maintained F: Documentation/sphinx/parse-headers.pl F: scripts/documentation-file-ref-check -F: scripts/sphinx-pre-install +F: tools/docs/sphinx-pre-install =20 DOCUMENTATION/ITALIAN M: Federico Vaga diff --git a/scripts/sphinx-pre-install b/tools/docs/sphinx-pre-install similarity index 100% rename from scripts/sphinx-pre-install rename to tools/docs/sphinx-pre-install --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 0DBE9333164; Wed, 17 Sep 2025 12:16:02 +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=1758111362; cv=none; b=JCbzqb5JyDu0Or9zaMgpGLvYalQ9+uYLHggSXUBepU7BNfTmD4qgTz5z50qyWXodMX+zUL69H30TVQSqpAI1h1GB2CnLWZWex+JW20T80w227zt630wtPPTniBy/tIEj9WXF7dHrFrepiS7K+iSKqz8FMLdyOUkpFlbQ1rL3LCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111362; c=relaxed/simple; bh=AH2lL83LG/MCK6GW00LCQjiXUczLYQf3wfFtphqsZ6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oek5Dfd/gaGEA3gnhw/RJ6G7I+lgLu8JtabptyFVOXs0aFTjB5IXYSPm+byqlO2dpOMqsXllARzjfKmuiQNP2+D0D3BBmpSCBwKjh7D+RYBBPU0p3K+g3c/u+c/irXHKjzwPVa1oMQ0qctDs0gugo/knJ/22EFFZL2SbU5iWEbY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g/KWGQ9N; 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="g/KWGQ9N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0866C4CEF7; Wed, 17 Sep 2025 12:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111361; bh=AH2lL83LG/MCK6GW00LCQjiXUczLYQf3wfFtphqsZ6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/KWGQ9NcAN9v6oSebFVQKvDDRIiCgXAx6UF6meul7UkQKm+T+GMXz/fcPpnfd+Dw bv+uihK7Jay6uSkXK1NgkVjYHHFzglgEiQhe7ooDET7L1Ct+vIM7zS9zDip4yOBrr6 75JUNuKBr/v5oPmRdBqRr5IlRuUsPqIX1EFgQ2EuQUQDR1zQR8fR3U2+taYEo3TWAe kfisWtscV1pa9rbQlzxVxsNBP3Qvv45qWYq7UPRlvqyDA8W4HPBLI6LMtj46T/EzNk YG14mBPj9CLHQmsJwZllP+9iMA3dlXvswT5T+Que0ru4dkd0/3T8rOwj80BXXNO4k2 WxIdqzCe6wQ7Q== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdg-12aY; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 08/24] tools/docs: sphinx-pre-install: drop a debug print Date: Wed, 17 Sep 2025 14:15:02 +0200 Message-ID: <4c7375298ce9aa1f15e0be42cc7e6fa7e8a54c1c.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" The version print at the lib was added for debugging purposes. Get rid of it. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-pre-install | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/docs/sphinx-pre-install b/tools/docs/sphinx-pre-install index 954ed3dc0645..fa12e01fc7fe 100755 --- a/tools/docs/sphinx-pre-install +++ b/tools/docs/sphinx-pre-install @@ -285,7 +285,6 @@ class AncillaryMethods: cur_ver =3D sys.version_info[:3] if cur_ver >=3D MIN_PYTHON_VERSION: ver =3D ver_str(cur_ver) - print(f"Python version: {ver}") =20 # This could be useful for debugging purposes if SphinxDependencyChecker.which("docutils"): --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 6C3D9393DF1; Wed, 17 Sep 2025 12:15:58 +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=1758111358; cv=none; b=E1OJcIDj5OnTs9K3up6feJm7GeZ6pOpK/x5LeX96OR+wOL7k0r0zxuE+d4jDCpZGiJj7PsdCs6NnfEBmyorJpO22mb+acrZU1ksk5lWky5P0/nrnw49QQO16ZPDpcjDmBsCv9WqALGsXVwhVpNyBFxpApxH8n2V6Wqhodd+3OU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111358; c=relaxed/simple; bh=+6TvP4G2cDhLKPN/soKTsxtFrnu65L1eQKi7+8h+GhI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JQiezdJhy6JmcIsnmehTkLNpY58Ndkd1/cQxvPpQMFgHb0Q60hcz3ygq6gk8YjWUlHY3X1chpszGmebSmtLu1uMUBdz8rre/bcPurofnQXBaH6Io837x1OwhKd491AysvoRu8iGQyPG/A2cJ3msm+eOuUATt8lL/INxorRTBMeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ghikJ8NO; 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="ghikJ8NO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9CF4C4CEFA; Wed, 17 Sep 2025 12:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111358; bh=+6TvP4G2cDhLKPN/soKTsxtFrnu65L1eQKi7+8h+GhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ghikJ8NOjsQIFxBgoQW6Vu23pH614OFo/RrSiFtqYzlStrR/RkWxOJrwQultaX2mS GeR8hAIkzqbtrsEQpxyTQ4LknCeey2q/QRQdgORCktxpO+24Q4RPFhRfO6UPyk/llh Hb2SuzZ4+l+yKqg0e4XWhhcdhkzD+lvoq4/62HWAqplto2N/vLybtTXcuAWhvw2WgI zcfWLUZO3VkQep1EqwgBFGEzm+MmI+lB9fqtPc7d4nAV7MtgD6z+8wZ3sPE4IM1FMC q1YnJoh4DMbyQqcg2KsYEWUu5ibAZf/1A4HtBczcmrwISS1/MKAcfPTilMNJASgEon TLWakWufRiCuw== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdk-19ZW; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 09/24] tools/docs: sphinx-pre-install: allow check for alternatives and bail out Date: Wed, 17 Sep 2025 14:15:03 +0200 Message-ID: <7d5855d9649bb928369b885b5c1e733197f3140f.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" The caller script may not want an automatic execution of the new version. Add two parameters to allow showing alternatives and to bail out if version is incompatible. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-pre-install | 48 +++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/tools/docs/sphinx-pre-install b/tools/docs/sphinx-pre-install index fa12e01fc7fe..895220c6d4f8 100755 --- a/tools/docs/sphinx-pre-install +++ b/tools/docs/sphinx-pre-install @@ -254,7 +254,7 @@ class AncillaryMethods: return (0, 0, 0) =20 @staticmethod - def find_python(): + def find_python(min_version): """ Detect if are out there any python 3.xy version newer than the current one. @@ -263,21 +263,25 @@ class AncillaryMethods: may need to update it one day, hopefully on a distant future. """ patterns =3D [ - "python3.[0-9]", "python3.[0-9][0-9]", + "python3.[0-9]", ] =20 # Seek for a python binary newer than MIN_PYTHON_VERSION + python_cmd =3D [] for path in os.getenv("PATH", "").split(":"): for pattern in patterns: for cmd in glob(os.path.join(path, pattern)): if os.path.isfile(cmd) and os.access(cmd, os.X_OK): version =3D SphinxDependencyChecker.get_python_ver= sion(cmd) - if version >=3D MIN_PYTHON_VERSION: - return cmd + if version >=3D min_version: + python_cmd.append((version, cmd)) + + return sorted(python_cmd, reverse=3DTrue) =20 @staticmethod - def check_python(): + def check_python(min_version, show_alternatives=3DFalse, bail_out=3DFa= lse, + success_on_error=3DFalse): """ Check if the current python binary satisfies our minimal requireme= nt for Sphinx build. If not, re-run with a newer version if found. @@ -301,18 +305,42 @@ class AncillaryMethods: =20 python_ver =3D ver_str(cur_ver) =20 - new_python_cmd =3D SphinxDependencyChecker.find_python() - if not new_python_cmd: + available_versions =3D SphinxDependencyChecker.find_python(min_ver= sion) + if not available_versions: print(f"ERROR: Python version {python_ver} is not spported any= more\n") print(" Can't find a new version. This script may fail") return =20 - # Restart script using the newer version script_path =3D os.path.abspath(sys.argv[0]) - args =3D [new_python_cmd, script_path] + sys.argv[1:] + + # Check possible alternatives + if available_versions: + new_python_cmd =3D available_versions[0][1] + else: + new_python_cmd =3D None + + if show_alternatives: + print("You could run, instead:") + for _, cmd in available_versions: + args =3D [cmd, script_path] + sys.argv[1:] + + cmd_str =3D " ".join(args) + print(f" {cmd_str}") + print() + + if bail_out: + msg =3D f"Python {python_ver} not supported. Bailing out" + if success_on_error: + print(msg, file=3Dsys.stderr) + sys.exit(0) + else: + sys.exit(msg) =20 print(f"Python {python_ver} not supported. Changing to {new_python= _cmd}") =20 + # Restart script using the newer version + args =3D [new_python_cmd, script_path] + sys.argv[1:] + try: os.execv(new_python_cmd, args) except OSError as e: @@ -1612,7 +1640,7 @@ def main(): =20 checker =3D SphinxDependencyChecker(args) =20 - checker.check_python() + checker.check_python(MIN_PYTHON_VERSION) checker.check_needs() =20 # Call main if not used as module --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 DB5A2372891; Wed, 17 Sep 2025 12:15:56 +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=1758111356; cv=none; b=E4FBSJRU4S2VMKHCHFanXuoYlpmdDiHtsEOQB5QmNsOSTyK1HCjeiP+H8optURuy0Yzh2PHnKOkXC/t/EI32GfiaVsO59jK1ZLclfY1rYDgaj7h2WcqklQFMFwH2b8LhCJ56h+is3NUI8V20lzUTtjfYdG01i7JvoXzwfz3FbVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111356; c=relaxed/simple; bh=uFmDzg+Gwc2jpPZcX4mIfP+EFkRf+cZmvTJP34ibSMs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WybnDw0nY+vNZw3YUYLg6KK1z+CtYLKxhOloRKMhbdn0Pf28Q9q5PYN1xcvI2m1oQNKFLuhiik942PMOOCI+KktR4I1gNmvjC4zmzr5b2dxitjyYXgSBqLuXkwvMk6cENWrKSheYMq7vSG7svN3DZfbEr4Ppvj6gGu7/Edw+j7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WFyOdnNe; 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="WFyOdnNe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BD53C4CEFA; Wed, 17 Sep 2025 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111356; bh=uFmDzg+Gwc2jpPZcX4mIfP+EFkRf+cZmvTJP34ibSMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WFyOdnNexX1iDgTb6czM+YgXoqC+KgQnhl/A7Q4/xi6P4fg78/oepzUPGF8cin7WS kbcYahU81vZP0L37fPYMhq7fMUeIjlV9lUvD0H451gHXWLQ+JgIzyLp+RJWJbZYv2j YgF4c63JnUr1MX5U8XH3+SeEHMeWtyJSsH/GMNN7df+bWRkMy4VkQcCRDbbzzyQH49 oJzRgXT7zgKS3Bcj/Tw5cTPiM8lXdRn39jSMKtNhN5LNMLArIf2KoII19cTXY3xlBj 5s1oqjM0+VA//anS1QFBJzSGWF5ZnR32rte8+KlABRMEThAte0ZGxJ1cbipBNzP4Mf U+Vx5lZhVP1dA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdo-1GgK; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 10/24] tools/docs: python_version: move version check from sphinx-pre-install Date: Wed, 17 Sep 2025 14:15:04 +0200 Message-ID: <8bd12676f1e95646dc97162c43bcaae522010d15.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab The sphinx-pre-install code has some logic to deal with Python version, which ensures that a minimal version will be enforced for documentation build logic. Move it to a separate library to allow re-using its code. No functional changes. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/lib/python_version.py | 158 +++++++++++++++++++++++++++++++ tools/docs/sphinx-pre-install | 147 +++------------------------- 2 files changed, 171 insertions(+), 134 deletions(-) create mode 100644 tools/docs/lib/python_version.py diff --git a/tools/docs/lib/python_version.py b/tools/docs/lib/python_versi= on.py new file mode 100644 index 000000000000..a9fda2470a26 --- /dev/null +++ b/tools/docs/lib/python_version.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2017-2025 Mauro Carvalho Chehab + +""" +Handle Python version check logic. + +Not all Python versions are supported by scripts. Yet, on some cases, +like during documentation build, a newer version of python could be +available. + +This class allows checking if the minimal requirements are followed. + +Better than that, PythonVersion.check_python() not only checks the minimal +requirements, but it automatically switches to a the newest available +Python version if present. + +""" + +import os +import re +import subprocess +import sys + +from glob import glob + +class PythonVersion: + """ + Ancillary methods that checks for missing dependencies for different + types of types, like binaries, python modules, rpm deps, etc. + """ + + def __init__(self, version): + """=C3=8Fnitialize self.version tuple from a version string""" + self.version =3D self.parse_version(version) + + @staticmethod + def parse_version(version): + """Convert a major.minor.patch version into a tuple""" + return tuple(int(x) for x in version.split(".")) + + @staticmethod + def ver_str(version): + """Returns a version tuple as major.minor.patch""" + return ".".join([str(x) for x in version]) + + def __str__(self): + """Returns a version tuple as major.minor.patch from self.version"= "" + return self.ver_str(self.version) + + @staticmethod + def get_python_version(cmd): + """ + Get python version from a Python binary. As we need to detect if + are out there newer python binaries, we can't rely on sys.release = here. + """ + + kwargs =3D {} + if sys.version_info < (3, 7): + kwargs['universal_newlines'] =3D True + else: + kwargs['text'] =3D True + + result =3D subprocess.run([cmd, "--version"], + stdout =3D subprocess.PIPE, + stderr =3D subprocess.PIPE, + **kwargs, check=3DFalse) + + version =3D result.stdout.strip() + + match =3D re.search(r"(\d+\.\d+\.\d+)", version) + if match: + return PythonVersion.parse_version(match.group(1)) + + print(f"Can't parse version {version}") + return (0, 0, 0) + + @staticmethod + def find_python(min_version): + """ + Detect if are out there any python 3.xy version newer than the + current one. + + Note: this routine is limited to up to 2 digits for python3. We + may need to update it one day, hopefully on a distant future. + """ + patterns =3D [ + "python3.[0-9][0-9]", + "python3.[0-9]", + ] + + python_cmd =3D [] + + # Seek for a python binary newer than min_version + for path in os.getenv("PATH", "").split(":"): + for pattern in patterns: + for cmd in glob(os.path.join(path, pattern)): + if os.path.isfile(cmd) and os.access(cmd, os.X_OK): + version =3D PythonVersion.get_python_version(cmd) + if version >=3D min_version: + python_cmd.append((version, cmd)) + + return sorted(python_cmd, reverse=3DTrue) + + @staticmethod + def check_python(min_version, show_alternatives=3DFalse, bail_out=3DFa= lse, + success_on_error=3DFalse): + """ + Check if the current python binary satisfies our minimal requireme= nt + for Sphinx build. If not, re-run with a newer version if found. + """ + cur_ver =3D sys.version_info[:3] + if cur_ver >=3D min_version: + ver =3D PythonVersion.ver_str(cur_ver) + return + + python_ver =3D PythonVersion.ver_str(cur_ver) + + available_versions =3D PythonVersion.find_python(min_version) + if not available_versions: + print(f"ERROR: Python version {python_ver} is not spported any= more\n") + print(" Can't find a new version. This script may fail") + return + + script_path =3D os.path.abspath(sys.argv[0]) + + # Check possible alternatives + if available_versions: + new_python_cmd =3D available_versions[0][1] + else: + new_python_cmd =3D None + + if show_alternatives: + print("You could run, instead:") + for _, cmd in available_versions: + args =3D [cmd, script_path] + sys.argv[1:] + + cmd_str =3D " ".join(args) + print(f" {cmd_str}") + print() + + if bail_out: + msg =3D f"Python {python_ver} not supported. Bailing out" + if success_on_error: + print(msg, file=3Dsys.stderr) + sys.exit(0) + else: + sys.exit(msg) + + print(f"Python {python_ver} not supported. Changing to {new_python= _cmd}") + + # Restart script using the newer version + args =3D [new_python_cmd, script_path] + sys.argv[1:] + + try: + os.execv(new_python_cmd, args) + except OSError as e: + sys.exit(f"Failed to restart with {new_python_cmd}: {e}") diff --git a/tools/docs/sphinx-pre-install b/tools/docs/sphinx-pre-install index 895220c6d4f8..d6d673b7945c 100755 --- a/tools/docs/sphinx-pre-install +++ b/tools/docs/sphinx-pre-install @@ -32,20 +32,10 @@ import subprocess import sys from glob import glob =20 +from lib.python_version import PythonVersion =20 -def parse_version(version): - """Convert a major.minor.patch version into a tuple""" - return tuple(int(x) for x in version.split(".")) - - -def ver_str(version): - """Returns a version tuple as major.minor.patch""" - - return ".".join([str(x) for x in version]) - - -RECOMMENDED_VERSION =3D parse_version("3.4.3") -MIN_PYTHON_VERSION =3D parse_version("3.7") +RECOMMENDED_VERSION =3D PythonVersion("3.4.3").version +MIN_PYTHON_VERSION =3D PythonVersion("3.7").version =20 =20 class DepManager: @@ -235,122 +225,11 @@ class AncillaryMethods: =20 return None =20 - @staticmethod - def get_python_version(cmd): - """ - Get python version from a Python binary. As we need to detect if - are out there newer python binaries, we can't rely on sys.release = here. - """ - - result =3D SphinxDependencyChecker.run([cmd, "--version"], - capture_output=3DTrue, text=3D= True) - version =3D result.stdout.strip() - - match =3D re.search(r"(\d+\.\d+\.\d+)", version) - if match: - return parse_version(match.group(1)) - - print(f"Can't parse version {version}") - return (0, 0, 0) - - @staticmethod - def find_python(min_version): - """ - Detect if are out there any python 3.xy version newer than the - current one. - - Note: this routine is limited to up to 2 digits for python3. We - may need to update it one day, hopefully on a distant future. - """ - patterns =3D [ - "python3.[0-9][0-9]", - "python3.[0-9]", - ] - - # Seek for a python binary newer than MIN_PYTHON_VERSION - python_cmd =3D [] - for path in os.getenv("PATH", "").split(":"): - for pattern in patterns: - for cmd in glob(os.path.join(path, pattern)): - if os.path.isfile(cmd) and os.access(cmd, os.X_OK): - version =3D SphinxDependencyChecker.get_python_ver= sion(cmd) - if version >=3D min_version: - python_cmd.append((version, cmd)) - - return sorted(python_cmd, reverse=3DTrue) - - @staticmethod - def check_python(min_version, show_alternatives=3DFalse, bail_out=3DFa= lse, - success_on_error=3DFalse): - """ - Check if the current python binary satisfies our minimal requireme= nt - for Sphinx build. If not, re-run with a newer version if found. - """ - cur_ver =3D sys.version_info[:3] - if cur_ver >=3D MIN_PYTHON_VERSION: - ver =3D ver_str(cur_ver) - - # This could be useful for debugging purposes - if SphinxDependencyChecker.which("docutils"): - result =3D SphinxDependencyChecker.run(["docutils", "--ver= sion"], - capture_output=3DTrue,= text=3DTrue) - ver =3D result.stdout.strip() - match =3D re.search(r"(\d+\.\d+\.\d+)", ver) - if match: - ver =3D match.group(1) - - print(f"Docutils version: {ver}") - - return - - python_ver =3D ver_str(cur_ver) - - available_versions =3D SphinxDependencyChecker.find_python(min_ver= sion) - if not available_versions: - print(f"ERROR: Python version {python_ver} is not spported any= more\n") - print(" Can't find a new version. This script may fail") - return - - script_path =3D os.path.abspath(sys.argv[0]) - - # Check possible alternatives - if available_versions: - new_python_cmd =3D available_versions[0][1] - else: - new_python_cmd =3D None - - if show_alternatives: - print("You could run, instead:") - for _, cmd in available_versions: - args =3D [cmd, script_path] + sys.argv[1:] - - cmd_str =3D " ".join(args) - print(f" {cmd_str}") - print() - - if bail_out: - msg =3D f"Python {python_ver} not supported. Bailing out" - if success_on_error: - print(msg, file=3Dsys.stderr) - sys.exit(0) - else: - sys.exit(msg) - - print(f"Python {python_ver} not supported. Changing to {new_python= _cmd}") - - # Restart script using the newer version - args =3D [new_python_cmd, script_path] + sys.argv[1:] - - try: - os.execv(new_python_cmd, args) - except OSError as e: - sys.exit(f"Failed to restart with {new_python_cmd}: {e}") - @staticmethod def run(*args, **kwargs): """ Excecute a command, hiding its output by default. - Preserve comatibility with older Python versions. + Preserve compatibility with older Python versions. """ =20 capture_output =3D kwargs.pop('capture_output', False) @@ -554,11 +433,11 @@ class MissingCheckers(AncillaryMethods): for line in result.stdout.split("\n"): match =3D re.match(r"^sphinx-build\s+([\d\.]+)(?:\+(?:/[\da-f]= +)|b\d+)?\s*$", line) if match: - return parse_version(match.group(1)) + return PythonVersion.parse_version(match.group(1)) =20 match =3D re.match(r"^Sphinx.*\s+([\d\.]+)\s*$", line) if match: - return parse_version(match.group(1)) + return PythonVersion.parse_version(match.group(1)) =20 def check_sphinx(self, conf): """ @@ -569,7 +448,7 @@ class MissingCheckers(AncillaryMethods): for line in f: match =3D re.match(r"^\s*needs_sphinx\s*=3D\s*[\'\"]([= \d\.]+)[\'\"]", line) if match: - self.min_version =3D parse_version(match.group(1)) + self.min_version =3D PythonVersion.parse_version(m= atch.group(1)) break except IOError: sys.exit(f"Can't open {conf}") @@ -589,8 +468,8 @@ class MissingCheckers(AncillaryMethods): sys.exit(f"{sphinx} didn't return its version") =20 if self.cur_version < self.min_version: - curver =3D ver_str(self.cur_version) - minver =3D ver_str(self.min_version) + curver =3D PythonVersion.ver_str(self.cur_version) + minver =3D PythonVersion.ver_str(self.min_version) =20 print(f"ERROR: Sphinx version is {curver}. It should be >=3D {= minver}") self.need_sphinx =3D 1 @@ -1331,7 +1210,7 @@ class SphinxDependencyChecker(MissingCheckers): else: if self.need_sphinx and ver >=3D self.min_version: return (f, ver) - elif parse_version(ver) > self.cur_version: + elif PythonVersion.parse_version(ver) > self.cur_version: return (f, ver) =20 return ("", ver) @@ -1438,7 +1317,7 @@ class SphinxDependencyChecker(MissingCheckers): return =20 if self.latest_avail_ver: - latest_avail_ver =3D ver_str(self.latest_avail_ver) + latest_avail_ver =3D PythonVersion.ver_str(self.latest_avail_v= er) =20 if not self.need_sphinx: # sphinx-build is present and its version is >=3D $min_version @@ -1534,7 +1413,7 @@ class SphinxDependencyChecker(MissingCheckers): else: print("Unknown OS") if self.cur_version !=3D (0, 0, 0): - ver =3D ver_str(self.cur_version) + ver =3D PythonVersion.ver_str(self.cur_version) print(f"Sphinx version: {ver}\n") =20 # Check the type of virtual env, depending on Python version @@ -1640,7 +1519,7 @@ def main(): =20 checker =3D SphinxDependencyChecker(args) =20 - checker.check_python(MIN_PYTHON_VERSION) + PythonVersion.check_python(MIN_PYTHON_VERSION) checker.check_needs() =20 # Call main if not used as module --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 9D44631A802; Wed, 17 Sep 2025 12:15:55 +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=1758111355; cv=none; b=DDG6pMrOcZtTvySlxxQ7hdkL30WGRur42IhWFPOL39xCE1HLV8EOz0Yh/ceGSbyZrLGRt7HDAmCOPAVHYPDP56hj2QhYfkd7zjlbyklM7pmd6+y+oRGUy42CrLraE8sTToP0lE7jW5iC/w6DkCa7ozt2vwt/WHxLc7/4mUJC5x8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=0Y7xHKz4h3eGEkKm5XfGE40A/GthvIC7Xyzd3QVPaDw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tfCDtOCaw4J979fPchs8IaVQOuBq7mZzfAV14QguecTTLH3/W7rUuuP9ihY+lhKQl6LGz0P20GGAWp3sutNl82e5syfK1M1KWRcAMrGwN8DDMYXJhz7Zpf1Xw49U6JLnORtSDsXw1ZmCH5puFVNJ8VfYJvZPNWRnAh3rxFXw42o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rgOH5eg4; 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="rgOH5eg4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5056C4CEF0; Wed, 17 Sep 2025 12:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=0Y7xHKz4h3eGEkKm5XfGE40A/GthvIC7Xyzd3QVPaDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rgOH5eg4uMdMglFUT3xrNZJSMICpldFDCE3UidqbdrCoAIsmBcLRrpoOveNY9tJaO 4YdeXVuoJYG9/kBP+loCAIRxWrHllFiHn7j9tzg26HnpD+fuxEEujWBNXF4OhTM9iw 6HrxfjSZnByuehf79QHJOfQNmsO9108uXAo+3v1TabqtVq+BYnZ7IpNEz1bLVFTtJZ EJol/KOlwMY8+MjLPamds2oeKTn2kRBB3H5MIZb3htL4tXpNTm3WubLLYyUlSeLBjI P6Uyl0vNlbOEy+Lt3NjWsqHjVSfnJgv7Nr4biSZs9O4AWieY/2YI2HtaLv6d8vlDyJ ebEM5tLEBSh0w== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGds-1OMH; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , "Mauro Carvalho Chehab" , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , Boqun Feng , Danilo Krummrich , Gary Guo , Miguel Ojeda , Trevor Gross , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH v7 11/24] tools/docs: sphinx-build-wrapper: add a wrapper for sphinx-build Date: Wed, 17 Sep 2025 14:15:05 +0200 Message-ID: <820f986c9b61637e5af6708a014e36d70740bcb7.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" There are too much magic inside docs Makefile to properly run sphinx-build. Create an ancillary script that contains all kernel-related sphinx-build call logic currently at Makefile. Such script is designed to work both as an standalone command and as part of a Makefile. As such, it properly handles POSIX jobserver used by GNU make. On a side note, there was a line number increase due to the conversion (ignoring comments) is: Documentation/Makefile | 131 +++---------- tools/docs/sphinx-build-wrapper | 293 +++++++++++++++++++++++++++++++ 2 files changed, 323 insertions(+), 101 deletions(-) Comments and descriptions adds: tools/docs/sphinx-build-wrapper | 261 +++++++++++++++++++++++++++++++- So, about half of the script are comments/descriptions. This is because some things are more verbosed on Python and because it requires reading env vars from Makefile. Besides it, this script has some extra features that don't exist at the Makefile: - It can be called directly from command line; - It properly return PDF build errors. When running the script alone, it will only take handle sphinx-build targets. On other words, it won't runn make rustdoc after building htmlfiles, nor it will run the extra check scripts. Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 129 ++----- tools/docs/sphinx-build-wrapper | 599 ++++++++++++++++++++++++++++++++ 2 files changed, 627 insertions(+), 101 deletions(-) create mode 100755 tools/docs/sphinx-build-wrapper diff --git a/Documentation/Makefile b/Documentation/Makefile index fd6399c79fab..380284026c13 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -23,21 +23,22 @@ SPHINXOPTS =3D SPHINXDIRS =3D . DOCS_THEME =3D DOCS_CSS =3D -_SPHINXDIRS =3D $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%= ,$(wildcard $(srctree)/Documentation/*/index.rst))) SPHINX_CONF =3D conf.py PAPER =3D BUILDDIR =3D $(obj)/output PDFLATEX =3D xelatex LATEXOPTS =3D -interaction=3Dbatchmode -no-shell-escape =20 +PYTHONPYCACHEPREFIX ?=3D $(abspath $(BUILDDIR)/__pycache__) + +# Wrapper for sphinx-build + +BUILD_WRAPPER =3D $(srctree)/tools/docs/sphinx-build-wrapper + # For denylisting "variable font" files # Can be overridden by setting as an env variable FONTS_CONF_DENY_VF ?=3D $(HOME)/deny-vf =20 -ifeq ($(findstring 1, $(KBUILD_VERBOSE)),) -SPHINXOPTS +=3D "-q" -endif - # User-friendly check for sphinx-build HAVE_SPHINX :=3D $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then ech= o 1; else echo 0; fi) =20 @@ -51,63 +52,29 @@ ifeq ($(HAVE_SPHINX),0) =20 else # HAVE_SPHINX =20 -# User-friendly check for pdflatex and latexmk -HAVE_PDFLATEX :=3D $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo= 1; else echo 0; fi) -HAVE_LATEXMK :=3D $(shell if which latexmk >/dev/null 2>&1; then echo 1; e= lse echo 0; fi) +# Common documentation targets +infodocs texinfodocs latexdocs epubdocs xmldocs pdfdocs linkcheckdocs: + $(Q)@$(srctree)/tools/docs/sphinx-pre-install --version-check + +$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ \ + --sphinxdirs=3D"$(SPHINXDIRS)" --conf=3D"$(SPHINX_CONF)" \ + --builddir=3D"$(BUILDDIR)" --deny-vf=3D$(FONTS_CONF_DENY_VF) \ + --theme=3D$(DOCS_THEME) --css=3D$(DOCS_CSS) --paper=3D$(PAPER) =20 -ifeq ($(HAVE_LATEXMK),1) - PDFLATEX :=3D latexmk -$(PDFLATEX) -endif #HAVE_LATEXMK - -# Internal variables. -PAPEROPT_a4 =3D -D latex_elements.papersize=3Da4paper -PAPEROPT_letter =3D -D latex_elements.papersize=3Dletterpaper -ALLSPHINXOPTS =3D -D kerneldoc_srctree=3D$(srctree) -D kerneldoc_bin=3D$= (KERNELDOC) -ALLSPHINXOPTS +=3D $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) -ifneq ($(wildcard $(srctree)/.config),) -ifeq ($(CONFIG_RUST),y) - # Let Sphinx know we will include rustdoc - ALLSPHINXOPTS +=3D -t rustdoc -endif +# Special handling for pdfdocs +ifneq ($(shell which $(PDFLATEX) >/dev/null 2>&1; echo $$?),0) +pdfdocs: + $(warning The '$(PDFLATEX)' command was not found. Make sure you have it = installed and in PATH to produce PDF output.) + @echo " SKIP Sphinx $@ target." endif -# the i18n builder cannot share the environment and doctrees with the othe= rs -I18NSPHINXOPTS =3D $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . - -# commands; the 'cmd' from scripts/Kbuild.include is not *loopable* -loop_cmd =3D $(echo-cmd) $(cmd_$(1)) || exit; - -# $2 sphinx builder e.g. "html" -# $3 name of the build subfolder / e.g. "userspace-api/media", used as: -# * dest folder relative to $(BUILDDIR) and -# * cache folder relative to $(BUILDDIR)/.doctrees -# $4 dest subfolder e.g. "man" for man pages at userspace-api/media/man -# $5 reST source folder relative to $(src), -# e.g. "userspace-api/media" for the linux-tv book-set at ./Documentati= on/userspace-api/media - -PYTHONPYCACHEPREFIX ?=3D $(abspath $(BUILDDIR)/__pycache__) - -quiet_cmd_sphinx =3D SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4) - cmd_sphinx =3D \ - PYTHONPYCACHEPREFIX=3D"$(PYTHONPYCACHEPREFIX)" \ - BUILDDIR=3D$(abspath $(BUILDDIR)) SPHINX_CONF=3D$(abspath $(src)/$5/$(SPH= INX_CONF)) \ - $(PYTHON3) $(srctree)/scripts/jobserver-exec \ - $(CONFIG_SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \ - $(SPHINXBUILD) \ - -b $2 \ - -c $(abspath $(src)) \ - -d $(abspath $(BUILDDIR)/.doctrees/$3) \ - -D version=3D$(KERNELVERSION) -D release=3D$(KERNELRELEASE) \ - $(ALLSPHINXOPTS) \ - $(abspath $(src)/$5) \ - $(abspath $(BUILDDIR)/$3/$4) && \ - if [ "x$(DOCS_CSS)" !=3D "x" ]; then \ - cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(= DOCS_CSS)) $(BUILDDIR)/$3/_static/; \ - fi =20 +# HTML main logic is identical to other targets. However, if rust is enabl= ed, +# an extra step at the end is required to generate rustdoc. htmldocs: - @$(srctree)/tools/docs/sphinx-pre-install --version-check - @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var))) - + $(Q)@$(srctree)/tools/docs/sphinx-pre-install --version-check + +$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ \ + --sphinxdirs=3D"$(SPHINXDIRS)" --conf=3D"$(SPHINX_CONF)" \ + --builddir=3D"$(BUILDDIR)" \ + --theme=3D$(DOCS_THEME) --css=3D$(DOCS_CSS) --paper=3D$(PAPER) # If Rust support is available and .config exists, add rustdoc generated c= ontents. # If there are any, the errors from this make rustdoc will be displayed but # won't stop the execution of htmldocs @@ -118,49 +85,6 @@ ifeq ($(CONFIG_RUST),y) endif endif =20 -texinfodocs: - @$(srctree)/tools/docs/sphinx-pre-install --version-check - @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,texinfo,$(var),texin= fo,$(var))) - -# Note: the 'info' Make target is generated by sphinx itself when -# running the texinfodocs target define above. -infodocs: texinfodocs - $(MAKE) -C $(BUILDDIR)/texinfo info - -linkcheckdocs: - @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(v= ar))) - -latexdocs: - @$(srctree)/tools/docs/sphinx-pre-install --version-check - @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$= (var))) - -ifeq ($(HAVE_PDFLATEX),0) - -pdfdocs: - $(warning The '$(PDFLATEX)' command was not found. Make sure you have it = installed and in PATH to produce PDF output.) - @echo " SKIP Sphinx $@ target." - -else # HAVE_PDFLATEX - -pdfdocs: DENY_VF =3D XDG_CONFIG_HOME=3D$(FONTS_CONF_DENY_VF) -pdfdocs: latexdocs - @$(srctree)/tools/docs/sphinx-pre-install --version-check - $(foreach var,$(SPHINXDIRS), \ - $(MAKE) PDFLATEX=3D"$(PDFLATEX)" LATEXOPTS=3D"$(LATEXOPTS)" $(DENY_VF)= -C $(BUILDDIR)/$(var)/latex || $(PYTHON3) $(srctree)/tools/docs/check-vari= able-fonts.py || exit; \ - mkdir -p $(BUILDDIR)/$(var)/pdf; \ - mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUI= LDDIR)/$(var)/pdf/; \ - ) - -endif # HAVE_PDFLATEX - -epubdocs: - @$(srctree)/tools/docs/sphinx-pre-install --version-check - @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(v= ar))) - -xmldocs: - @$(srctree)/tools/docs/sphinx-pre-install --version-check - @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var= ))) - endif # HAVE_SPHINX =20 # The following targets are independent of HAVE_SPHINX, and the rules shou= ld @@ -172,6 +96,9 @@ refcheckdocs: cleandocs: $(Q)rm -rf $(BUILDDIR) =20 +# Used only on help +_SPHINXDIRS =3D $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%= ,$(wildcard $(srctree)/Documentation/*/index.rst))) + dochelp: @echo ' Linux kernel internal documentation in different formats from Re= ST:' @echo ' htmldocs - HTML' diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per new file mode 100755 index 000000000000..c57c732b879c --- /dev/null +++ b/tools/docs/sphinx-build-wrapper @@ -0,0 +1,599 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Mauro Carvalho Chehab +# +# pylint: disable=3DR0902, R0912, R0913, R0914, R0915, R0917, C0103 +# +# Converted from docs Makefile and parallel-wrapper.sh, both under +# GPLv2, copyrighted since 2008 by the following authors: +# +# Akira Yokosawa +# Arnd Bergmann +# Breno Leitao +# Carlos Bilbao +# Dave Young +# Donald Hunter +# Geert Uytterhoeven +# Jani Nikula +# Jan Stancek +# Jonathan Corbet +# Joshua Clayton +# Kees Cook +# Linus Torvalds +# Magnus Damm +# Masahiro Yamada +# Mauro Carvalho Chehab +# Maxim Cournoyer +# Peter Foley +# Randy Dunlap +# Rob Herring +# Shuah Khan +# Thorsten Blum +# Tomas Winkler + + +""" +Sphinx build wrapper that handles Kernel-specific business rules: + +- it gets the Kernel build environment vars; +- it determines what's the best parallelism; +- it handles SPHINXDIRS + +This tool ensures that MIN_PYTHON_VERSION is satisfied. If version is +below that, it seeks for a new Python version. If found, it re-runs using +the newer version. +""" + +import argparse +import os +import shlex +import shutil +import subprocess +import sys + +from lib.python_version import PythonVersion +from lib.latex_fonts import LatexFontChecker + +LIB_DIR =3D "../../scripts/lib" +SRC_DIR =3D os.path.dirname(os.path.realpath(__file__)) + +sys.path.insert(0, os.path.join(SRC_DIR, LIB_DIR)) + +from jobserver import JobserverExec # pylint: disable=3DC0413,C041= 1,E0401 + +# +# Some constants +# +MIN_PYTHON_VERSION =3D PythonVersion("3.7").version +PAPER =3D ["", "a4", "letter"] + +TARGETS =3D { + "cleandocs": { "builder": "clean" }, + "linkcheckdocs": { "builder": "linkcheck" }, + "htmldocs": { "builder": "html" }, + "epubdocs": { "builder": "epub", "out_dir": "epub" }, + "texinfodocs": { "builder": "texinfo", "out_dir": "texinfo" }, + "infodocs": { "builder": "texinfo", "out_dir": "texinfo" }, + "latexdocs": { "builder": "latex", "out_dir": "latex" }, + "pdfdocs": { "builder": "latex", "out_dir": "latex" }, + "xmldocs": { "builder": "xml", "out_dir": "xml" }, +} + + +# +# SphinxBuilder class +# + +class SphinxBuilder: + """ + Handles a sphinx-build target, adding needed arguments to build + with the Kernel. + """ + + def is_rust_enabled(self): + """Check if rust is enabled at .config""" + config_path =3D os.path.join(self.srctree, ".config") + if os.path.isfile(config_path): + with open(config_path, "r", encoding=3D"utf-8") as f: + return "CONFIG_RUST=3Dy" in f.read() + return False + + def get_path(self, path, use_cwd=3DFalse, abs_path=3DFalse): + """ + Ancillary routine to handle patches the right way, as shell does. + + It first expands "~" and "~user". Then, if patch is not absolute, + join self.srctree. Finally, if requested, convert to abspath. + """ + + path =3D os.path.expanduser(path) + if not path.startswith("/"): + if use_cwd: + base =3D os.getcwd() + else: + base =3D self.srctree + + path =3D os.path.join(base, path) + + if abs_path: + return os.path.abspath(path) + + return path + + def get_sphinx_extra_opts(self, n_jobs): + """ + Get the number of jobs to be used for docs build passed via command + line and desired sphinx verbosity. + + The number of jobs can be on different places: + + 1) It can be passed via "-j" argument; + 2) The SPHINXOPTS=3D"-j8" env var may have "-j"; + 3) if called via GNU make, -j specifies the desired number of jobs. + with GNU makefile, this number is available via POSIX jobserver; + 4) if none of the above is available, it should default to "-jauto= ", + and let sphinx decide the best value. + """ + + # + # SPHINXOPTS env var, if used, contains extra arguments to be used + # by sphinx-build time. Among them, it may contain sphinx verbosity + # and desired number of parallel jobs. + # + parser =3D argparse.ArgumentParser() + parser.add_argument('-j', '--jobs', type=3Dint) + parser.add_argument('-q', '--quiet', type=3Dint) + + # + # Other sphinx-build arguments go as-is, so place them + # at self.sphinxopts, using shell parser + # + sphinxopts =3D shlex.split(os.environ.get("SPHINXOPTS", "")) + + # + # Build a list of sphinx args, honoring verbosity here if specified + # + + verbose =3D self.verbose + sphinx_args, self.sphinxopts =3D parser.parse_known_args(sphinxopt= s) + if sphinx_args.quiet is True: + verbose =3D False + + # + # If the user explicitly sets "-j" at command line, use it. + # Otherwise, pick it from SPHINXOPTS args + # + if n_jobs: + self.n_jobs =3D n_jobs + elif sphinx_args.jobs: + self.n_jobs =3D sphinx_args.jobs + else: + self.n_jobs =3D None + + if not verbose: + self.sphinxopts +=3D ["-q"] + + def __init__(self, builddir, verbose=3DFalse, n_jobs=3DNone): + """Initialize internal variables""" + self.verbose =3D None + + # + # Normal variables passed from Kernel's makefile + # + self.kernelversion =3D os.environ.get("KERNELVERSION", "unknown") + self.kernelrelease =3D os.environ.get("KERNELRELEASE", "unknown") + self.pdflatex =3D os.environ.get("PDFLATEX", "xelatex") + self.latexopts =3D os.environ.get("LATEXOPTS", "-interaction=3Dbat= chmode -no-shell-escape") + + if not verbose: + verbose =3D bool(os.environ.get("KBUILD_VERBOSE", "") !=3D "") + + if verbose is not None: + self.verbose =3D verbose + + # + # Source tree directory. This needs to be at os.environ, as + # Sphinx extensions use it + # + self.srctree =3D os.environ.get("srctree") + if not self.srctree: + self.srctree =3D "." + os.environ["srctree"] =3D self.srctree + + # + # Now that we can expand srctree, get other directories as well + # + self.sphinxbuild =3D os.environ.get("SPHINXBUILD", "sphinx-build") + self.kerneldoc =3D self.get_path(os.environ.get("KERNELDOC", + "scripts/kernel-doc.= py")) + self.builddir =3D self.get_path(builddir, use_cwd=3DTrue, abs_path= =3DTrue) + + self.config_rust =3D self.is_rust_enabled() + + # + # Get directory locations for LaTeX build toolchain + # + self.pdflatex_cmd =3D shutil.which(self.pdflatex) + self.latexmk_cmd =3D shutil.which("latexmk") + + self.env =3D os.environ.copy() + + self.get_sphinx_extra_opts(n_jobs) + + def run_sphinx(self, sphinx_build, build_args, *args, **pwargs): + """ + Executes sphinx-build using current python3 command. + + When calling via GNU make, POSIX jobserver is used to tell how + many jobs are still available from a job pool. claim all remaining + jobs, as we don't want sphinx-build to run in parallel with other + jobs. + + Despite that, the user may actually force a different value than + the number of available jobs via command line. + + The "with" logic here is used to ensure that the claimed jobs will + be freed once subprocess finishes + """ + + with JobserverExec() as jobserver: + if jobserver.claim: + # + # when GNU make is used, claim available jobs from jobserv= er + # + n_jobs =3D str(jobserver.claim) + else: + # + # Otherwise, let sphinx decide by default + # + n_jobs =3D "auto" + + # + # If explicitly requested via command line, override default + # + if self.n_jobs: + n_jobs =3D str(self.n_jobs) + + cmd =3D [sys.executable, sphinx_build] + cmd +=3D [f"-j{n_jobs}"] + cmd +=3D self.sphinxopts + cmd +=3D build_args + + if self.verbose: + print(" ".join(cmd)) + + return subprocess.call(cmd, *args, **pwargs) + + def handle_html(self, css, output_dir): + """ + Extra steps for HTML and epub output. + + For such targets, we need to ensure that CSS will be properly + copied to the output _static directory + """ + + if not css: + return + + css =3D os.path.expanduser(css) + if not css.startswith("/"): + css =3D os.path.join(self.srctree, css) + + static_dir =3D os.path.join(output_dir, "_static") + os.makedirs(static_dir, exist_ok=3DTrue) + + try: + shutil.copy2(css, static_dir) + except (OSError, IOError) as e: + print(f"Warning: Failed to copy CSS: {e}", file=3Dsys.stderr) + + def handle_pdf(self, output_dirs, deny_vf): + """ + Extra steps for PDF output. + + As PDF is handled via a LaTeX output, after building the .tex file, + a new build is needed to create the PDF output from the latex + directory. + """ + builds =3D {} + max_len =3D 0 + + # + # Since early 2024, Fedora and openSUSE tumbleweed have started + # deploying variable-font format of "Noto CJK", causing LaTeX + # to break with CJK. Work around it, by denying the variable font + # usage during xelatex build by passing the location of a config + # file with a deny list. + # + # See tools/docs/lib/latex_fonts.py for more details. + # + if deny_vf: + deny_vf =3D os.path.expanduser(deny_vf) + if os.path.isdir(deny_vf): + self.env["XDG_CONFIG_HOME"] =3D deny_vf + + for from_dir in output_dirs: + pdf_dir =3D os.path.join(from_dir, "../pdf") + os.makedirs(pdf_dir, exist_ok=3DTrue) + + if self.latexmk_cmd: + latex_cmd =3D [self.latexmk_cmd, f"-{self.pdflatex}"] + else: + latex_cmd =3D [self.pdflatex] + + latex_cmd.extend(shlex.split(self.latexopts)) + + tex_suffix =3D ".tex" + + # + # Process each .tex file + # + + has_tex =3D False + build_failed =3D False + with os.scandir(from_dir) as it: + for entry in it: + if not entry.name.endswith(tex_suffix): + continue + + name =3D entry.name[:-len(tex_suffix)] + has_tex =3D True + + # + # LaTeX PDF error code is almost useless for us: + # any warning makes it non-zero. For kernel doc builds= it + # always return non-zero even when build succeeds. + # So, let's do the best next thing: check if all PDF + # files were built. If they're, print a summary and + # return 0 at the end of this function + # + try: + subprocess.run(latex_cmd + [entry.path], + cwd=3Dfrom_dir, check=3DTrue, env= =3Dself.env) + except subprocess.CalledProcessError: + pass + + pdf_name =3D name + ".pdf" + pdf_from =3D os.path.join(from_dir, pdf_name) + pdf_to =3D os.path.join(pdf_dir, pdf_name) + + if os.path.exists(pdf_from): + os.rename(pdf_from, pdf_to) + builds[name] =3D os.path.relpath(pdf_to, self.buil= ddir) + else: + builds[name] =3D "FAILED" + build_failed =3D True + + name =3D entry.name.removesuffix(".tex") + max_len =3D max(max_len, len(name)) + + if not has_tex: + name =3D os.path.basename(from_dir) + max_len =3D max(max_len, len(name)) + builds[name] =3D "FAILED (no .tex)" + build_failed =3D True + + msg =3D "Summary" + msg +=3D "\n" + "=3D" * len(msg) + print() + print(msg) + + for pdf_name, pdf_file in builds.items(): + print(f"{pdf_name:<{max_len}}: {pdf_file}") + + print() + + if build_failed: + msg =3D LatexFontChecker().check() + if msg: + print(msg) + + sys.exit("PDF build failed: not all PDF files were created.") + else: + print("All PDF files were built.") + + def handle_info(self, output_dirs): + """ + Extra steps for Info output. + + For texinfo generation, an additional make is needed from the + texinfo directory. + """ + + for output_dir in output_dirs: + try: + subprocess.run(["make", "info"], cwd=3Doutput_dir, check= =3DTrue) + except subprocess.CalledProcessError as e: + sys.exit(f"Error generating info docs: {e}") + + def cleandocs(self, builder): # pylint: disable=3DW0613 + """Remove documentation output directory""" + shutil.rmtree(self.builddir, ignore_errors=3DTrue) + + def build(self, target, sphinxdirs=3DNone, conf=3D"conf.py", + theme=3DNone, css=3DNone, paper=3DNone, deny_vf=3DNone): + """ + Build documentation using Sphinx. This is the core function of this + module. It prepares all arguments required by sphinx-build. + """ + + builder =3D TARGETS[target]["builder"] + out_dir =3D TARGETS[target].get("out_dir", "") + + # + # Cleandocs doesn't require sphinx-build + # + if target =3D=3D "cleandocs": + self.cleandocs(builder) + return + + if theme: + os.environ["DOCS_THEME"] =3D theme + + # + # Other targets require sphinx-build, so check if it exists + # + sphinxbuild =3D shutil.which(self.sphinxbuild, path=3Dself.env["PA= TH"]) + if not sphinxbuild: + sys.exit(f"Error: {self.sphinxbuild} not found in PATH.\n") + + if builder =3D=3D "latex": + if not self.pdflatex_cmd and not self.latexmk_cmd: + sys.exit("Error: pdflatex or latexmk required for PDF gene= ration") + + docs_dir =3D os.path.abspath(os.path.join(self.srctree, "Documenta= tion")) + + # + # Fill in base arguments for Sphinx build + # + kerneldoc =3D self.kerneldoc + if kerneldoc.startswith(self.srctree): + kerneldoc =3D os.path.relpath(kerneldoc, self.srctree) + + args =3D [ "-b", builder, "-c", docs_dir ] + + if builder =3D=3D "latex": + if not paper: + paper =3D PAPER[1] + + args.extend(["-D", f"latex_elements.papersize=3D{paper}paper"]) + + if self.config_rust: + args.extend(["-t", "rustdoc"]) + + if conf: + self.env["SPHINX_CONF"] =3D self.get_path(conf, abs_path=3DTru= e) + + if not sphinxdirs: + sphinxdirs =3D os.environ.get("SPHINXDIRS", ".") + + # + # sphinxdirs can be a list or a whitespace-separated string + # + sphinxdirs_list =3D [] + for sphinxdir in sphinxdirs: + if isinstance(sphinxdir, list): + sphinxdirs_list +=3D sphinxdir + else: + sphinxdirs_list +=3D sphinxdir.split() + + # + # Step 1: Build each directory in separate. + # + # This is not the best way of handling it, as cross-references bet= ween + # them will be broken, but this is what we've been doing since + # the beginning. + # + output_dirs =3D [] + for sphinxdir in sphinxdirs_list: + src_dir =3D os.path.join(docs_dir, sphinxdir) + doctree_dir =3D os.path.join(self.builddir, ".doctrees") + output_dir =3D os.path.join(self.builddir, sphinxdir, out_dir) + + # + # Make directory names canonical + # + src_dir =3D os.path.normpath(src_dir) + doctree_dir =3D os.path.normpath(doctree_dir) + output_dir =3D os.path.normpath(output_dir) + + os.makedirs(doctree_dir, exist_ok=3DTrue) + os.makedirs(output_dir, exist_ok=3DTrue) + + output_dirs.append(output_dir) + + build_args =3D args + [ + "-d", doctree_dir, + "-D", f"kerneldoc_bin=3D{kerneldoc}", + "-D", f"version=3D{self.kernelversion}", + "-D", f"release=3D{self.kernelrelease}", + "-D", f"kerneldoc_srctree=3D{self.srctree}", + src_dir, + output_dir, + ] + + try: + self.run_sphinx(sphinxbuild, build_args, env=3Dself.env) + except (OSError, ValueError, subprocess.SubprocessError) as e: + sys.exit(f"Build failed: {repr(e)}") + + # + # Ensure that each html/epub output will have needed static fi= les + # + if target in ["htmldocs", "epubdocs"]: + self.handle_html(css, output_dir) + + # + # Step 2: Some targets (PDF and info) require an extra step once + # sphinx-build finishes + # + if target =3D=3D "pdfdocs": + self.handle_pdf(output_dirs, deny_vf) + elif target =3D=3D "infodocs": + self.handle_info(output_dirs) + +def jobs_type(value): + """ + Handle valid values for -j. Accepts Sphinx "-jauto", plus a number + equal or bigger than one. + """ + if value is None: + return None + + if value.lower() =3D=3D 'auto': + return value.lower() + + try: + if int(value) >=3D 1: + return value + + raise argparse.ArgumentTypeError(f"Minimum jobs is 1, got {value}") + except ValueError: + raise argparse.ArgumentTypeError(f"Must be 'auto' or positive inte= ger, got {value}") # pylint: disable=3DW0707 + +def main(): + """ + Main function. The only mandatory argument is the target. If not + specified, the other arguments will use default values if not + specified at os.environ. + """ + parser =3D argparse.ArgumentParser(description=3D"Kernel documentation= builder") + + parser.add_argument("target", choices=3Dlist(TARGETS.keys()), + help=3D"Documentation target to build") + parser.add_argument("--sphinxdirs", nargs=3D"+", + help=3D"Specific directories to build") + parser.add_argument("--conf", default=3D"conf.py", + help=3D"Sphinx configuration file") + parser.add_argument("--builddir", default=3D"output", + help=3D"Sphinx configuration file") + + parser.add_argument("--theme", help=3D"Sphinx theme to use") + + parser.add_argument("--css", help=3D"Custom CSS file for HTML/EPUB") + + parser.add_argument("--paper", choices=3DPAPER, default=3DPAPER[0], + help=3D"Paper size for LaTeX/PDF output") + + parser.add_argument('--deny-vf', + help=3D"Configuration to deny variable fonts on pd= f builds") + + parser.add_argument("-v", "--verbose", action=3D'store_true', + help=3D"place build in verbose mode") + + parser.add_argument('-j', '--jobs', type=3Djobs_type, + help=3D"Sets number of jobs to use with sphinx-bui= ld") + + args =3D parser.parse_args() + + PythonVersion.check_python(MIN_PYTHON_VERSION) + + builder =3D SphinxBuilder(builddir=3Dargs.builddir, + verbose=3Dargs.verbose, n_jobs=3Dargs.jobs) + + builder.build(args.target, sphinxdirs=3Dargs.sphinxdirs, conf=3Dargs.c= onf, + theme=3Dargs.theme, css=3Dargs.css, paper=3Dargs.paper, + deny_vf=3Dargs.deny_vf) + +if __name__ =3D=3D "__main__": + main() --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 DD56130CB50; Wed, 17 Sep 2025 12:15:54 +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=1758111355; cv=none; b=jZLcWDkZTwEmsrgH2XhuiU9tSVzAqMsCAICl6jZ5sBYDgIIbmlmzFgubGD9Zor9ysl2OS1nafb4pVrtpgS9/+yPqwu6TtdKd7K83aZQdg69zSEUDJ3a8ciy9VM49XOm9KQ9fd6PyJxRWAnMiLvr4sDv1zLMPNHpaVOWEUjZWeBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=ZLbhSMLrYrG412X2oMrDythT1CiWtmLDdQQNSbEgmmI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dax/ufaHo2pSWhz3RoPV6aOKXwLnXIlETFDVApiWLn3SGUnK+oMAx521quSNB9KbAn7tCeQ4LwOUFClSDYOLxyX0a7MTtC2PgBafopw0UTzDyp4VxRm06M5fBzpDg/CffIS6mWRBdQZPlIrdpl5RSzW+NmdOlfVe8Ldlisq3rqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G2OdkxGB; 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="G2OdkxGB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EFFCC4CEF5; Wed, 17 Sep 2025 12:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111354; bh=ZLbhSMLrYrG412X2oMrDythT1CiWtmLDdQQNSbEgmmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G2OdkxGBcl6PWAso9+K3wR9CNuvL87Bz1Tc20BhYfgk4l4ITFHH6u+9yeJ9dDIVgu /bz8qmcuMJrFyvFyI3AaM4UHplw4+0E2Uqt9z099IPXlDJOMmO45B0zjkH4gU2KibR d6tKSxA7TKnaPkJWTs4l2reJ22UHiDXp9U+SGP4ezwJbCyoJCeDkuUi/aUpMkCPU/i C69zaQK8GVSyNXEHHhlPTR5V39fTr9zA/R4AiFQgGXxtKRldahlfZfvi8bCZptqbEv Np8vEH/2NIuBioaZO8+/0eHCSAKA9vbvbKncfg3Q2vPVh6EIb4PYqyV3mL9mMPT04b lHVTJ0eTs281g== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGdw-1VMu; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 12/24] docs: parallel-wrapper.sh: remove script Date: Wed, 17 Sep 2025 14:15:06 +0200 Message-ID: <1f9e6c7cfd74fcbaf788687d006d63d57ffdd049.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" The only usage of this script was docs Makefile. Now that it is using the new sphinx-build-wrapper, which has inside the code from parallel-wrapper.sh, we can drop this script. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/parallel-wrapper.sh | 33 ------------------------ 1 file changed, 33 deletions(-) delete mode 100644 Documentation/sphinx/parallel-wrapper.sh diff --git a/Documentation/sphinx/parallel-wrapper.sh b/Documentation/sphin= x/parallel-wrapper.sh deleted file mode 100644 index e54c44ce117d..000000000000 --- a/Documentation/sphinx/parallel-wrapper.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0+ -# -# Figure out if we should follow a specific parallelism from the make -# environment (as exported by scripts/jobserver-exec), or fall back to -# the "auto" parallelism when "-jN" is not specified at the top-level -# "make" invocation. - -sphinx=3D"$1" -shift || true - -parallel=3D"$PARALLELISM" -if [ -z "$parallel" ] ; then - # If no parallelism is specified at the top-level make, then - # fall back to the expected "-jauto" mode that the "htmldocs" - # target has had. - auto=3D$(perl -e 'open IN,"'"$sphinx"' --version 2>&1 |"; - while () { - if (m/([\d\.]+)/) { - print "auto" if ($1 >=3D "1.7") - } - } - close IN') - if [ -n "$auto" ] ; then - parallel=3D"$auto" - fi -fi -# Only if some parallelism has been determined do we add the -jN option. -if [ -n "$parallel" ] ; then - parallel=3D"-j$parallel" -fi - -exec "$sphinx" $parallel "$@" --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 383AD225761; Wed, 17 Sep 2025 12:15:53 +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=1758111354; cv=none; b=UvZUy3S22wI1lTOTMz9+8qRhOX+FvC3Ul5vfKqLGHXtfvcnGrJVZhJKdRGoKa9S1cXGsLI97GfUfbPvBTpYtlgwMDZsz0i8r2OWpeSx+TT7Xzif742tPXrnG8LiCFw/BS3WEX5Air2V872Wk8P2Ah0Yic3ee8DW+xT8ugiACzz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111354; c=relaxed/simple; bh=0ypUcNGg9z6BJTKB3g3MJi0xHG6c16cyioz2ve+I/iQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jG8X3Z12zASABTIzSS4hxEGLviZK38E1q+Lj1GHY7ixRDB3/DqC2BIeQ1+8M+2ws/144ab1l8GjfoQSarwo3f4dPTLpcmCOImawAiZ+6cVd1E7SKvi5Y/Q36wl60XcmR9M/GxFL2iwa72mWlYAaTmmVXkp2qHLbAQ4zVkUcBjPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aScCu71n; 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="aScCu71n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BACD4C4CEF0; Wed, 17 Sep 2025 12:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111353; bh=0ypUcNGg9z6BJTKB3g3MJi0xHG6c16cyioz2ve+I/iQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aScCu71ns3Q4t5aSDMqAS61P2Jmg7w5LIqvl22+yxOhR/qrCd+WCxU4rs0g14VNfV 4Zv2JpekEbA32D3DjQuU6LrmDZRaVnu0MbCIlRzvVRPHet66jIhePEwi/c9Ud5hATv aJRRuBvzV2VZ4ZJh1WErRTL3RiizRf6j4ylhc0NLWW+kA3qY+QmjCdSNE0WKHtCeVK JoG+5DG/k3TFazCHbLX+5m+WrYIuBBSyMZSHRXIrCHoMdN1v/7cYAVgucTfDlcfDdV +CuV7J9dmnUKEXWcpo0hIEjJH/vKQmIZi2hQH8oLQ1NAkvF0/AN6gh50vKGXqYIc8f SZO6dsEIZlLsA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGe0-1cDV; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 13/24] docs: Makefile: document latex/PDF PAPER= parameter Date: Wed, 17 Sep 2025 14:15:07 +0200 Message-ID: <4ed5c9fbb30c67c0325a278a687c9bbe11d29c16.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" While the build system supports this for a long time, this was never documented. Add a documentation for it. Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/Makefile b/Documentation/Makefile index 380284026c13..a52b311cdadc 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -124,4 +124,6 @@ dochelp: @echo @echo ' make DOCS_CSS=3D{a .css file} adds a DOCS_CSS override file for= html/epub output.' @echo + @echo ' make PAPER=3D{a4|letter} Specifies the paper size used for LaTe= X/PDF output.' + @echo @echo ' Default location for the generated documents is Documentation/o= utput' --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 8C47631A7FD; Wed, 17 Sep 2025 12:15:55 +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=1758111355; cv=none; b=nUlgpdC70A9AgAHSHSFB4SbWestd3il1zsn90e7wRBHPt5MCTO9FpcwWn76N2favJtxXYnFN0lmBII7PZE3byxjnUDSzsrwvFMa7ZqkHArP9SlIRBJZM5ChffRDHiuRL8PXm+UJAFk6LlwAtRUpfaZ4HxMdBcVCQJo6Usg37y/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=mOGPpjFInnJF5ficZgf3c7TZFdWiehGB3ZFVn3w7fEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YppNsrJRsL2aCthDwV7FcFEmgfoLzUi/nP5fQoXIfIlDagUIFT/UJN/ideUPksvnQ+DtJzGSI0o4hUHZW4kt7JEovpp5SY0cVJxrgdv8BaMkOfibK5Vr3K4nQ9dd4PwTynvcoG3e+isd3muKyJ9IXat0gmPhXQtJGbTgo34cLd8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mb73G6p/; 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="mb73G6p/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AB6FC4CEFD; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=mOGPpjFInnJF5ficZgf3c7TZFdWiehGB3ZFVn3w7fEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mb73G6p/MvHTbaZemWskx/A9k3EmwRPf8L50Vgu916lpBnMg97Sb6QnzyuKLVBhd+ 5BOI61zeGUS/abs3dj+02VPFeW4Kr63K54vhIlU94glf9tYxMw91/BQBsm959rqVAA DKTkrMcl3gWTv6FqsAJDrvbxVSFPeTj7FnyNcxpoeqUPwWJk2mHRNt7dTPI2iU792U yKT55gGq9ZAlYkmWnicFDvNhkgp1GRVuXtJZUrtzEu/sx5g5KSmanRzGIKfaOgwjaS zxpaNu97+uBKsms6vYnsOA1+d/4CN15VCsw5yhIAVTOQKBWhyxWnawIMngcK6dLdTi AL/txEBiydQnA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGe4-1jQ5; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 14/24] docs: Makefile: document FONTS_CONF_DENY_VF= parameter Date: Wed, 17 Sep 2025 14:15:08 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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" This parameter is there for some time, but it doesn't have anything documenting it at make help. Add some documentation, pointing to the place where one can find more details. Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/Makefile b/Documentation/Makefile index a52b311cdadc..05397b9d844d 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -126,4 +126,7 @@ dochelp: @echo @echo ' make PAPER=3D{a4|letter} Specifies the paper size used for LaTe= X/PDF output.' @echo + @echo ' make FONTS_CONF_DENY_VF=3D{path} sets a deny list to block vari= able Noto CJK fonts' + @echo ' for PDF build. See tools/docs/lib/latex_fonts.py for more detai= ls' + @echo @echo ' Default location for the generated documents is Documentation/o= utput' --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 BF98F2FBDE8; Wed, 17 Sep 2025 12:15:58 +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=1758111358; cv=none; b=dreLXmktjuCZ+7ZslDe3hXcXN4UfYst6tp07N+k20ABKDad7KNg1sNVBaIqJvxNuAhzShHqV1p2CMA9AF2F7B7G9OdFhzcCsSgzGB/4PnlRr7gSP9XUIvzQt7j4wuAkh4WhWMA2jvyBADN8t0mNOsv+kGhb2/1TM6LHXvnDYl20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111358; c=relaxed/simple; bh=PUUaTyw8rlc0Hc2z+x0BdPRC+RKe/Sri73mjZjht+w8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=buHOeact7041/VkGo4Cwv/+/NB/OBbaTue8XGMD5EY0US7KRZCB5iDhdY4EYn8dzvNSIFg8o1Cp1vf/ikONCgZkSlqFaB5oD/d+XQAwFGgOkK5Xcm/PqpuURb1aYFpA3oH1vosPuR4V2CM+D/GYezFLRADyzCtbOaNP0vFRdVQU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aQFj/nqS; 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="aQFj/nqS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BBEDC4CEF5; Wed, 17 Sep 2025 12:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111358; bh=PUUaTyw8rlc0Hc2z+x0BdPRC+RKe/Sri73mjZjht+w8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQFj/nqSwFzfj++u4XcOZwP5aN8k6g6yaU9dLkvDKnoAq204Qy5szO+u/j+Nn1fzo njTPyCogL1XTpEPZxKn0q3GeNmSc0t2mGtFzfYLb0qCxBTshOzQOS0h1vAMF3kpqGI D+YKuq8Iq/p41aLdmkDd342nP1ceAZ63bwK9fwmEb+DJPc0nhThiKlj/Mz/8maLgqZ CsYC8iwp/8WcRC4/3DJki7c9ez3EcGKraK7aO/hYtsbsv/BYYRzCIGkysQwuACXfbb m5n+lJcqN6jobKmnYZMe84PAbBqPFjk/NGBpsK7Jxu6qAHqV0ybJlUfkGqWLK6jfJx ns26zxHzece1g== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGe8-1qN7; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 15/24] tools/docs: sphinx-build-wrapper: add an argument for LaTeX interactive mode Date: Wed, 17 Sep 2025 14:15:09 +0200 Message-ID: <48d17b80c88d5f54ed63713fa2410f75ef15bc58.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" By default, we use LaTeX batch mode to build docs. This way, when an error happens, the build fails. This is good for normal builds, but when debugging problems with pdf generation, the best is to use interactive mode. We already support it via LATEXOPTS, but having a command line argument makes it easier: Interactive mode: ./scripts/sphinx-build-wrapper pdfdocs --sphinxdirs peci -v -i ... Running 'xelatex --no-pdf -no-pdf -recorder ".../Documentation/output/pe= ci/latex/peci.tex"' ... Default batch mode: ./scripts/sphinx-build-wrapper pdfdocs --sphinxdirs peci -v ... Running 'xelatex --no-pdf -no-pdf -interaction=3Dbatchmode -no-shell-esca= pe -recorder ".../Documentation/output/peci/latex/peci.tex"' ... Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-build-wrapper | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index c57c732b879c..50761f125bc9 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -173,7 +173,7 @@ class SphinxBuilder: if not verbose: self.sphinxopts +=3D ["-q"] =20 - def __init__(self, builddir, verbose=3DFalse, n_jobs=3DNone): + def __init__(self, builddir, verbose=3DFalse, n_jobs=3DNone, interacti= ve=3DNone): """Initialize internal variables""" self.verbose =3D None =20 @@ -183,7 +183,11 @@ class SphinxBuilder: self.kernelversion =3D os.environ.get("KERNELVERSION", "unknown") self.kernelrelease =3D os.environ.get("KERNELRELEASE", "unknown") self.pdflatex =3D os.environ.get("PDFLATEX", "xelatex") - self.latexopts =3D os.environ.get("LATEXOPTS", "-interaction=3Dbat= chmode -no-shell-escape") + + if not interactive: + self.latexopts =3D os.environ.get("LATEXOPTS", "-interaction= =3Dbatchmode -no-shell-escape") + else: + self.latexopts =3D os.environ.get("LATEXOPTS", "") =20 if not verbose: verbose =3D bool(os.environ.get("KBUILD_VERBOSE", "") !=3D "") @@ -584,12 +588,16 @@ def main(): parser.add_argument('-j', '--jobs', type=3Djobs_type, help=3D"Sets number of jobs to use with sphinx-bui= ld") =20 + parser.add_argument('-i', '--interactive', action=3D'store_true', + help=3D"Change latex default to run in interactive= mode") + args =3D parser.parse_args() =20 PythonVersion.check_python(MIN_PYTHON_VERSION) =20 builder =3D SphinxBuilder(builddir=3Dargs.builddir, - verbose=3Dargs.verbose, n_jobs=3Dargs.jobs) + verbose=3Dargs.verbose, n_jobs=3Dargs.jobs, + interactive=3Dargs.interactive) =20 builder.build(args.target, sphinxdirs=3Dargs.sphinxdirs, conf=3Dargs.c= onf, theme=3Dargs.theme, css=3Dargs.css, paper=3Dargs.paper, --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 0DA4C3728B6; Wed, 17 Sep 2025 12:15:57 +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=1758111357; cv=none; b=gl6sl6vlJ/qZ1djCdT3eQu49I8jLQfnazg1L4oauVL/kOK/U2OoRA+qK3CJdRspxYc7QUw3iFoeN2IMKgQZSsGjkLi4LHgHaLvn+Nsk9qsl9efFOQeRqLIPh7mj/VQli6t/YRcCODdjFc+CpIyV9aezKYSYdNfYohNHNeyFpDrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111357; c=relaxed/simple; bh=Pbt/uH3/UgM6ew/nk/FSpaBLbop272L8YPcfdZN28/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qvcljgq9gXT3jrH2CMjLu+QhEfLG1Q8+dYA+ofw4wBCP8nW81mxwmhDzFfQrXmSQDM4g4Dqk25XsYpW1chcq2kkcWGpeWsRmPo2Za6bX9M2Spg3jdr0bOV4EXJXWz0Zx2i0oxO6R4EllXSqHe6BzZmz54GjGuUeQbAgAL+VGj1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cmvoOSL0; 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="cmvoOSL0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B14EAC4CEFD; Wed, 17 Sep 2025 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111356; bh=Pbt/uH3/UgM6ew/nk/FSpaBLbop272L8YPcfdZN28/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cmvoOSL0CsnT8QTxitmP48dsarh/Et5dMpv6mosIMl1y8gaXJN42II6loeIE4p314 jbe2AyS29p/2i5DS7Dlzx6ZuL37IWhd56tWuXTfZeKr0LdGujIu6mbJ7y+eUWhCgrE auH++UuJK9e98rSYcrW5LsxuxYVWyGziRDCD5GfzLLXVlhJg1GrjoWHYi8ND+uVG08 GvCV6a8b5hQcws2dhcStwsLlK4IfwD3PoGIpsfzVu1pBEm+BIpJbV/M8SnkKd1Q6pM FZ9EuUf7ag2StayO1FqeHa/Co7zi5pP9q4OjMRYN+vBhBVcC2wXOc/SAZ5oEs0LxeT NA+rLOaDafCBg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGeC-1xOE; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 16/24] tools/docs: sphinx-build-wrapper: allow building PDF files in parallel Date: Wed, 17 Sep 2025 14:15:10 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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" Use POSIX jobserver when available or -j to run PDF builds in parallel, restoring pdf build performance. Yet, running it when debugging troubles is a bad idea, so, when calling directly via command line, except if "-j" is splicitly requested, it will serialize the build. With such change, a PDF doc builds now takes around 5 minutes on a Ryzen 9 machine with 32 cpu threads: # Explicitly paralelize both Sphinx and LaTeX pdf builds $ make cleandocs; time scripts/sphinx-build-wrapper pdfdocs -j 33 real 5m17.901s user 15m1.499s sys 2m31.482s # Use POSIX jobserver to paralelize both sphinx-build and LaTeX $ make cleandocs; time make pdfdocs real 5m22.369s user 15m9.076s sys 2m31.419s # Serializes PDF build, while keeping Sphinx parallelized. # it is equivalent of passing -jauto via command line $ make cleandocs; time scripts/sphinx-build-wrapper pdfdocs real 11m20.901s user 13m2.910s sys 1m44.553s Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-build-wrapper | 218 +++++++++++++++++++++++--------- 1 file changed, 156 insertions(+), 62 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 50761f125bc9..0fe21b343e7a 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -51,6 +51,8 @@ import shutil import subprocess import sys =20 +from concurrent import futures + from lib.python_version import PythonVersion from lib.latex_fonts import LatexFontChecker =20 @@ -291,6 +293,87 @@ class SphinxBuilder: except (OSError, IOError) as e: print(f"Warning: Failed to copy CSS: {e}", file=3Dsys.stderr) =20 + def build_pdf_file(self, latex_cmd, from_dir, path): + """Builds a single pdf file using latex_cmd""" + try: + subprocess.run(latex_cmd + [path], + cwd=3Dfrom_dir, check=3DTrue, env=3Dself.env) + + return True + except subprocess.CalledProcessError: + return False + + def pdf_parallel_build(self, tex_suffix, latex_cmd, tex_files, n_jobs): + """Build PDF files in parallel if possible""" + builds =3D {} + build_failed =3D False + max_len =3D 0 + has_tex =3D False + + # + # LaTeX PDF error code is almost useless for us: + # any warning makes it non-zero. For kernel doc builds it always r= eturn + # non-zero even when build succeeds. So, let's do the best next th= ing: + # Ignore build errors. At the end, check if all PDF files were bui= lt, + # printing a summary with the built ones and returning 0 if all of + # them were actually built. + # + with futures.ThreadPoolExecutor(max_workers=3Dn_jobs) as executor: + jobs =3D {} + + for from_dir, pdf_dir, entry in tex_files: + name =3D entry.name + + if not name.endswith(tex_suffix): + continue + + name =3D name[:-len(tex_suffix)] + + max_len =3D max(max_len, len(name)) + + has_tex =3D True + + future =3D executor.submit(self.build_pdf_file, latex_cmd, + from_dir, entry.path) + jobs[future] =3D (from_dir, pdf_dir, name) + + for future in futures.as_completed(jobs): + from_dir, pdf_dir, name =3D jobs[future] + + pdf_name =3D name + ".pdf" + pdf_from =3D os.path.join(from_dir, pdf_name) + + try: + success =3D future.result() + + if success and os.path.exists(pdf_from): + pdf_to =3D os.path.join(pdf_dir, pdf_name) + + os.rename(pdf_from, pdf_to) + + # + # if verbose, get the name of built PDF file + # + if self.verbose: + builds[name] =3D os.path.relpath(pdf_to, self.b= uilddir) + else: + builds[name] =3D "FAILED" + build_failed =3D True + except futures.Error as e: + builds[name] =3D f"FAILED ({repr(e)})" + build_failed =3D True + + # + # Handle case where no .tex files were found + # + if not has_tex: + name =3D "Sphinx LaTeX builder" + max_len =3D max(max_len, len(name)) + builds[name] =3D "FAILED (no .tex file was generated)" + build_failed =3D True + + return builds, build_failed, max_len + def handle_pdf(self, output_dirs, deny_vf): """ Extra steps for PDF output. @@ -301,6 +384,8 @@ class SphinxBuilder: """ builds =3D {} max_len =3D 0 + tex_suffix =3D ".tex" + tex_files =3D [] =20 # # Since early 2024, Fedora and openSUSE tumbleweed have started @@ -327,74 +412,83 @@ class SphinxBuilder: =20 latex_cmd.extend(shlex.split(self.latexopts)) =20 - tex_suffix =3D ".tex" - - # - # Process each .tex file - # - - has_tex =3D False - build_failed =3D False + # Get a list of tex files to process with os.scandir(from_dir) as it: for entry in it: - if not entry.name.endswith(tex_suffix): - continue - - name =3D entry.name[:-len(tex_suffix)] - has_tex =3D True - - # - # LaTeX PDF error code is almost useless for us: - # any warning makes it non-zero. For kernel doc builds= it - # always return non-zero even when build succeeds. - # So, let's do the best next thing: check if all PDF - # files were built. If they're, print a summary and - # return 0 at the end of this function - # - try: - subprocess.run(latex_cmd + [entry.path], - cwd=3Dfrom_dir, check=3DTrue, env= =3Dself.env) - except subprocess.CalledProcessError: - pass - - pdf_name =3D name + ".pdf" - pdf_from =3D os.path.join(from_dir, pdf_name) - pdf_to =3D os.path.join(pdf_dir, pdf_name) - - if os.path.exists(pdf_from): - os.rename(pdf_from, pdf_to) - builds[name] =3D os.path.relpath(pdf_to, self.buil= ddir) - else: - builds[name] =3D "FAILED" - build_failed =3D True - - name =3D entry.name.removesuffix(".tex") - max_len =3D max(max_len, len(name)) - - if not has_tex: - name =3D os.path.basename(from_dir) - max_len =3D max(max_len, len(name)) - builds[name] =3D "FAILED (no .tex)" - build_failed =3D True - - msg =3D "Summary" - msg +=3D "\n" + "=3D" * len(msg) - print() - print(msg) - - for pdf_name, pdf_file in builds.items(): - print(f"{pdf_name:<{max_len}}: {pdf_file}") - - print() - - if build_failed: + if entry.name.endswith(tex_suffix): + tex_files.append((from_dir, pdf_dir, entry)) + + # + # When using make, this won't be used, as the number of jobs comes + # from POSIX jobserver. So, this covers the case where build comes + # from command line. On such case, serialize by default, except if + # the user explicitly sets the number of jobs. + # + n_jobs =3D 1 + + # n_jobs is either an integer or "auto". Only use it if it is a nu= mber + if self.n_jobs: + try: + n_jobs =3D int(self.n_jobs) + except ValueError: + pass + + # + # When using make, jobserver.claim is the number of jobs that were + # used with "-j" and that aren't used by other make targets + # + with JobserverExec() as jobserver: + n_jobs =3D 1 + + # + # Handle the case when a parameter is passed via command line, + # using it as default, if jobserver doesn't claim anything + # + if self.n_jobs: + try: + n_jobs =3D int(self.n_jobs) + except ValueError: + pass + + if jobserver.claim: + n_jobs =3D jobserver.claim + + builds, build_failed, max_len =3D self.pdf_parallel_build(tex_= suffix, + latex_= cmd, + tex_fi= les, + n_jobs) + + # + # In verbose mode, print a summary with the build results per file. + # Otherwise, print a single line with all failures, if any. + # On both cases, return code 1 indicates build failures, + # + if self.verbose: + msg =3D "Summary" + msg +=3D "\n" + "=3D" * len(msg) + print() + print(msg) + + for pdf_name, pdf_file in builds.items(): + print(f"{pdf_name:<{max_len}}: {pdf_file}") + + print() + if build_failed: + msg =3D LatexFontChecker().check() + if msg: + print(msg) + + sys.exit("Error: not all PDF files were created.") + + elif build_failed: + n_failures =3D len(builds) + failures =3D ", ".join(builds.keys()) + msg =3D LatexFontChecker().check() if msg: print(msg) =20 - sys.exit("PDF build failed: not all PDF files were created.") - else: - print("All PDF files were built.") + sys.exit(f"Error: Can't build {n_failures} PDF file(s): {failu= res}") =20 def handle_info(self, output_dirs): """ --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 85EF432341B; Wed, 17 Sep 2025 12:15:56 +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=1758111356; cv=none; b=LQEg5F3Az9IFPIakyUxHGjV9enDD0MeREtUBk9A9r8QDa8wHo/Mv99JzA4abQbH2LpyCoUcJW7wtZborjtoOrdWiNqTV2jr0LMtOWFPLiE9gJvQ42Lq2LdEXBICZaAdl+nCURH8C9aUT1shGbUwIFDG6LbQV+njmXZyJ0X7GtGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111356; c=relaxed/simple; bh=WDtXWJRYNGux0wtm1BAyWaADemyId01OLfJz/YWYDuE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FIHyb9Mdv/6+uV26z7EuGroBjBVPF5cDIQ/jzS2BIh3NtMvYsOyGN6gGcaPWYtiiwTGpQTjAputPXtYu4dx57lTsVCkz9LoqyF8ngR3lGDNCf0tabAdEJi3goNDFH0cg15B3SbCAMd+XIP5qADymH7sLXg2Vm39aH58JsAKcRSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QqPa1XqK; 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="QqPa1XqK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51268C4CEFC; Wed, 17 Sep 2025 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111356; bh=WDtXWJRYNGux0wtm1BAyWaADemyId01OLfJz/YWYDuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QqPa1XqKkyijLM33gHHnyuHrp6uL06ePBXnhbbFsRFGRAM49LcdJXSyAbYKF3IqQi KD35INfB/senKvC/4XEkvTJZQp/GkI7sKAAJOKVy86YJObGdNdHzBADd4DHFMc7t3W 3T2aELdY9Gv0c4wxxMtXjHJfuj57QmyePs3M0VtLK+y2IsYxpjaIxwwzz3GveUFQUW 5F4XANT6TddfiIBRl6DokTHEJv4Myt3n8aNsvvPlU1qFJnixUh69MJMaAkvGk6gB/O lOt46OA1BjXk9sQfV15k76rumVHA0rXJgJZCtjOhuaqO8D07G/FrI2bPuzNiwVa3d9 q+F4vGLqy7RlQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGeG-24Q9; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 17/24] tools/docs,scripts: sphinx-*: prevent sphinx-build crashes Date: Wed, 17 Sep 2025 14:15:11 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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" On a properly set system, LANG and LC_ALL is always defined. However, some distros like Debian, Gentoo and their variants start with those undefioned. When Sphinx tries to set a locale with: locale.setlocale(locale.LC_ALL, '') It raises an exception, making Sphinx fail. This is more likely to happen with test containers. Add a logic to detect and workaround such issue by setting locale to C. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-build-wrapper | 11 +++++++++++ tools/docs/sphinx-pre-install | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 0fe21b343e7a..6c2580303e8e 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -45,6 +45,7 @@ the newer version. """ =20 import argparse +import locale import os import shlex import shutil @@ -565,6 +566,16 @@ class SphinxBuilder: if not sphinxdirs: sphinxdirs =3D os.environ.get("SPHINXDIRS", ".") =20 + # + # The sphinx-build tool has a bug: internally, it tries to set + # locale with locale.setlocale(locale.LC_ALL, ''). This causes a + # crash if language is not set. Detect and fix it. + # + try: + locale.setlocale(locale.LC_ALL, '') + except locale.Error: + self.env["LC_ALL"] =3D "C" + # # sphinxdirs can be a list or a whitespace-separated string # diff --git a/tools/docs/sphinx-pre-install b/tools/docs/sphinx-pre-install index d6d673b7945c..663d4e2a3f57 100755 --- a/tools/docs/sphinx-pre-install +++ b/tools/docs/sphinx-pre-install @@ -26,6 +26,7 @@ system pacage install is recommended. """ =20 import argparse +import locale import os import re import subprocess @@ -422,8 +423,19 @@ class MissingCheckers(AncillaryMethods): """ Gets sphinx-build version. """ + env =3D os.environ.copy() + + # The sphinx-build tool has a bug: internally, it tries to set + # locale with locale.setlocale(locale.LC_ALL, ''). This causes a + # crash if language is not set. Detect and fix it. try: - result =3D self.run([cmd, "--version"], + locale.setlocale(locale.LC_ALL, '') + except Exception: + env["LC_ALL"] =3D "C" + env["LANG"] =3D "C" + + try: + result =3D self.run([cmd, "--version"], env=3Denv, stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.STDOUT, text=3DTrue, check=3DTrue) --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 DC0C2372893; Wed, 17 Sep 2025 12:15:56 +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=1758111357; cv=none; b=OAy1qdkJMtXt68EF6IDt4uD3hYSjGVNZFc5F/b7PZAd7Ah6b1YIg2KwP4DYJ7UIi5fEzpofOcZt2aufDyXRNFx5NDXDN4ZskcRGhKINqcEF2KrwphtEIM4TJxGyTa89UkO924BmdOyszVYGYmUgn5NHjdI1ZISeNPnSod7XRhbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111357; c=relaxed/simple; bh=k6YcbtXwsJKesw6XBa4evKMXBMHtuUFMe++T/iQChqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=saqmNJjtDOT6H7kPErYbTxw6iUjsxF2IJgQTQg9ICimIeKgIubbrozdkJodTit7Z/abE9v8WNDJ6gkNAo6ol4VhaNa2iH5EEn6TlPFNwjmfzhYG5mY33AJ3lgUmdQI9guL3z9SIHdvK38Ju1nmL7Shx3TRFE0j9/MuLMUJIovkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CcqaPjO5; 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="CcqaPjO5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8338C4CEFB; Wed, 17 Sep 2025 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111356; bh=k6YcbtXwsJKesw6XBa4evKMXBMHtuUFMe++T/iQChqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CcqaPjO5d13YqyrnTLHuAHXUsgGfZqF+/MIN+tJYABEREFfiexjUsj6fK/pAk2B/4 Tjqp6GGJlwIEJnDnn4cDf1HhDY99CluKDx0s6gkfKJPXzG4c1/+uzOZWQbB5XLzjeN DfNb/cf2k3oWAkN+V3e5WNBRg3vHwPxdfSH6SF5ZMe0BoTN+S1VwptcuKciry0tfMo X9Doezmkjn+TES6E0TilslNbX1JF7a0W2Ryn+87UJv5dvN0YfwKHfLlXpoRetox1O5 kUXbBna6vT6iU6cUYZJpPiZqeBFr4lLuJYhbOrWI+KxhYW+OP+4tvXDTO53S8Utqvd KkroKx5+Mwh7g== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGeK-2BSi; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 18/24] tools/docs: sphinx-build-wrapper: Fix output for duplicated names Date: Wed, 17 Sep 2025 14:15:12 +0200 Message-ID: <66cef4f4600ec0252044cefd7117ed873438f337.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" When SPHINXDIRS is used, basename may be identical for different files. If this happens, the summary and error detection won't be accurate. Fix it by using relative names from builddir. While here, don't duplicate names. Report, instead: - SUCCESS output PDF file was built - FAILED latexmk/xelatex didn't build any PDF output - FAILED: no .tex files were generated Sphinx didn't build any tex file for SPHINXDIRS directories - FAILED ({python exception}) When a concurrent.futures is catched. Usually indicates an internal error at the build logic. With that, building multiple dirs with the same name is reported properly: $ make V=3D1 SPHINXDIRS=3D"admin-guide/media driver-api/media userspace= -api/media" pdfdocs Summary =3D=3D=3D=3D=3D=3D=3D admin-guide/media/pdf/media.pdf : SUCCESS driver-api/media/pdf/media.pdf : SUCCESS userspace-api/media/pdf/media.pdf: SUCCESS And if at least one of them fails, return code will be 1. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-build-wrapper | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 6c2580303e8e..8d1f77c4a880 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -329,9 +329,6 @@ class SphinxBuilder: continue =20 name =3D name[:-len(tex_suffix)] - - max_len =3D max(max_len, len(name)) - has_tex =3D True =20 future =3D executor.submit(self.build_pdf_file, latex_cmd, @@ -343,34 +340,35 @@ class SphinxBuilder: =20 pdf_name =3D name + ".pdf" pdf_from =3D os.path.join(from_dir, pdf_name) + pdf_to =3D os.path.join(pdf_dir, pdf_name) + out_name =3D os.path.relpath(pdf_to, self.builddir) + max_len =3D max(max_len, len(out_name)) =20 try: success =3D future.result() =20 if success and os.path.exists(pdf_from): - pdf_to =3D os.path.join(pdf_dir, pdf_name) - os.rename(pdf_from, pdf_to) =20 # # if verbose, get the name of built PDF file # if self.verbose: - builds[name] =3D os.path.relpath(pdf_to, self.b= uilddir) + builds[out_name] =3D "SUCCESS" else: - builds[name] =3D "FAILED" + builds[out_name] =3D "FAILED" build_failed =3D True except futures.Error as e: - builds[name] =3D f"FAILED ({repr(e)})" + builds[out_name] =3D f"FAILED ({repr(e)})" build_failed =3D True =20 # # Handle case where no .tex files were found # if not has_tex: - name =3D "Sphinx LaTeX builder" - max_len =3D max(max_len, len(name)) - builds[name] =3D "FAILED (no .tex file was generated)" + out_name =3D "LaTeX files" + max_len =3D max(max_len, len(out_name)) + builds[out_name] =3D "FAILED: no .tex files were generated" build_failed =3D True =20 return builds, build_failed, max_len --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 BB0AA37C116; Wed, 17 Sep 2025 12:15:57 +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=1758111357; cv=none; b=pF92yc4wHN81Ui46Ye/LyOHz/oDGyl3Wj9Km6nWXaJfDBLOSjqiU8khgtDo/QzdHisDP2SXSx11dBPw30x2TWvGy7JLio0LveNYY0BvnuFa+vIyR4UCPp2Okdw14zBD8Ua/rWalBDjHzEzil9RCD7H2Rck76soaAwoGeLOz6AVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111357; c=relaxed/simple; bh=KDZQ/WnN5vw7Bl6a4chb+TcehefEfRpozxecUjS1tVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NCNIKTQHwWhPfS2wBIKzcuRKUWPLhI19BH/3viRuO1MdovV11UpRhsP9TbPOEigBJ8BkSwN3+ifsMEQFDVK+61+MQEwFU1udCS+0p34sDHQ+w+NnYhOhOv9RERFJpFx764n84dfxceRIG2BqnO4c4fgLtElIX1WgLfM+liFoQ4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aSauP6aJ; 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="aSauP6aJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26724C4CEF7; Wed, 17 Sep 2025 12:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111357; bh=KDZQ/WnN5vw7Bl6a4chb+TcehefEfRpozxecUjS1tVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aSauP6aJcU9M95c1AYqWV0JLEGZhuDsNcSVaPznUJ79TcJbKvkmv4fX+JoXSR1p4/ xRXl/3cSWXhu4Lt5tKk2YAvMZhZ8eax/HDx6tNVjISKTkQp9HGPOkqM246SU56CGx2 pYkTPK65EulCmBvT2GB0LY/GSDDscgFY5GZPfXj+1hdglwT+ixxlwu4MDZdBOr9c+p 7z9rawYAnO43cbG11l9DJk+37IXHQYRDfCnO+PT/lRo4Otrr5LU7B5s1mZcy5h7lZX xk43b0K/W1L0s1VzS4Ocr9kWRkWPBFWfoSeK0LMn0iTXVAKqxN/q8GjkWfvPUWuTXH hWKi5jo+A8fRg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGeO-2J2F; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Alice Ryhl , Masahiro Yamada , Miguel Ojeda , Nathan Chancellor , Nicolas Schier , Randy Dunlap , Tamir Duberstein , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 19/24] docs: add support to build manpages from kerneldoc output Date: Wed, 17 Sep 2025 14:15:13 +0200 Message-ID: <25a6f9a1c1d746c9e6b3a5eba181d01fe98976ea.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" Generating man files currently requires running a separate script. The target also doesn't appear at the docs Makefile. Add support for mandocs at the Makefile, adding the build logic inside sphinx-build-wrapper, updating documentation and dropping the ancillary script. Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 3 +- Documentation/doc-guide/kernel-doc.rst | 29 ++++----- Makefile | 2 +- scripts/split-man.pl | 28 --------- tools/docs/sphinx-build-wrapper | 81 ++++++++++++++++++++++++-- 5 files changed, 95 insertions(+), 48 deletions(-) delete mode 100755 scripts/split-man.pl diff --git a/Documentation/Makefile b/Documentation/Makefile index 05397b9d844d..aa42b2cb7030 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -53,7 +53,7 @@ ifeq ($(HAVE_SPHINX),0) else # HAVE_SPHINX =20 # Common documentation targets -infodocs texinfodocs latexdocs epubdocs xmldocs pdfdocs linkcheckdocs: +mandocs infodocs texinfodocs latexdocs epubdocs xmldocs pdfdocs linkcheckd= ocs: $(Q)@$(srctree)/tools/docs/sphinx-pre-install --version-check +$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ \ --sphinxdirs=3D"$(SPHINXDIRS)" --conf=3D"$(SPHINX_CONF)" \ @@ -104,6 +104,7 @@ dochelp: @echo ' htmldocs - HTML' @echo ' texinfodocs - Texinfo' @echo ' infodocs - Info' + @echo ' mandocs - Man pages' @echo ' latexdocs - LaTeX' @echo ' pdfdocs - PDF' @echo ' epubdocs - EPUB' diff --git a/Documentation/doc-guide/kernel-doc.rst b/Documentation/doc-gui= de/kernel-doc.rst index af9697e60165..4370cc8fbcf5 100644 --- a/Documentation/doc-guide/kernel-doc.rst +++ b/Documentation/doc-guide/kernel-doc.rst @@ -579,20 +579,23 @@ source. How to use kernel-doc to generate man pages ------------------------------------------- =20 -If you just want to use kernel-doc to generate man pages you can do this -from the kernel git tree:: +To generate man pages for all files that contain kernel-doc markups, run:: =20 - $ scripts/kernel-doc -man \ - $(git grep -l '/\*\*' -- :^Documentation :^tools) \ - | scripts/split-man.pl /tmp/man + $ make mandocs =20 -Some older versions of git do not support some of the variants of syntax f= or -path exclusion. One of the following commands may work for those versions= :: +Or calling ``script-build-wrapper`` directly:: =20 - $ scripts/kernel-doc -man \ - $(git grep -l '/\*\*' -- . ':!Documentation' ':!tools') \ - | scripts/split-man.pl /tmp/man + $ ./tools/docs/sphinx-build-wrapper mandocs =20 - $ scripts/kernel-doc -man \ - $(git grep -l '/\*\*' -- . ":(exclude)Documentation" ":(exclude)tools"= ) \ - | scripts/split-man.pl /tmp/man +The output will be at ``/man`` directory inside the output directory +(by default: ``Documentation/output``). + +Optionally, it is possible to generate a partial set of man pages by +using SPHINXDIRS: + + $ make SPHINXDIRS=3Ddriver-api/media mandocs + +.. note:: + + When SPHINXDIRS=3D{subdir} is used, it will only generate man pages for + the files explicitly inside a ``Documentation/{subdir}/.../*.rst`` file. diff --git a/Makefile b/Makefile index 6bfe776bf3c5..9bd44afeda26 100644 --- a/Makefile +++ b/Makefile @@ -1800,7 +1800,7 @@ $(help-board-dirs): help-%: # Documentation targets # ------------------------------------------------------------------------= --- DOC_TARGETS :=3D xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ - linkcheckdocs dochelp refcheckdocs texinfodocs infodocs + linkcheckdocs dochelp refcheckdocs texinfodocs infodocs mandocs PHONY +=3D $(DOC_TARGETS) $(DOC_TARGETS): $(Q)$(MAKE) $(build)=3DDocumentation $@ diff --git a/scripts/split-man.pl b/scripts/split-man.pl deleted file mode 100755 index 96bd99dc977a..000000000000 --- a/scripts/split-man.pl +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env perl -# SPDX-License-Identifier: GPL-2.0 -# -# Author: Mauro Carvalho Chehab -# -# Produce manpages from kernel-doc. -# See Documentation/doc-guide/kernel-doc.rst for instructions - -if ($#ARGV < 0) { - die "where do I put the results?\n"; -} - -mkdir $ARGV[0],0777; -$state =3D 0; -while () { - if (/^\.TH \"[^\"]*\" 9 \"([^\"]*)\"/) { - if ($state =3D=3D 1) { close OUT } - $state =3D 1; - $fn =3D "$ARGV[0]/$1.9"; - print STDERR "Creating $fn\n"; - open OUT, ">$fn" or die "can't open $fn: $!\n"; - print OUT $_; - } elsif ($state !=3D 0) { - print OUT $_; - } -} - -close OUT; diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 8d1f77c4a880..7a6eb41837e6 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -47,12 +47,14 @@ the newer version. import argparse import locale import os +import re import shlex import shutil import subprocess import sys =20 from concurrent import futures +from glob import glob =20 from lib.python_version import PythonVersion from lib.latex_fonts import LatexFontChecker @@ -77,6 +79,7 @@ TARGETS =3D { "epubdocs": { "builder": "epub", "out_dir": "epub" }, "texinfodocs": { "builder": "texinfo", "out_dir": "texinfo" }, "infodocs": { "builder": "texinfo", "out_dir": "texinfo" }, + "mandocs": { "builder": "man", "out_dir": "man" }, "latexdocs": { "builder": "latex", "out_dir": "latex" }, "pdfdocs": { "builder": "latex", "out_dir": "latex" }, "xmldocs": { "builder": "xml", "out_dir": "xml" }, @@ -503,6 +506,71 @@ class SphinxBuilder: except subprocess.CalledProcessError as e: sys.exit(f"Error generating info docs: {e}") =20 + def handle_man(self, kerneldoc, docs_dir, src_dir, output_dir): + """ + Create man pages from kernel-doc output + """ + + re_kernel_doc =3D re.compile(r"^\.\.\s+kernel-doc::\s*(\S+)") + re_man =3D re.compile(r'^\.TH "[^"]*" (\d+) "([^"]*)"') + + if docs_dir =3D=3D src_dir: + # + # Pick the entire set of kernel-doc markups from the entire tr= ee + # + kdoc_files =3D set([self.srctree]) + else: + kdoc_files =3D set() + + for fname in glob(os.path.join(src_dir, "**"), recursive=3DTru= e): + if os.path.isfile(fname) and fname.endswith(".rst"): + with open(fname, "r", encoding=3D"utf-8") as in_fp: + data =3D in_fp.read() + + for line in data.split("\n"): + match =3D re_kernel_doc.match(line) + if match: + if os.path.isfile(match.group(1)): + kdoc_files.add(match.group(1)) + + if not kdoc_files: + sys.exit(f"Directory {src_dir} doesn't contain kernel-doc = tags") + + cmd =3D [ kerneldoc, "-m" ] + sorted(kdoc_files) + try: + if self.verbose: + print(" ".join(cmd)) + + result =3D subprocess.run(cmd, stdout=3Dsubprocess.PIPE, text= =3D True) + + if result.returncode: + print(f"Warning: kernel-doc returned {result.returncode} w= arnings") + + except (OSError, ValueError, subprocess.SubprocessError) as e: + sys.exit(f"Failed to create man pages for {src_dir}: {repr(e)}= ") + + fp =3D None + try: + for line in result.stdout.split("\n"): + match =3D re_man.match(line) + if not match: + if fp: + fp.write(line + '\n') + continue + + if fp: + fp.close() + + fname =3D f"{output_dir}/{match.group(2)}.{match.group(1)}" + + if self.verbose: + print(f"Creating {fname}") + fp =3D open(fname, "w", encoding=3D"utf-8") + fp.write(line + '\n') + finally: + if fp: + fp.close() + def cleandocs(self, builder): # pylint: disable=3DW0613 """Remove documentation output directory""" shutil.rmtree(self.builddir, ignore_errors=3DTrue) @@ -531,7 +599,7 @@ class SphinxBuilder: # Other targets require sphinx-build, so check if it exists # sphinxbuild =3D shutil.which(self.sphinxbuild, path=3Dself.env["PA= TH"]) - if not sphinxbuild: + if not sphinxbuild and target !=3D "mandocs": sys.exit(f"Error: {self.sphinxbuild} not found in PATH.\n") =20 if builder =3D=3D "latex": @@ -619,10 +687,13 @@ class SphinxBuilder: output_dir, ] =20 - try: - self.run_sphinx(sphinxbuild, build_args, env=3Dself.env) - except (OSError, ValueError, subprocess.SubprocessError) as e: - sys.exit(f"Build failed: {repr(e)}") + if target =3D=3D "mandocs": + self.handle_man(kerneldoc, docs_dir, src_dir, output_dir) + else: + try: + self.run_sphinx(sphinxbuild, build_args, env=3Dself.en= v) + except (OSError, ValueError, subprocess.SubprocessError) a= s e: + sys.exit(f"Build failed: {repr(e)}") =20 # # Ensure that each html/epub output will have needed static fi= les --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 D5A2B371EAF; Wed, 17 Sep 2025 12:15:56 +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=1758111356; cv=none; b=NqOlXbF4z1MRMjRHNCmVTRiZZknVM6fOJIumKgYAQVFBc9+SYGg5DW4vNq/Fq8tRbXj2/530LDsDKL/A12098KVnYlE+AHOo8S09VA2utggvi8fpE6c8GFL+UQH4dPOxTh2Au1V+xTfu/luWjKqSvJfw9i+1b+LBNIkCr4nVsYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111356; c=relaxed/simple; bh=bNOmw1tzFH8Sl7kR3p+wUYP6U5+a6FHYIcsXQNkIydI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZIIUVOznDP3RT/8RWO7Y3mWRq9m8vvmtS1BidvMI0Hw5QJcNFoCC7Ac4R66VybQCEKfr9jZ7zTMb+YW46SKbl3gMu1O2FsSbvSSRCpnUZPkMFCBMbW//0pXpNYwshKYC4y75rwcog0bD6ZvTGlIejJgespJvRlvVgKVqBXFK+rM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jbPoNrMK; 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="jbPoNrMK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83037C19422; Wed, 17 Sep 2025 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111356; bh=bNOmw1tzFH8Sl7kR3p+wUYP6U5+a6FHYIcsXQNkIydI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbPoNrMKn1gSfxlY36zJAHXYIUfCUJDeVVvWAhIFQYCrdjO7KBRubv7DJqBODQG6x ifnvCcTkAaO3Gh2aPLIkWOFQ7pP8auVp/KiVU+T5E7w/tUKR6Wo3bMbcuevEsw/0uP JU5C6QGDrTOJFlKxIVUhm3dqQyiBpLSUs99w/xVKAQncuGGpZyrdgCNNgG3f55uxYq 8P01LwaLHH8ZdulLmXcBUXdvGiUaZKpPuHNFbiDcQMBt2UPMOeOaDRFoc6MUCbl7R2 2rMGJbyZoDksWXhvV602xkLmLb7DpPFXUtV5EG4t6BvJVoHlcCzZ8656m0/97Xocue OAYa+3vfkcN+g== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGeS-2Q88; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 20/24] tools: kernel-doc: add a see also section at man pages Date: Wed, 17 Sep 2025 14:15:14 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab While cross-references are complex, as related ones can be on different files, we can at least correlate the ones that belong to the same file, adding a SEE ALSO section for them. The result is not bad. See for instance: $ tools/docs/sphinx-build-wrapper --sphinxdirs driver-api/media -- mandocs $ man Documentation/output/driver-api/man/edac_pci_add_device.9 edac_pci_add_device(9) Kernel Hacker's Manual edac_pci_add_device(9) NAME edac_pci_add_device - Insert the 'edac_dev' structure into the edac_pci global list and create sysfs entries associated with edac_pci structure. SYNOPSIS int edac_pci_add_device (struct edac_pci_ctl_info *pci , int edac_idx ); ARGUMENTS pci pointer to the edac_device structure to be added to the list edac_idx A unique numeric identifier to be assigned to the RETURN 0 on Success, or an error code on failure SEE ALSO edac_pci_alloc_ctl_info(9), edac_pci_free_ctl_info(9), edac_pci_alloc_index(9), edac_pci_del_device(9), edac_pci_cre=E2= =80=90 ate_generic_ctl(9), edac_pci_release_generic_ctl(9), edac_pci_create_sysfs(9), edac_pci_remove_sysfs(9) August 2025 edac_pci_add_device edac_pci_add_device(9) Signed-off-by: Mauro Carvalho Chehab --- scripts/lib/kdoc/kdoc_files.py | 5 +- scripts/lib/kdoc/kdoc_output.py | 84 +++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/scripts/lib/kdoc/kdoc_files.py b/scripts/lib/kdoc/kdoc_files.py index 9e09b45b02fa..061c033f32da 100644 --- a/scripts/lib/kdoc/kdoc_files.py +++ b/scripts/lib/kdoc/kdoc_files.py @@ -275,7 +275,10 @@ class KernelFiles(): self.config.log.warning("No kernel-doc for file %s", fname) continue =20 - for arg in self.results[fname]: + symbols =3D self.results[fname] + self.out_style.set_symbols(symbols) + + for arg in symbols: m =3D self.out_msg(fname, arg.name, arg) =20 if m is None: diff --git a/scripts/lib/kdoc/kdoc_output.py b/scripts/lib/kdoc/kdoc_output= .py index ea8914537ba0..1eca9a918558 100644 --- a/scripts/lib/kdoc/kdoc_output.py +++ b/scripts/lib/kdoc/kdoc_output.py @@ -215,6 +215,9 @@ class OutputFormat: =20 # Virtual methods to be overridden by inherited classes # At the base class, those do nothing. + def set_symbols(self, symbols): + """Get a list of all symbols from kernel_doc""" + def out_doc(self, fname, name, args): """Outputs a DOC block""" =20 @@ -577,6 +580,7 @@ class ManFormat(OutputFormat): =20 super().__init__() self.modulename =3D modulename + self.symbols =3D [] =20 dt =3D None tstamp =3D os.environ.get("KBUILD_BUILD_TIMESTAMP") @@ -593,6 +597,68 @@ class ManFormat(OutputFormat): =20 self.man_date =3D dt.strftime("%B %Y") =20 + def arg_name(self, args, name): + """ + Return the name that will be used for the man page. + + As we may have the same name on different namespaces, + prepend the data type for all types except functions and typedefs. + + The doc section is special: it uses the modulename. + """ + + dtype =3D args.type + + if dtype =3D=3D "doc": + return self.modulename + + if dtype in ["function", "typedef"]: + return name + + return f"{dtype} {name}" + + def set_symbols(self, symbols): + """ + Get a list of all symbols from kernel_doc. + + Man pages will uses it to add a SEE ALSO section with other + symbols at the same file. + """ + self.symbols =3D symbols + + def out_tail(self, fname, name, args): + """Adds a tail for all man pages""" + + # SEE ALSO section + if len(self.symbols) >=3D 2: + cur_name =3D self.arg_name(args, name) + + self.data +=3D f'.SH "SEE ALSO"' + "\n.PP\n" + related =3D [] + for arg in self.symbols: + out_name =3D self.arg_name(arg, arg.name) + + if cur_name =3D=3D out_name: + continue + + related.append(f"\\fB{out_name}\\fR(9)") + + self.data +=3D ",\n".join(related) + "\n" + + # TODO: does it make sense to add other sections? Maybe + # REPORTING ISSUES? LICENSE? + + def msg(self, fname, name, args): + """ + Handles a single entry from kernel-doc parser. + + Add a tail at the end of man pages output. + """ + super().msg(fname, name, args) + self.out_tail(fname, name, args) + + return self.data + def output_highlight(self, block): """ Outputs a C symbol that may require being highlighted with @@ -618,7 +684,9 @@ class ManFormat(OutputFormat): if not self.check_doc(name, args): return =20 - self.data +=3D f'.TH "{self.modulename}" 9 "{self.modulename}" "{s= elf.man_date}" "API Manual" LINUX' + "\n" + out_name =3D self.arg_name(args, name) + + self.data +=3D f'.TH "{self.modulename}" 9 "{out_name}" "{self.man= _date}" "API Manual" LINUX' + "\n" =20 for section, text in args.sections.items(): self.data +=3D f'.SH "{section}"' + "\n" @@ -627,7 +695,9 @@ class ManFormat(OutputFormat): def out_function(self, fname, name, args): """output function in man""" =20 - self.data +=3D f'.TH "{name}" 9 "{name}" "{self.man_date}" "Kernel= Hacker\'s Manual" LINUX' + "\n" + out_name =3D self.arg_name(args, name) + + self.data +=3D f'.TH "{name}" 9 "{out_name}" "{self.man_date}" "Ke= rnel Hacker\'s Manual" LINUX' + "\n" =20 self.data +=3D ".SH NAME\n" self.data +=3D f"{name} \\- {args['purpose']}\n" @@ -671,7 +741,9 @@ class ManFormat(OutputFormat): self.output_highlight(text) =20 def out_enum(self, fname, name, args): - self.data +=3D f'.TH "{self.modulename}" 9 "enum {name}" "{self.ma= n_date}" "API Manual" LINUX' + "\n" + out_name =3D self.arg_name(args, name) + + self.data +=3D f'.TH "{self.modulename}" 9 "{out_name}" "{self.man= _date}" "API Manual" LINUX' + "\n" =20 self.data +=3D ".SH NAME\n" self.data +=3D f"enum {name} \\- {args['purpose']}\n" @@ -703,8 +775,9 @@ class ManFormat(OutputFormat): def out_typedef(self, fname, name, args): module =3D self.modulename purpose =3D args.get('purpose') + out_name =3D self.arg_name(args, name) =20 - self.data +=3D f'.TH "{module}" 9 "{name}" "{self.man_date}" "API = Manual" LINUX' + "\n" + self.data +=3D f'.TH "{module}" 9 "{out_name}" "{self.man_date}" "= API Manual" LINUX' + "\n" =20 self.data +=3D ".SH NAME\n" self.data +=3D f"typedef {name} \\- {purpose}\n" @@ -717,8 +790,9 @@ class ManFormat(OutputFormat): module =3D self.modulename purpose =3D args.get('purpose') definition =3D args.get('definition') + out_name =3D self.arg_name(args, name) =20 - self.data +=3D f'.TH "{module}" 9 "{args.type} {name}" "{self.man_= date}" "API Manual" LINUX' + "\n" + self.data +=3D f'.TH "{module}" 9 "{out_name}" "{self.man_date}" "= API Manual" LINUX' + "\n" =20 self.data +=3D ".SH NAME\n" self.data +=3D f"{args.type} {name} \\- {purpose}\n" --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 5ADE031A7ED; Wed, 17 Sep 2025 12:15:55 +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=1758111355; cv=none; b=E9giHM9dWDew0BfWgFh/k1JSeglfHpxZ7fKJb07TmiWa6mJXLkrn6tolF2lunIkpc/DmE304HtXkQCW3IAgwX2iQW5FmUvsCWJ0w6M9fWdInG8zin41c9qw4RFigD+Znr10ctxuUoxWoiDArMOZp8IigRZu24soFwOjxV0vgWoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=4Yu1gA5/uZ+OPBNEREkXam+9wN35SUbcDazI/2U7I9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mu6vw0fzqI4adn3a1ygVAQ70feZCRVATfuvFMKSsCSSuNGt8jwfmEORdK7d50bJGgU3V4oQCCgRa7X7vOeJEf8aThk3jUHANK3vO82HxSh2Z+CYH7QbKH4SRqlLkkKRQtkH2pOUHmmOKuY88YSpzSkKlDsjszwDq8iqKuE31ETU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DuSPDP2u; 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="DuSPDP2u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35ABBC4CEF5; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=4Yu1gA5/uZ+OPBNEREkXam+9wN35SUbcDazI/2U7I9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DuSPDP2uz1S6Ah3lzir9ox5agDWER2+Br02ozMoLiMMv0o29AKGdXrioJo1zAQunT dmByOx7XFTteRsralZHWyujQwCtDF/NjbAOwi+B/7MVQM2NCoawVK6ZuzSSqESW15+ jmfINvCB36t7CZCRNCe63Jf/exL08BYsI0LhLGZe4ZdVBKGOVtHL/zMoGi2qW0sf99 KxlqYAakLN1ZbRSE5C2TBvYK3vlcXXhLaTr+aaAeVd1xnFhP5zPdPfgkn+z9VmdsUp 7aqxUTJdAxVL+PXB/JIUPd8d2EXdu28gfwSc5vLO0jIg2jklhb4jG6lsFI++eNIDwy yaDR32QMRIGJQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGeW-2XQS; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 21/24] scripts: kdoc_parser.py: warn about Python version only once Date: Wed, 17 Sep 2025 14:15:15 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 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" When running kernel-doc over multiple documents, it emits one error message per file with is not what we want: $ python3.6 scripts/kernel-doc.py . --none ... Warning: ./include/trace/events/swiotlb.h:0 Python 3.7 or later is require= d for correct results Warning: ./include/trace/events/iommu.h:0 Python 3.7 or later is required = for correct results Warning: ./include/trace/events/sock.h:0 Python 3.7 or later is required f= or correct results ... Change the logic to warn it only once at the library: $ python3.6 scripts/kernel-doc.py . --none Warning: Python 3.7 or later is required for correct results Warning: ./include/cxl/features.h:0 Python 3.7 or later is required for co= rrect results When running from command line, it warns twice, but that sounds ok. Signed-off-by: Mauro Carvalho Chehab --- scripts/lib/kdoc/kdoc_parser.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser= .py index a560546c1867..574972e1f741 100644 --- a/scripts/lib/kdoc/kdoc_parser.py +++ b/scripts/lib/kdoc/kdoc_parser.py @@ -314,6 +314,7 @@ class KernelEntry: self.section =3D SECTION_DEFAULT self._contents =3D [] =20 +python_warning =3D False =20 class KernelDoc: """ @@ -347,9 +348,13 @@ class KernelDoc: # We need Python 3.7 for its "dicts remember the insertion # order" guarantee # - if sys.version_info.major =3D=3D 3 and sys.version_info.minor < 7: + global python_warning + if (not python_warning and + sys.version_info.major =3D=3D 3 and sys.version_info.minor < 7= ): + self.emit_msg(0, 'Python 3.7 or later is required for correct res= ults') + python_warning =3D True =20 def emit_msg(self, ln, msg, warning=3DTrue): """Emit a message""" --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 C94DC31A814; Wed, 17 Sep 2025 12:15:55 +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=1758111355; cv=none; b=o3HqGdFpto+faHg2vPz1esloirWXkmyVpmIgf8KDVfZmLam5DTKFnDY9E+zAsxnGUo77UqeREcYYz8VWlj2Ca5l1/ULSfVnjfg2CJk2xTqDGE1G2qDIEG/1KYlMsAUNtWHZqw/tLu90ZLAtnC33C50ypmYslSCQJ2NJCCi1IEmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=lrdZawkRIwStzU2yfc2G77xAk+2MIGzDv7SZmR0L4QE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RaTvxys1BOFkCEM2+hrISJWJd5ucEkChilbjaMOoMnTkLeFid89fvpQw8G+E8/+erxMwPe6WWXWECeYqBSfNNpv/fbcfEJdu18e40a+rLsBPhj769luD31bz6S69SsYbpRaVOFQXLFQZauX5wZa4GmjE+5S0c742TSWbbxcZoAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lBrbbbIS; 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="lBrbbbIS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ED8FC4AF0B; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=lrdZawkRIwStzU2yfc2G77xAk+2MIGzDv7SZmR0L4QE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lBrbbbIScd0kAq84yYc3uTrivnTKTe4chMBtWl1x7zkjAEyU1OTe5QsgRXtHn598Z 1Wgm+gT/bQdwkKdgNpPIDf0LfGqYzDKmsq4BHqvRJ8HmlB6EQXZfgxoGUiZyWGLldR ZjvfA+jloScArCXlAG4OQ8aHVLuE6wmv2/zwRERwjTROceLA4knbwRP+pNiAHAb5Vx WH8hNMneGwlzwxlE9gBcPAdrf/E4lNc23WaahnoMaMvWVXDxkLUEIQqiv85HSxyW9W /KNJYh7u7VlR97dG5gUE6P8aOYUkU4xEvpZJK/3/5B4F0fSO1T01qLGEv4DlEyC1/C 1UlBs6GWoyCCw== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGea-2ezA; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , "Mauro Carvalho Chehab" , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , Bill Wendling , Boqun Feng , Danilo Krummrich , Gary Guo , Justin Stitt , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Trevor Gross , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, rust-for-linux@vger.kernel.org Subject: [PATCH v7 22/24] tools/docs: sphinx-build-wrapper: move rust doc builder to wrapper Date: Wed, 17 Sep 2025 14:15:16 +0200 Message-ID: <6794e21fda3158c1d7d385a2e61df2354d42ce54.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Simplify even further the docs Makefile by moving rust build logic to the wrapper. After this change, running make on an environment with rust enabled works as expected. With CONFIG_RUST: $ make O=3D/tmp/foo LLVM=3D1 SPHINXDIRS=3Dpeci htmldocs make[1]: Entrando no diret=C3=B3rio '/tmp/foo' Using alabaster theme Using Python kernel-doc GEN Makefile DESCEND objtool CC arch/x86/kernel/asm-offsets.s INSTALL libsubcmd_headers CALL /new_devel/docs/scripts/checksyscalls.sh RUSTC L rust/core.o BINDGEN rust/bindings/bindings_generated.rs BINDGEN rust/bindings/bindings_helpers_generated.rs ... Without it: $ make SPHINXDIRS=3Dpeci htmldocs Using alabaster theme Using Python kernel-doc Both work as it is it is supposed to do. After the change, it is also possible to build directly with the script by passing "--rustodoc". if CONFIG_RUST, this works fine: $ ./tools/docs/sphinx-build-wrapper --sphinxdirs peci --rustdoc -- html= docs Using alabaster theme Using Python kernel-doc SYNC include/config/auto.conf ... RUSTC L rust/core.o ... If not, it will produce a warning that RUST may be disabled: $ ./tools/docs/sphinx-build-wrapper --sphinxdirs peci --rustdoc -- html= docs Using alabaster theme Using Python kernel-doc *** *** Configuration file ".config" not found! *** *** Please run some configurator (e.g. "make oldconfig" or *** "make menuconfig" or "make xconfig"). *** make[1]: *** [/new_devel/docs/Makefile:829: .config] Error 1 make: *** [Makefile:248: __sub-make] Error 2 Ignored errors when building rustdoc: Command '['make', 'LLVM=3D1', 'ru= stdoc']' returned non-zero exit status 2.. Is RUST enabled? Signed-off-by: Mauro Carvalho Chehab --- Documentation/Makefile | 29 +++++----------- tools/docs/sphinx-build-wrapper | 59 ++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Documentation/Makefile b/Documentation/Makefile index aa42b2cb7030..b32f68387dfc 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -23,6 +23,7 @@ SPHINXOPTS =3D SPHINXDIRS =3D . DOCS_THEME =3D DOCS_CSS =3D +RUSTDOC =3D SPHINX_CONF =3D conf.py PAPER =3D BUILDDIR =3D $(obj)/output @@ -42,6 +43,10 @@ FONTS_CONF_DENY_VF ?=3D $(HOME)/deny-vf # User-friendly check for sphinx-build HAVE_SPHINX :=3D $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then ech= o 1; else echo 0; fi) =20 +ifeq ($(CONFIG_RUST),y) + RUSTDOC=3D"--rustdoc" +endif + ifeq ($(HAVE_SPHINX),0) =20 .DEFAULT: @@ -53,10 +58,10 @@ ifeq ($(HAVE_SPHINX),0) else # HAVE_SPHINX =20 # Common documentation targets -mandocs infodocs texinfodocs latexdocs epubdocs xmldocs pdfdocs linkcheckd= ocs: +htmldocs mandocs infodocs texinfodocs latexdocs epubdocs xmldocs pdfdocs l= inkcheckdocs: $(Q)@$(srctree)/tools/docs/sphinx-pre-install --version-check - +$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ \ - --sphinxdirs=3D"$(SPHINXDIRS)" --conf=3D"$(SPHINX_CONF)" \ + +$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ $(RUSTDOC)\ + --sphinxdirs=3D"$(SPHINXDIRS)" --conf=3D"$(SPHINX_CONF)" $(RUSTDOC)\ --builddir=3D"$(BUILDDIR)" --deny-vf=3D$(FONTS_CONF_DENY_VF) \ --theme=3D$(DOCS_THEME) --css=3D$(DOCS_CSS) --paper=3D$(PAPER) =20 @@ -67,24 +72,6 @@ pdfdocs: @echo " SKIP Sphinx $@ target." endif =20 -# HTML main logic is identical to other targets. However, if rust is enabl= ed, -# an extra step at the end is required to generate rustdoc. -htmldocs: - $(Q)@$(srctree)/tools/docs/sphinx-pre-install --version-check - +$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ \ - --sphinxdirs=3D"$(SPHINXDIRS)" --conf=3D"$(SPHINX_CONF)" \ - --builddir=3D"$(BUILDDIR)" \ - --theme=3D$(DOCS_THEME) --css=3D$(DOCS_CSS) --paper=3D$(PAPER) -# If Rust support is available and .config exists, add rustdoc generated c= ontents. -# If there are any, the errors from this make rustdoc will be displayed but -# won't stop the execution of htmldocs - -ifneq ($(wildcard $(srctree)/.config),) -ifeq ($(CONFIG_RUST),y) - $(Q)$(MAKE) rustdoc || true -endif -endif - endif # HAVE_SPHINX =20 # The following targets are independent of HAVE_SPHINX, and the rules shou= ld diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 7a6eb41837e6..e24486dede76 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -96,14 +96,6 @@ class SphinxBuilder: with the Kernel. """ =20 - def is_rust_enabled(self): - """Check if rust is enabled at .config""" - config_path =3D os.path.join(self.srctree, ".config") - if os.path.isfile(config_path): - with open(config_path, "r", encoding=3D"utf-8") as f: - return "CONFIG_RUST=3Dy" in f.read() - return False - def get_path(self, path, use_cwd=3DFalse, abs_path=3DFalse): """ Ancillary routine to handle patches the right way, as shell does. @@ -218,8 +210,6 @@ class SphinxBuilder: "scripts/kernel-doc.= py")) self.builddir =3D self.get_path(builddir, use_cwd=3DTrue, abs_path= =3DTrue) =20 - self.config_rust =3D self.is_rust_enabled() - # # Get directory locations for LaTeX build toolchain # @@ -274,7 +264,7 @@ class SphinxBuilder: =20 return subprocess.call(cmd, *args, **pwargs) =20 - def handle_html(self, css, output_dir): + def handle_html(self, css, output_dir, rustdoc): """ Extra steps for HTML and epub output. =20 @@ -282,20 +272,34 @@ class SphinxBuilder: copied to the output _static directory """ =20 - if not css: - return + if css: + css =3D os.path.expanduser(css) + if not css.startswith("/"): + css =3D os.path.join(self.srctree, css) =20 - css =3D os.path.expanduser(css) - if not css.startswith("/"): - css =3D os.path.join(self.srctree, css) + static_dir =3D os.path.join(output_dir, "_static") + os.makedirs(static_dir, exist_ok=3DTrue) =20 - static_dir =3D os.path.join(output_dir, "_static") - os.makedirs(static_dir, exist_ok=3DTrue) + try: + shutil.copy2(css, static_dir) + except (OSError, IOError) as e: + print(f"Warning: Failed to copy CSS: {e}", file=3Dsys.stde= rr) =20 - try: - shutil.copy2(css, static_dir) - except (OSError, IOError) as e: - print(f"Warning: Failed to copy CSS: {e}", file=3Dsys.stderr) + if rustdoc: + if "MAKE" in self.env: + cmd =3D [self.env["MAKE"]] + else: + cmd =3D ["make", "LLVM=3D1"] + + cmd +=3D [ "rustdoc"] + if self.verbose: + print(" ".join(cmd)) + + try: + subprocess.run(cmd, check=3DTrue) + except subprocess.CalledProcessError as e: + print(f"Ignored errors when building rustdoc: {e}. Is RUST= enabled?", + file=3Dsys.stderr) =20 def build_pdf_file(self, latex_cmd, from_dir, path): """Builds a single pdf file using latex_cmd""" @@ -576,7 +580,7 @@ class SphinxBuilder: shutil.rmtree(self.builddir, ignore_errors=3DTrue) =20 def build(self, target, sphinxdirs=3DNone, conf=3D"conf.py", - theme=3DNone, css=3DNone, paper=3DNone, deny_vf=3DNone): + theme=3DNone, css=3DNone, paper=3DNone, deny_vf=3DNone, rust= doc=3DFalse): """ Build documentation using Sphinx. This is the core function of this module. It prepares all arguments required by sphinx-build. @@ -623,7 +627,7 @@ class SphinxBuilder: =20 args.extend(["-D", f"latex_elements.papersize=3D{paper}paper"]) =20 - if self.config_rust: + if rustdoc: args.extend(["-t", "rustdoc"]) =20 if conf: @@ -699,7 +703,7 @@ class SphinxBuilder: # Ensure that each html/epub output will have needed static fi= les # if target in ["htmldocs", "epubdocs"]: - self.handle_html(css, output_dir) + self.handle_html(css, output_dir, rustdoc) =20 # # Step 2: Some targets (PDF and info) require an extra step once @@ -756,6 +760,9 @@ def main(): parser.add_argument('--deny-vf', help=3D"Configuration to deny variable fonts on pd= f builds") =20 + parser.add_argument('--rustdoc', action=3D"store_true", + help=3D"Enable rustdoc build. Requires CONFIG_RUST= ") + parser.add_argument("-v", "--verbose", action=3D'store_true', help=3D"place build in verbose mode") =20 @@ -775,7 +782,7 @@ def main(): =20 builder.build(args.target, sphinxdirs=3Dargs.sphinxdirs, conf=3Dargs.c= onf, theme=3Dargs.theme, css=3Dargs.css, paper=3Dargs.paper, - deny_vf=3Dargs.deny_vf) + rustdoc=3Dargs.rustdoc, deny_vf=3Dargs.deny_vf) =20 if __name__ =3D=3D "__main__": main() --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 8C53931A7FE; Wed, 17 Sep 2025 12:15:55 +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=1758111355; cv=none; b=J/YwXAI+cEHWAJnwpODfpWQ6Zrou15+nYLU95aV6SyRCUoxzEL6yu6Dt94burMxxCQ9g5gYpCHF6/UcG2rwFP/EP90riYzYU8X27I0G5gUHp5+kr1SO+o8RyoZvfEiuBTsYYAAKs0pKeD7OYnTdgF9+eJX0YqF9YN9Xzs0FrHm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=xi6aaKetpX4fDfqLRLgmvyJ++GISVlfrcSwACNlUxeU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hBsnac4hQY2lmnJxHclK9THSiFp03BuDffgCjInscxBnZEBsw5ltSc+Y4h1+M1L9OonxFin34rEs+a4nk1crBHqTTTRBtkHPqfi5sC2Dbf/Fv9ekTKRASg2Xw6sba7vC/UeOc3nbHh+VQw4kxYchRVH8IK9vCezXwLFqirJtblU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ubxjd3Rt; 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="ubxjd3Rt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33346C4CEFB; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=xi6aaKetpX4fDfqLRLgmvyJ++GISVlfrcSwACNlUxeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ubxjd3RtVhTUrp69IIre1zcMwuzT3PV8wJf44Cm7SdfKbHBdqMhd5O+ilgXBPRDAY G0gEKSaHI+v2UoCxcYkFaX9OKzm6JsE9bpvkPO87A06oR9mcuvkz859Mnuwysbu7nf T2NrM5w9XTl+hyLRcM43Km/5vhXmEQVah1WJhKyOXTjLJnB8cCQpAUTRjUXnQyG14U gNHUranFt2MwvbJgNEsysZhqLNM2ZgZRnQKN0pnTZ2XwZ4tfd6PwbKowq3wFMVkMGm 8Wsz7JVbv5k5y64p5bQOUOszo7M04Dqg5rQ6JMFLokIpCQplZrcyOsUwO/5Ux7gM4B VA3yiLLdfWl2w== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGee-2ma4; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , "Mauro Carvalho Chehab" , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , Boqun Feng , Danilo Krummrich , Gary Guo , Miguel Ojeda , Trevor Gross , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH v7 23/24] tools/docs: sphinx-* break documentation bulds on openSUSE Date: Wed, 17 Sep 2025 14:15:17 +0200 Message-ID: <43c10221cc1a6ccd0b7b84fc8ffc92ff02d7d0fb.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" Before this patch, building htmldocs on opensuseLEAP works fine: # make htmldocs Available Python versions: /usr/bin/python3.11 Python 3.6.15 not supported. Changing to /usr/bin/python3.11 Python 3.6.15 not supported. Changing to /usr/bin/python3.11 Using alabaster theme Using Python kernel-doc ... As the logic detects that Python 3.6 is too old and recommends intalling python311-Sphinx. If installed, documentation builds work like a charm. Yet, some develpers complained that running python3.11 instead of python3 should not happen. So, let's break the build to make them happier: $ make htmldocs Python 3.6.15 not supported. Bailing out You could run, instead: /usr/bin/python3.11 tools/docs/sphinx-build-wrapper htmldocs \ --sphinxdirs=3D. --conf=3Dconf.py --builddir=3DDocumentation/output= --theme=3D --css=3D \ --paper=3D Python 3.6.15 not supported. Bailing out make[2]: *** [Documentation/Makefile:76: htmldocs] Error 1 make[1]: *** [Makefile:1806: htmldocs] Error 2 make: *** [Makefile:248: __sub-make] Error 2 It should be noticed that: 1. after this change, sphinx-pre-install needs to be called by hand: $ /usr/bin/python3.11 tools/docs/sphinx-pre-install Detected OS: openSUSE Leap 15.6. Sphinx version: 7.2.6 All optional dependencies are met. Needed package dependencies are met. 2. sphinx-build-wrapper will auto-detect python3.11 and suggest a way to build the docs using the parameters passed via make variables. In this specific example: /usr/bin/python3.11 tools/docs/sphinx-build-wrapper htmldocs --sphinxdir= s=3D. --conf=3Dconf.py --theme=3D --css=3D --paper=3D 3. As this needs to be executed outside docs Makefile, it won't run the validation check scripts nor build Rust documentation if enabled, as the extra scripts are part of the docs Makefile. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/lib/python_version.py | 28 ++++++++++++++++++++++++---- tools/docs/sphinx-build-wrapper | 3 ++- tools/docs/sphinx-pre-install | 3 ++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/docs/lib/python_version.py b/tools/docs/lib/python_versi= on.py index a9fda2470a26..4fde1b882164 100644 --- a/tools/docs/lib/python_version.py +++ b/tools/docs/lib/python_version.py @@ -20,9 +20,11 @@ Python version if present. import os import re import subprocess +import shlex import sys =20 from glob import glob +from textwrap import indent =20 class PythonVersion: """ @@ -44,6 +46,25 @@ class PythonVersion: """Returns a version tuple as major.minor.patch""" return ".".join([str(x) for x in version]) =20 + @staticmethod + def cmd_print(cmd, max_len=3D80): + cmd_line =3D [] + + for w in cmd: + w =3D shlex.quote(w) + + if cmd_line: + if not max_len or len(cmd_line[-1]) + len(w) < max_len: + cmd_line[-1] +=3D " " + w + continue + else: + cmd_line[-1] +=3D " \\" + cmd_line.append(w) + else: + cmd_line.append(w) + + return "\n ".join(cmd_line) + def __str__(self): """Returns a version tuple as major.minor.patch from self.version"= "" return self.ver_str(self.version) @@ -130,14 +151,13 @@ class PythonVersion: else: new_python_cmd =3D None =20 - if show_alternatives: + if show_alternatives and available_versions: print("You could run, instead:") for _, cmd in available_versions: args =3D [cmd, script_path] + sys.argv[1:] =20 - cmd_str =3D " ".join(args) - print(f" {cmd_str}") - print() + cmd_str =3D indent(PythonVersion.cmd_print(args), " ") + print(f"{cmd_str}\n") =20 if bail_out: msg =3D f"Python {python_ver} not supported. Bailing out" diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index e24486dede76..103b0044bb0b 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -774,7 +774,8 @@ def main(): =20 args =3D parser.parse_args() =20 - PythonVersion.check_python(MIN_PYTHON_VERSION) + PythonVersion.check_python(MIN_PYTHON_VERSION, show_alternatives=3DTru= e, + bail_out=3DTrue) =20 builder =3D SphinxBuilder(builddir=3Dargs.builddir, verbose=3Dargs.verbose, n_jobs=3Dargs.jobs, diff --git a/tools/docs/sphinx-pre-install b/tools/docs/sphinx-pre-install index 663d4e2a3f57..698989584b6a 100755 --- a/tools/docs/sphinx-pre-install +++ b/tools/docs/sphinx-pre-install @@ -1531,7 +1531,8 @@ def main(): =20 checker =3D SphinxDependencyChecker(args) =20 - PythonVersion.check_python(MIN_PYTHON_VERSION) + PythonVersion.check_python(MIN_PYTHON_VERSION, + bail_out=3DTrue, success_on_error=3DTrue) checker.check_needs() =20 # Call main if not used as module --=20 2.51.0 From nobody Thu Oct 2 11:48:27 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 5E4B831A7EE; Wed, 17 Sep 2025 12:15:55 +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=1758111355; cv=none; b=ksnt/+2YaANtJhh6kDyoRSEfVKY320NOCtH9d73QCX9D5f2bj4YQz/O0CxAPkl4KCDaKyThVKTDFfnhWT2+Yr9ubjdRigYo9ytoDGhB6e/U7rNwmdBCL7uKQ3KhDh5tyuteEg15PBL0cm6FRz8LAnfKzR9Conh0f5bootaFYh90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758111355; c=relaxed/simple; bh=5h0Y2l0VICf3uSdAhL346MOGEeZeAoHZKXVIcjeYSFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DNonKc8OuCR337vSk4mUOpS7PQiy0M6K0REW9Bw9ggUVtU7t9bsCfIWUAHANb++DeOWsPChAGBwOnsFHAAD0LdWp8bl/CZHbigg+lmo84SWqR2qnfm3DWbcLb0UK79zSsm9+0tAdXZGADA2e62rB0NeWnUKfrWQ202G/ZKSBH8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R3KQxy18; 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="R3KQxy18" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DA34C4CEFC; Wed, 17 Sep 2025 12:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758111355; bh=5h0Y2l0VICf3uSdAhL346MOGEeZeAoHZKXVIcjeYSFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R3KQxy18stTFku7K5UzoFyBSpJmbElGYMZjjhl7ncGUbf1p/K6TAiSYrpLYpxBFAs ySYpHUQDNHeyapWE6lpDiq8VVS1eWtIf9oGC5hy9yLrV5NZXJ9cNQXO1/VTIhSUCk8 HJVFaLTWLjTQ9SP01TnmMx5lQxe6/cqwpzHG6QpPCsqBcO74zU3RnVEiAeUDjSxj0l kxDj1tbZf/h+1MDCDICfy31cFX9qUEPfiMOWgRcQXknCFtSsGOwzciEQ4Ilk+qymQU e8u+ZLyVBdKtGWUbETOzQ8Jk65EEElOF0g0ZtBG123/xjMDHJVlLb3C0+2h8kkOMMy y/Sc6L+ax6kbQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uyr4h-0000000CGei-2tcX; Wed, 17 Sep 2025 14:15:51 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org Subject: [PATCH v7 24/24] tools/docs: sphinx-build-wrapper: add support to run inside venv Date: Wed, 17 Sep 2025 14:15:18 +0200 Message-ID: <8372cc28d0f91a133da98c5cb8b005c3dbffdc23.1758111077.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 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" Sometimes, it is desired to run Sphinx from a virtual environment. Add a command line parameter to automatically build Sphinx from such environment. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-build-wrapper | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 103b0044bb0b..6ed3d58ec277 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -69,6 +69,7 @@ from jobserver import JobserverExec # pylint: dis= able=3DC0413,C0411,E0401 # # Some constants # +VENV_DEFAULT =3D "sphinx_latest" MIN_PYTHON_VERSION =3D PythonVersion("3.7").version PAPER =3D ["", "a4", "letter"] =20 @@ -171,8 +172,10 @@ class SphinxBuilder: if not verbose: self.sphinxopts +=3D ["-q"] =20 - def __init__(self, builddir, verbose=3DFalse, n_jobs=3DNone, interacti= ve=3DNone): + def __init__(self, builddir, venv=3DNone, verbose=3DFalse, n_jobs=3DNo= ne, + interactive=3DNone): """Initialize internal variables""" + self.venv =3D venv self.verbose =3D None =20 # @@ -220,6 +223,21 @@ class SphinxBuilder: =20 self.get_sphinx_extra_opts(n_jobs) =20 + # + # If venv command line argument is specified, run Sphinx from venv + # + if venv: + bin_dir =3D os.path.join(venv, "bin") + if not os.path.isfile(os.path.join(bin_dir, "activate")): + sys.exit(f"Venv {venv} not found.") + + # "activate" virtual env + self.env["PATH"] =3D bin_dir + ":" + self.env["PATH"] + self.env["VIRTUAL_ENV"] =3D venv + if "PYTHONHOME" in self.env: + del self.env["PYTHONHOME"] + print(f"Setting venv to {venv}") + def run_sphinx(self, sphinx_build, build_args, *args, **pwargs): """ Executes sphinx-build using current python3 command. @@ -254,7 +272,12 @@ class SphinxBuilder: if self.n_jobs: n_jobs =3D str(self.n_jobs) =20 - cmd =3D [sys.executable, sphinx_build] + if self.venv: + cmd =3D ["python"] + else: + cmd =3D [sys.executable,] + + cmd +=3D [sphinx_build] cmd +=3D [f"-j{n_jobs}"] cmd +=3D self.sphinxopts cmd +=3D build_args @@ -772,12 +795,16 @@ def main(): parser.add_argument('-i', '--interactive', action=3D'store_true', help=3D"Change latex default to run in interactive= mode") =20 + parser.add_argument("-V", "--venv", nargs=3D'?', const=3Df'{VENV_DEFAU= LT}', + default=3DNone, + help=3Df'If used, run Sphinx from a venv dir (defa= ult dir: {VENV_DEFAULT})') + args =3D parser.parse_args() =20 PythonVersion.check_python(MIN_PYTHON_VERSION, show_alternatives=3DTru= e, bail_out=3DTrue) =20 - builder =3D SphinxBuilder(builddir=3Dargs.builddir, + builder =3D SphinxBuilder(builddir=3Dargs.builddir, venv=3Dargs.venv, verbose=3Dargs.verbose, n_jobs=3Dargs.jobs, interactive=3Dargs.interactive) =20 --=20 2.51.0