From nobody Fri Oct 3 06:33:25 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 3F4942BE633; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=VSnY1/QdrM32Qr0FpJ/swbN4C+5qZWVZw0A+Wnewku50Dp5uy6fCN0Wsip3T1vECdNkdW6ocKREy0UViJz9GpJ76+d7lTrzYr/R4X2iwKz2/JwFeWYMUC1IdKB5HYmnNHLYUMVSqNTtu8aqV22xyeluR4N8eH1yFrjgNMpr1dmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=AiE/HI6OagdGD9ZL2nK8qpA5ue5A1dovU9+3kLCIiqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=BJDZVjvLaWMSZoAWNxBHFBzGaUKaTleP40Xnd1H5DAl7X9UrVITQX3TsFM3e5aiPfvjabpSojGRP4PEYsw9OUBZl9Ff8VnOp8RhnWz8eVwt4Kc8irvtEsJgZObKrU90MQFo6GbKPMoPxN1EKUfcC3BYqBTqL23ObAYyPqILlNeg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h7XkYJ4z; 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="h7XkYJ4z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E5ACC4CEF0; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=AiE/HI6OagdGD9ZL2nK8qpA5ue5A1dovU9+3kLCIiqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h7XkYJ4zTVYYWOqv35vKvXQ5Od4hDe2HPNij7V6B0jHW9lYrriQFaTV8XaQGZcHiQ RoR5hgkAhBCRD3PAGAd52twtytsV+LcT9PMq++uUbJAfLIAR7WEVUyMqIASv04rXM5 /IgNrfh+HFSNDh55SEFotTS61KC5z59tHk+GRTaDU7pF6Ydd01zWge1j+uhWkpy8k/ XBIiwPLV4QhNfWWtbMx4ck51c+9hANpFrz7VHWgEnyvurGheEQv3ubl97cJGC8NPJe eBZENPjbmZARI/DqHJ0Kjs+korB+Mv8uwixKn7K1/5wmK/2EgYcMKIXIW5BJJcwrPQ cSx9NqjpMQUCg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jP9-2sg1; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 01/19] scripts/jobserver-exec: move the code to a class Date: Thu, 4 Sep 2025 09:33:01 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 Fri Oct 3 06:33:25 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 3F5162BE635; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=qBqbI3oVagAO0FOcD9HwMXUIH7tN9p4bNdP/qBRyHD894jXE7y7Sg/jfc9NXMILtQv6h1xA0nHoXzFVn/SJm5tmB75a6K/lUnkoQ/R00ggMetI7IBfbAcn/JnTVq06EvStWMliJsz2er08jCong5HBRgt3CnkgNC4FUfvZOL/aA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=RnTLGaGUuMOKF6PxxwxnFcuRL48slw9WnQakpfhYXJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mLdI6q1nIcnMDScB3CJNdEMt89FTgdhJbGex4gA5vaJYDg9nVuQIOVPSfprDxkclmKlBSNdXnrYCZnWb5PAio6e9OvZi9S6Vsl6QYAf6lRXEGH6CmaukVCkJQhPzULpce4IMZCBei+Bmd9RYcr9B8W1mwGo5UKBNlrVPKql9yaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p1eRrd77; 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="p1eRrd77" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B02AC4AF09; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=RnTLGaGUuMOKF6PxxwxnFcuRL48slw9WnQakpfhYXJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p1eRrd77Sd/JFaxZ5O49iATffRA6sJNybmpXK6SlDIj7vngmKmIXks+75/amjZM4m uy+Z3RMvRzfZuoaVjpQAppUuadzew+zHZhu7r0RuG4Gfmzwel3HTkHt96nwiSqpfSu XViWX01mtdJLyIjKBMLKeyjRXpMoIvADyKZwJ9akHp0X05J2oG/+Zkh/qSAWAMcHaI OPICxh4PECQss858xJGqM5lrDhcIPziJysFZQRZkf4BLg3RtWukSgBWie0uZnG21ZF erazab1s33XLwLWQ8ZA84tc4wwh0l4664NS1/CK4OCgmkNE7TtYUnEZDL6yKPY0CCw IZKHps+rLcjFg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPD-2zj6; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 02/19] scripts/jobserver-exec: move its class to the lib directory Date: Thu, 4 Sep 2025 09:33:02 +0200 Message-ID: <928e3c95aa49c94c8b3dc312de129e36acf9cc87.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 Fri Oct 3 06:33:25 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 E231B2BE039; Thu, 4 Sep 2025 07:33:26 +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=1756971207; cv=none; b=nKdu8rqiYBVGj062dlzoBGzE9e3Emr2NbCuNGqS7WLpQBohaF8PSUm/jYbTo7mw568HcfI1pr2g85q6r6h5YuZ+NAZ0WxKqspTmMSvRC0h3LUOaUtmMuKtDma6GRfwB+bQQqTXhIr+lRN2nIvazkohQhpaiCfRTxuWjMGN/W4yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=jlol1TuhVNcZDXlNqsLBvYWROc27W0iXgTQpgdIUTbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Ekx9OJn0XSlIh5mFZ/QUASrb0vjlmEXgfD4TYmDdm9qTT2Cacsk4W+kZBIJoWCE+GD7tv/HiCQipHVNfBZNhMUWynyPP1O+Huv79lUHwoBwgrwl3pj/ONd5chS59b4bfxbGIPcc9Rz9fbjf/AGz3qo/o72SmhbkM4AWQJ79dBj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PEzYxh4u; 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="PEzYxh4u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99237C4CEF8; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=jlol1TuhVNcZDXlNqsLBvYWROc27W0iXgTQpgdIUTbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PEzYxh4uTdApX9OUdPVoC+YVi2SnSIQdU2ud5YUIYLHvH3JcyMdCe2rt+HNj31OnR no2awCLXT4J+aV+Fm3dv+sfBfVQH6rzmx4PjGcbUxDngPTbmgtfsk/BD5qx/eOJvuo 9kjR5RGGKyM17xCA/vSYPWi0CU5DDeYihvQdo5IlhqwjjHYxBwIJtSlmCIRnvYhuLK DC9uKgPbEt0kj0aGg/XnmUrS+9e8ERs9CxmKtNSLkrZBuc/kTvcxsHGOCQp7vJ/CJe zcsJJOc5qOvPCnG6/rbX1oYpwoc1km1Ufcj7hnxGo/TkuLho3UE3Do2k6z72HPJGmf xUDkbebAKgUew== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPH-36dq; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 03/19] scripts/jobserver-exec: add a help message Date: Thu, 4 Sep 2025 09:33:03 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 Fri Oct 3 06:33:25 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 1AD6D2BE047; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=o1yRfTCv7HXSOER6kROKj/T+e0gLvWpOUGRkg4ruDvwd/ekZsEv7Typ7RVl6fJhCN4y6BrER1mMy1SiEm4G0OigAhTXP+smLnzeDthwTCDObdbcz/+VLvhdWV0S5HywdUimydoRFE411ZbhY8sWJ0MYBTwTM2Y1tUOA/v7Y5NMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=ZNNE9b19wje69qRgb12NqpyGw7VPdaWJOQjCEXZjJk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=C8JSRJtfanSt3MFa9vc40A+DhfKrOcP2+uYYX6VCXHAak9q3RGym96Iun6Q1YP7H07s82aSiKB60CVjefNFxDCD1lkef/UAxc0rp4UWObfBUoX85ctGND3AUDOuYcKBQ2mGtyi4b5EGgEuTsR/a6M9Z+X0KO3A2/Zj4RSArxThg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gFHtWIoQ; 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="gFHtWIoQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92FD7C4CEF7; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=ZNNE9b19wje69qRgb12NqpyGw7VPdaWJOQjCEXZjJk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gFHtWIoQnELSsuWk18yCioYqGRCY7pb0GSTNyIyMRf8r1IRrecfC3yj6qTXGnzE2/ YUrkzNEMbBEonxMHlD3dHSz8nUhjTVKj6M00zhD7UoMjR/hU/39CF29f9AvuWiI9sN OBv08m21YG933gwg1+pNYp1uAQM+bWCNhgycmq7noPy5Im9/3OyuQ+G281Uuh4Pi2T uxbGtcUIMV1DsLNfRVoYHq/oi3du84nsBj9wG8pKu8nW1lpz5oSRI+yUxuFfVEDkGE J7nj7otrmst6hsUVjJTAsdoYeqR047gr2H8TGQWAy65cUquuitQND1scjYWDS/JKPi OGwbhR2rg8c4w== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPL-3DfW; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Akira Yokosawa , Alex Shi , Dongliang Mu , Federico Vaga , Mauro Carvalho Chehab , Randy Dunlap , Yanteng Si , linux-kernel@vger.kernel.org Subject: [PATCH v4 04/19] scripts: sphinx-pre-install: move it to tools/docs Date: Thu, 4 Sep 2025 09:33:04 +0200 Message-ID: <68810fc1065bbe8ef1305041fb10fa632bb64dd3.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 5c20c68be89a..deb2029228ed 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 || sh $(srctree)/scripts/check-variable-fonts.= sh || 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=EF=BF=BD=EF=BF=BD in grado di darvi dei suggerimenti su come procedere= per completare 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=EF=BF=BD=EF=BF=BD=EF=BF=BDLaTeX=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BDSphinx=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD:: =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=EF=BF=BD=EF=BF=BD=EF=BF=BDLaTeX=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD . 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 =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BDhtml=EF=BF=BD=EF=BF=BD=EF= =BF=BDPDF=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BDLaTeX=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= Python=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BDhtml=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD 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 =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD Linux =EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD :: =20 cd linux - ./scripts/sphinx-pre-install + ./tools/docs/sphinx-pre-install =20 =EF=BF=BD=EF=BF=BD=EF=BF=BD Fedora =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD= =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF= =BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD:: =20 diff --git a/MAINTAINERS b/MAINTAINERS index ef87548b8f88..06bbed30b788 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7310,7 +7310,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/ @@ -7345,7 +7344,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 Fri Oct 3 06:33:25 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 3F3CE2BE630; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=mfXTjoDUqSmmKEXCI6nNMDs8RcjTjEH0Fw9iQo1juCaglJTerqsfTBQXWAH3x5pgBBeYK9l17ogBeZSt8t/JgXV8be2jb/8faXPqCEhYcINQH1XitYINDOr6RiTT1WDyuY81sfGr/+SHZK90bs2iyj9BQU1pBvpbDL9VPk78B5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=bVmM7VBx6Mz+IphxfOc+eSU514/9PatRnA7YynRL2jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=L1AcLf/iw9yyMK07hkn3zKD9gIw23GddvxUxnGUlQ9J+8IedAizblKWwd5woW9ri6iNfc0N5exZ5Qu/oyZVcr06jZaxu7jNPHqrAxDfHPcJSB3glZ7FI+XAldZuqOQSI/brB5ijmslLCsrlGkSl7gUVhJMCTLqn3i0ceO9V9HJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ulOTGkLl; 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="ulOTGkLl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 974E8C4CEFA; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=bVmM7VBx6Mz+IphxfOc+eSU514/9PatRnA7YynRL2jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ulOTGkLlBHkuYAZ0YytF3LpXUWNw6JwdFfnngpAg/PI/v7Io9C8epoiCBaI63b3Cs C1t7go3ED4ftj8nO9lRItzSEkZKKyudJNuslp/0ktxrpQ48xSPNHXFUKd8XFXU94qr BMNIw+ToHahsVahA/Yt8hskWJrSv/0mDpJJIJmKvCIIFKbcedbN2siKDBvoUC+v7wo F5Yw5vAtiMAw6MeOzUV8f4EPpVN2oU3eifU4u1BtKzUvQjpXElpsHkSMWQCHBokuCI M3rpFqm3sHhq2wDKZ3LmvLqqcTZokIjf2nli07OybshHipDQjX1yT6mGAWaD/OJDIq Pzy4hojbMbXKw== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPP-3KWH; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 05/19] tools/docs: python_version: move version check from sphinx-pre-install Date: Thu, 4 Sep 2025 09:33:05 +0200 Message-ID: <784ca5070326558220cc275deaa046a274badebe.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 | 133 +++++++++++++++++++++++++++++++ tools/docs/sphinx-pre-install | 120 +++------------------------- 2 files changed, 146 insertions(+), 107 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..0519d524e547 --- /dev/null +++ b/tools/docs/lib/python_version.py @@ -0,0 +1,133 @@ +#!/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): + """=EF=BF=BD=EF=BF=BDnitialize self.version tuple from a version s= tring""" + 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]", + "python3.[0-9][0-9]", + ] + + # 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: + return cmd + + return None + + @staticmethod + def check_python(min_version): + """ + 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) + print(f"Python version: {ver}") + + return + + python_ver =3D PythonVersion.ver_str(cur_ver) + + new_python_cmd =3D PythonVersion.find_python(min_version) + if not new_python_cmd: + 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 + + # 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:] + + print(f"Python {python_ver} not supported. Changing to {new_python= _cmd}") + + 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 954ed3dc0645..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,95 +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(): - """ - 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]", - "python3.[0-9][0-9]", - ] - - # Seek for a python binary newer than MIN_PYTHON_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 SphinxDependencyChecker.get_python_ver= sion(cmd) - if version >=3D MIN_PYTHON_VERSION: - return cmd - - @staticmethod - def check_python(): - """ - 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) - print(f"Python version: {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) - - new_python_cmd =3D SphinxDependencyChecker.find_python() - if not new_python_cmd: - 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 - - # 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:] - - print(f"Python {python_ver} not supported. Changing to {new_python= _cmd}") - - 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) @@ -527,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): """ @@ -542,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}") @@ -562,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 @@ -1304,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) @@ -1411,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 @@ -1507,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 @@ -1613,7 +1519,7 @@ def main(): =20 checker =3D SphinxDependencyChecker(args) =20 - checker.check_python() + PythonVersion.check_python(MIN_PYTHON_VERSION) checker.check_needs() =20 # Call main if not used as module --=20 2.51.0 From nobody Fri Oct 3 06:33:25 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 E23F32BE03E; Thu, 4 Sep 2025 07:33:26 +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=1756971207; cv=none; b=UF0VO1Lut9B94hkzIXFsKeyBKstk3fzZoaA+9b3NyTPMyQwPy0E9s+CIveKuF6YipZMUMOAK35Trcy+P2TN5vAv5oMCGM3YuhgejlQ0gR7X0Bgtwnf2DeofeJIlaIctLSWI7PrLQNV6s4DTX67vUvxfRAw9NTi+dV8CvNZnQVEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=/dLIDswzK4KrvEpdBfQvdI/IqyHPjqk3TcTvIyNvmfo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=eq0KDrj2lFxFWC+qH3FVXcbA8tKc7p1jLx4JxF9o7NqnzX/7UX2xW+7ZOddcplnDhwqtFNOd/uaD3sm0lEmqufiOX/OCEF2g55YzRIVU8K5fJWlVm/V+j0LrK9N79QG96ftTmuTRTML4/+DmMdhLC09qbemLeceWMdrTfdLrC/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=olTW0BUV; 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="olTW0BUV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90C1EC4CEF4; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=/dLIDswzK4KrvEpdBfQvdI/IqyHPjqk3TcTvIyNvmfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=olTW0BUV8uUhz+OhKjYSqZaxES6n4IP1BzDAsguRctcvzUkHBGIsb+3bidZ/OLoO5 BYUBLRxjqc77FsXlM1RMu15grqZJFv8CFjo7F2bjlVpX2QHdxwWMfIWvPAhXIv2VHm 09WFO6Ip+gT2RtxES96bd9YDuhYRnkTZFUPH2DtuisbRBK/0nmhGSpPKf5+Xo5ZqAH 77Mv/8+u8pyeVTbETMgWB3Ng9Gstsbf290/V9+Xq32XQhyrRxzFiPEoRc6HYoVTHAQ zYQN3nOeNEkWlF0THA34KtUugYYLCl3h8HjP3AFJo/4fihlfv0UbBJ4cSmklHovMWB fVyU69HAgjh/g== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPT-3REL; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 06/19] tools/docs: python_version: drop a debug print Date: Thu, 4 Sep 2025 09:33:06 +0200 Message-ID: <64cdaa3c980931ee7e25e3b3494070c47bbf5545.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 The version print at the lib was added for debugging purposes. Get rid of it. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/lib/python_version.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/docs/lib/python_version.py b/tools/docs/lib/python_versi= on.py index 0519d524e547..660bfe7d23fa 100644 --- a/tools/docs/lib/python_version.py +++ b/tools/docs/lib/python_version.py @@ -109,8 +109,6 @@ class PythonVersion: cur_ver =3D sys.version_info[:3] if cur_ver >=3D min_version: ver =3D PythonVersion.ver_str(cur_ver) - print(f"Python version: {ver}") - return =20 python_ver =3D PythonVersion.ver_str(cur_ver) --=20 2.51.0 From nobody Fri Oct 3 06:33:25 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 E24642BE041; Thu, 4 Sep 2025 07:33:26 +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=1756971207; cv=none; b=a9Dp5DcFOWOKXoT1+ZtqcSJzksEhIoZLucR/6xp10XZHyHW85KjFJnM2+WMl5gvzxikF7Y1EMyzkoB6sU39cAJw/Ok59Kaku55BByNkZbe5pK5MGIJ9GDpyGHMzoNelheZaXqFaFAA2k4QcFfY2aPWbCdp5hbxCPpo1g/a1L4oQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=GdJwj3d3TAyo2Nn7d6rWe+07TNA7IyqQabnELNUF9QU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Z2dDwk0iBnS/AYL94dCWAledmF1v+IN2CW2/y7KbkOFwAdrdUfyoa/1IKHCHc4uNkifslxjATL6u9fcFEvC1dPUKaY8MyLcB9990sWnv9bu5BsWluBWTjGoHzaU1xQcazDqyX2yeRRJ/cqiT5feALOrRoD+J4jwdktiJeQ8lq4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PpX7gU/P; 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="PpX7gU/P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94D2DC4CEF9; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=GdJwj3d3TAyo2Nn7d6rWe+07TNA7IyqQabnELNUF9QU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PpX7gU/PnwgjnFUJJFz5XQmgz2Gmw+nTFuSUrXWFDumuqWaoMFhSGwz+HLusBw4+g Wee2pJRG3UXkdqfY+if9lfmTWUsk7XCwOm7S0HQFni4Gx5g8iOHa02OncqpiGbJUVU XBiRUAzThvMUuxbnNGXTU92+HnLoKtYL5vqRVkTZvwo5le7pg5nEJNxGgGMS+ANuXJ oNEp69EUVr0DQvfMd70uXflRsflAPdJEPCEF4sGpNuxfjaWYOFFbyvZVPf12jx/mcq +5k65Yk4v9lWQmh+w6B3rz0dMMOi/0URbYdEhJ420+pSczJnipvMeu5PVAudyVDNfi ayJDft+dT/yGg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPX-3XpJ; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 07/19] tools/docs: python_version: allow check for alternatives and bail out Date: Thu, 4 Sep 2025 09:33:07 +0200 Message-ID: <71e8254ce711754b64e9bcb864c4886a1a970e7f.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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/lib/python_version.py | 43 ++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/tools/docs/lib/python_version.py b/tools/docs/lib/python_versi= on.py index 660bfe7d23fa..a9fda2470a26 100644 --- a/tools/docs/lib/python_version.py +++ b/tools/docs/lib/python_version.py @@ -85,10 +85,12 @@ class PythonVersion: 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 + python_cmd =3D [] + # Seek for a python binary newer than min_version for path in os.getenv("PATH", "").split(":"): for pattern in patterns: @@ -96,12 +98,13 @@ class PythonVersion: if os.path.isfile(cmd) and os.access(cmd, os.X_OK): version =3D PythonVersion.get_python_version(cmd) if version >=3D min_version: - return cmd + python_cmd.append((version, cmd)) =20 - return None + return sorted(python_cmd, reverse=3DTrue) =20 @staticmethod - def check_python(min_version): + 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. @@ -113,18 +116,42 @@ class PythonVersion: =20 python_ver =3D PythonVersion.ver_str(cur_ver) =20 - new_python_cmd =3D PythonVersion.find_python(min_version) - if not new_python_cmd: + 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 =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: --=20 2.51.0 From nobody Fri Oct 3 06:33:25 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 453FC2BE656; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=fsHu7+7Sgt1wXe5fmJamdG6APN4ocikGQKcDez/DJBZz8wuRbndT3xYFt0b7zgmt//YT7so/lGKgcKeK9l3Nmu88Ww3bvP2Os8tq5/0Z0P3X7HEL/NpxhOf9lwwdf1EKkcbULmBShahdiMy5QgclOr4bgSoKR+5xCOwJSqeu0Kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=kDjHaD7JK/vZFANE720h7No8CVlG5ABHe3bK5OTNRqA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=JKl/M//J+/SFW08pyIRyngpidkq8i/H+TolXXxyg37qrBLBtfW7SIiAm862EFHW+UcC+5AOADL+3B83Ex3eys9EmVtjJp1NK1liAgl97sQdbWABGS4Yy89DfMRN4lIA0kqA1U1kVAWhP3NaMq6RjjMq9fhojwC5CxupHjfdOkUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oIrvEhLr; 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="oIrvEhLr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EC38C4AF0C; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971207; bh=kDjHaD7JK/vZFANE720h7No8CVlG5ABHe3bK5OTNRqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oIrvEhLrmJdZS1n/hFd+esFti36dPjavD6kU2/T7CCuvxANS1HF6yBKBGiP9GHTev AGsd2aNlJvaLi8eqgGdVFCItG3K37xDfKdMzS9wuTgkc3m2Z2UP21fJcM4xhyM+fvP cmWTY4STdrOElXqR6luWQybCZNVS+pZH0LN+qLSf7XpQvT+1gJsGSzQN8S2l75w2pA Uf5VGJxCRrROHHSd1h2X3/+q9CuJoqY3F596847cwuTu8hqo8E22L8ADxUXxi39DmY gU2hpqUuUfh1aRWGfUvdBO2W+T4h+a5XCiIe/fAt4f6TXC/aV0xU9AVc6F93ZGHi4G aZQQzec5eJPzQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPf-3fKw; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , Boqun Feng , Danilo Krummrich , Gary Guo , Mauro Carvalho Chehab , Miguel Ojeda , Trevor Gross , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH v4 08/19] tools/docs: sphinx-build-wrapper: add a wrapper for sphinx-build Date: Thu, 4 Sep 2025 09:33:08 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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: Documentation/Makefile | 131 +++---------- tools/docs/sphinx-build-wrapper | 293 +++++++++++++++++++++++++++++++ 2 files changed, 323 insertions(+), 101 deletions(-) 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 | 131 ++++---------- tools/docs/sphinx-build-wrapper | 293 ++++++++++++++++++++++++++++++++ 2 files changed, 323 insertions(+), 101 deletions(-) create mode 100755 tools/docs/sphinx-build-wrapper diff --git a/Documentation/Makefile b/Documentation/Makefile index deb2029228ed..4736f02b6c9e 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,31 @@ 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)" \ + --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 +ifeq ($(shell which $(PDFLATEX) >/dev/null 2>&1; echo $$?),0) +pdfdocs: DENY_VF =3D XDG_CONFIG_HOME=3D$(FONTS_CONF_DENY_VF) +else +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 +87,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 || sh $(srctree)/scripts/check-variable-fonts.= sh || 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 +98,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..3256418d8dc5 --- /dev/null +++ b/tools/docs/sphinx-build-wrapper @@ -0,0 +1,293 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +import argparse +import os +import shlex +import shutil +import subprocess +import sys +from lib.python_version import PythonVersion + +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 + +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" }, +} + +class SphinxBuilder: + def is_rust_enabled(self): + 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): + 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 __init__(self, builddir, verbose=3DFalse, n_jobs=3DNone): + self.verbose =3D None + 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 + parser =3D argparse.ArgumentParser() + parser.add_argument('-j', '--jobs', type=3Dint) + parser.add_argument('-q', '--quiet', type=3Dint) + sphinxopts =3D shlex.split(os.environ.get("SPHINXOPTS", "")) + sphinx_args, self.sphinxopts =3D parser.parse_known_args(sphinxopt= s) + if sphinx_args.quiet is True: + self.verbose =3D False + if sphinx_args.jobs: + self.n_jobs =3D sphinx_args.jobs + self.n_jobs =3D n_jobs + self.srctree =3D os.environ.get("srctree") + if not self.srctree: + self.srctree =3D "." + os.environ["srctree"] =3D self.srctree + 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() + + self.pdflatex_cmd =3D shutil.which(self.pdflatex) + self.latexmk_cmd =3D shutil.which("latexmk") + + self.env =3D os.environ.copy() + + def run_sphinx(self, sphinx_build, build_args, *args, **pwargs): + with JobserverExec() as jobserver: + if jobserver.claim: + n_jobs =3D str(jobserver.claim) + else: + n_jobs =3D "auto" # Supported since Sphinx 1.7 + cmd =3D [] + cmd.append(sys.executable) + cmd.append(sphinx_build) + if self.n_jobs: + n_jobs =3D str(self.n_jobs) + + if n_jobs: + cmd +=3D [f"-j{n_jobs}"] + + if not self.verbose: + cmd.append("-q") + 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): + 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): + builds =3D {} + max_len =3D 0 + 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" + 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 + try: + subprocess.run(latex_cmd + [entry.path], + cwd=3Dfrom_dir, check=3DTrue) + 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: + sys.exit("PDF build failed: not all PDF files were created.") + else: + print("All PDF files were built.") + + def handle_info(self, output_dirs): + 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): + shutil.rmtree(self.builddir, ignore_errors=3DTrue) + + def build(self, target, sphinxdirs=3DNone, conf=3D"conf.py", + theme=3DNone, css=3DNone, paper=3DNone): + builder =3D TARGETS[target]["builder"] + out_dir =3D TARGETS[target].get("out_dir", "") + if target =3D=3D "cleandocs": + self.cleandocs(builder) + return + if theme: + os.environ["DOCS_THEME"] =3D theme + 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")) + 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_list =3D [] + for sphinxdir in sphinxdirs: + if isinstance(sphinxdir, list): + sphinxdirs_list +=3D sphinxdir + else: + for name in sphinxdir.split(" "): + sphinxdirs_list.append(name) + 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) + 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)}") + if target in ["htmldocs", "epubdocs"]: + self.handle_html(css, output_dir) + if target =3D=3D "pdfdocs": + self.handle_pdf(output_dirs) + elif target =3D=3D "infodocs": + self.handle_info(output_dirs) + +def jobs_type(value): + 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}") + +def main(): + 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("-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) + +if __name__ =3D=3D "__main__": + main() --=20 2.51.0 From nobody Fri Oct 3 06:33:25 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 451B62BE655; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=oMa+VKoqy8oqz/Yj3n8VOz7HEY98ibVutBN0vRl11P9rqJLs7Jn+AGnivWhEr9jrc/Uy7NLzqxmbSOftk4Jwukz9xA5OEbdjkczEuzyC0rGNP7ifWGyJsmH0A8T5/2uMBzBA/w/KILl/OlJoBGEOrw+5tLHhisgBkO98Qmn6WdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=YKT7sd1ZkHa51vLkotcuMyzse1qM4BPzGd7zz31OQF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=gO+ojEAouUzdR11SUxWl5qZAp1YiJbKtHKO1/S6NTDkZOEdpvvP5OrcCaqEUHr/arstOfP6DP2E3L965LXrt8PYiJuY19N/d9n+Z9UQNTsiI+gLG7IWX/1Zayr8Naai6/6VWpvv9tJndnFAM+gryJaEcUj1OadhwEcLl7gtql9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cQUj1LE1; 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="cQUj1LE1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A77C8C4CEFC; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971207; bh=YKT7sd1ZkHa51vLkotcuMyzse1qM4BPzGd7zz31OQF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cQUj1LE1vVMzhb/QKi25DXkDIG8pXRMiNbojybUJZQSwn+rXRIRsrOrxGlxdTvnQe vmrTzNmUqnURgXbTLzTf3qOpjHqPy296N261azoM5dXJVEeIR5hPCsa1UuKouqvvh2 SWvdMoMeVckWgytMUpcJ6sE2rH3hZFZ/LyAbJKSjerhg0MzbRy/AJY5g1HnP8HMi9Z VPAagqGCgOMGRUR7njW5ynot/SLoJT0fp0GOhp+w303DTZLJjaiSCj3dsXGZIO5E5t qnIbtql3au1r5ufIXdf/5h3jOdVk/t34WgqwiwD1IDkW7TlhbDu8C/Q5ln72C10GJ5 zwJ8paEEshTlA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPj-3nDk; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , Boqun Feng , Danilo Krummrich , Gary Guo , Mauro Carvalho Chehab , Miguel Ojeda , Trevor Gross , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH v4 09/19] tools/docs: sphinx-build-wrapper: add comments and blank lines Date: Thu, 4 Sep 2025 09:33:09 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 To help seing the actual size of the script when it was added, I opted to strip out all comments from the original script. Add them here: tools/docs/sphinx-build-wrapper | 261 +++++++++++++++++++++++++++++++- 1 file changed, 257 insertions(+), 4 deletion(-) As the code from the script has 288 lines of code, it means that about half of the script are comments. Also ensure pylint won't report any warnings. No functional changes. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/sphinx-build-wrapper | 262 +++++++++++++++++++++++++++++++- 1 file changed, 258 insertions(+), 4 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index 3256418d8dc5..ea9f8e17b0bc 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -1,21 +1,71 @@ #!/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 =20 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)) =20 -from jobserver import JobserverExec +from jobserver import JobserverExec # pylint: disable=3DC0413,C041= 1,E0401 =20 +# +# Some constants +# MIN_PYTHON_VERSION =3D PythonVersion("3.7").version PAPER =3D ["", "a4", "letter"] + TARGETS =3D { "cleandocs": { "builder": "clean" }, "linkcheckdocs": { "builder": "linkcheck" }, @@ -28,8 +78,19 @@ TARGETS =3D { "xmldocs": { "builder": "xml", "out_dir": "xml" }, } =20 + +# +# 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: @@ -37,41 +98,88 @@ class SphinxBuilder: return False =20 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 =20 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 + + # + # As we handle number of jobs and quiet in separate, we need to pi= ck + # both the same way as sphinx-build would pick, optionally accepts + # whitespaces or not. So let's use argparse to handle argument exp= ansion + # 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 + # sphinx_args, self.sphinxopts =3D parser.parse_known_args(sphinxopt= s) if sphinx_args.quiet is True: self.verbose =3D False + if sphinx_args.jobs: self.n_jobs =3D sphinx_args.jobs + + # + # If the command line argument "-j" is used override SPHINXOPTS + # + self.n_jobs =3D n_jobs + + # + # 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")) @@ -79,20 +187,36 @@ class SphinxBuilder: =20 self.config_rust =3D self.is_rust_enabled() =20 + # + # Get directory locations for LaTeX build toolchain + # self.pdflatex_cmd =3D shutil.which(self.pdflatex) self.latexmk_cmd =3D shutil.which("latexmk") =20 self.env =3D os.environ.copy() =20 def run_sphinx(self, sphinx_build, build_args, *args, **pwargs): + """ + Executes sphinx-build using current python3 command and setting + -j parameter if possible to run the build in parallel. + """ + with JobserverExec() as jobserver: if jobserver.claim: n_jobs =3D str(jobserver.claim) else: n_jobs =3D "auto" # Supported since Sphinx 1.7 + cmd =3D [] + cmd.append(sys.executable) + cmd.append(sphinx_build) + + # + # Override auto setting, if explicitly passed from command line + # or via SPHINXOPTS + # if self.n_jobs: n_jobs =3D str(self.n_jobs) =20 @@ -101,59 +225,100 @@ class SphinxBuilder: =20 if not self.verbose: cmd.append("-q") + cmd +=3D self.sphinxopts cmd +=3D build_args + if self.verbose: print(" ".join(cmd)) return subprocess.call(cmd, *args, **pwargs) =20 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) =20 def handle_pdf(self, output_dirs): + """ + 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 + 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) 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)) =20 @@ -162,58 +327,100 @@ class SphinxBuilder: 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: sys.exit("PDF build failed: not all PDF files were created.") else: print("All PDF files were built.") =20 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}") =20 - def cleandocs(self, builder): + def cleandocs(self, builder): # pylint: disable=3DW0613 + """Remove documentation output directory""" shutil.rmtree(self.builddir, ignore_errors=3DTrue) =20 def build(self, target, sphinxdirs=3DNone, conf=3D"conf.py", theme=3DNone, css=3DNone, paper=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 + 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): @@ -221,17 +428,32 @@ class SphinxBuilder: else: for name in sphinxdir.split(" "): sphinxdirs_list.append(name) + + # + # 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}", @@ -241,31 +463,54 @@ class SphinxBuilder: 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) elif target =3D=3D "infodocs": self.handle_info(output_dirs) =20 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}") + raise argparse.ArgumentTypeError(f"Must be 'auto' or positive inte= ger, got {value}") # pylint: disable=3DW0707 =20 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"+", @@ -274,18 +519,27 @@ def main(): 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("-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) =20 --=20 2.51.0 From nobody Fri Oct 3 06:33:25 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 40FDC2BE63F; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=IhCtvkwh3mLP33vg0ekZmviJUtLl1eFhaayZbVjRpdXCXlLsfyr6JkQNAL3Iyv+gYTRwr+vo3alxCYpWfSwvS2bv1bG74FUWe0axMvhF/8VFT6aH39YQ4eghqDCDF3sn53T8q9v5kNlaspty3tTFBPjltOBLJlszDlpM6fTohbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=SW0tJnngS/ct2ODjXine9JSlkR4t/QS2wUfoS4CRDyM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mtqCEfmC9fzdwHDyWRfRXRta1031fbma4g2WPpP+j5nUIqVJ+56NF1eFs7Ul/u1iQ0RyR3jfKbuoZ9YbX4bGXsEOxZbL2hZ1ouX5NKKtmsXvM2TZwvHs4aOd2TAc17BLN7BSE0kQeQACLHe570r6bg67K+TDjjH7JQ+gPKV5n3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T3ZSj9jx; 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="T3ZSj9jx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5744C4CEF1; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=SW0tJnngS/ct2ODjXine9JSlkR4t/QS2wUfoS4CRDyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T3ZSj9jxUflsBM7votUvM+0jOHs5IDpPVUwYOkr+SpJalrBO60YvSkUE/3Gy2oAwa LOQvUYTPdCkMz7rNDFp34i+9qY5F/UEMGxU6c2CGqzFRtzia3qiKH1tdO6hevUwI7X TfzFBOnGIz+FKPcg7wKcQ2gq7Z6civQpBlAPlbNKipkLsN9SyxbH1T3XDfuv8o5e/4 GVc44hfukdewP/n70YvxiPA/3JhJVnTU6cbrb3AIJad9jTCN7CX8Y9IieJ0Zm0nF5O GbmoandplZKQ+DV6cAVDXlqwmnUfNASqxDrUnXxRiG2+ylUJQitomo4CRnOcNlgFwD nX5Rkue+MANQg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPn-3uEG; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 10/19] tools/docs: sphinx-build-wrapper: add support to run inside venv Date: Thu, 4 Sep 2025 09:33:10 +0200 Message-ID: <2158cc4cf1f9bcf4c191f8031c1fb717cb989f7f.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index ea9f8e17b0bc..cf7b30bc40ff 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -63,6 +63,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 @@ -119,8 +120,9 @@ class SphinxBuilder: =20 return path =20 - def __init__(self, builddir, verbose=3DFalse, n_jobs=3DNone): + def __init__(self, builddir, venv=3DNone, verbose=3DFalse, n_jobs=3DNo= ne): """Initialize internal variables""" + self.venv =3D venv self.verbose =3D None =20 # @@ -195,6 +197,21 @@ class SphinxBuilder: =20 self.env =3D os.environ.copy() =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 and setting @@ -209,7 +226,10 @@ class SphinxBuilder: =20 cmd =3D [] =20 - cmd.append(sys.executable) + if self.venv: + cmd.append("python") + else: + cmd.append(sys.executable) =20 cmd.append(sphinx_build) =20 @@ -533,11 +553,15 @@ 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("-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) =20 - builder =3D SphinxBuilder(builddir=3Dargs.builddir, + builder =3D SphinxBuilder(builddir=3Dargs.builddir, venv=3Dargs.venv, verbose=3Dargs.verbose, n_jobs=3Dargs.jobs) =20 builder.build(args.target, sphinxdirs=3Dargs.sphinxdirs, conf=3Dargs.c= onf, --=20 2.51.0 From nobody Fri Oct 3 06:33:25 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 E23902BE03B; Thu, 4 Sep 2025 07:33:26 +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=1756971207; cv=none; b=AVbSXrwbaSz4LxffwXNiGSUkSVQ1pNhULm772iU3+VHNgmhgZ7Mw82Rgkwb26099iLfycb8jaf8AcuaY8CCZ9ilCyanx7zHVP5jVKl5o/BEgAo/D3iZ5q9hee26W61xRy0nmRnEMbpMt13+nlkrnEiiApU84BV7p/IAFP1t+8Wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=ZLbhSMLrYrG412X2oMrDythT1CiWtmLDdQQNSbEgmmI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=hWBtBs6jjaxMvfVmmNoZM2sMexCTpESotzeIjSbEqemZfisKmACy/MC6lPMMSbwRK3IsrKB5hkeXQFi2VYqM9gxnsADTgQleli9I5V67giDCyK2MbtXqJ0gR3RyBfuL+85i7dA/YdDHPppJ65bZtY+5vU1j8XDK/6iBCjPtJHdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oJ3ae1hB; 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="oJ3ae1hB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A07FFC4CEFE; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=ZLbhSMLrYrG412X2oMrDythT1CiWtmLDdQQNSbEgmmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oJ3ae1hBCzr9H6EM6d5j3Pa+M9XZcoFHapiHSRm2OGbUUTm8lrWNpZVlaComxf03e 2eJwL286weD4fMgVCBLau4guEVjfoS6Jd6Xm24KSOs2e4VrP7mzmv/F2cakfWCWcBn udVcPA8jIbIb9bLpM9gVCEAotdnvrN7k7HXCFK8kNlQnJQno02zJG6/j4C4IkOx6Gj G0oRGmaIFu2SzsURPMy0158El7f7DqvSgg0aPmjw3RBfIVv2m9AIo7IchytY1+evvI FAClPJcO0odOY/ovyYdy5lNPARO9JZJnJjiL70+xqSPJj2J8CLA+w6nGTt+F2bQXCI z1IrXBAJl/nag== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPr-40xC; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 11/19] docs: parallel-wrapper.sh: remove script Date: Thu, 4 Sep 2025 09:33:11 +0200 Message-ID: <36db8fe6394b8339c2a45a1e698fc224fe35c9f4.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 Fri Oct 3 06:33:25 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 1CF5E2BE050; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=Ztqu9/YqCRDk5YAyqHtIfk5SnOU0+LfBxi9flCZhy8DLlhk6YP1fV9gI1nBu9r+pg6qYVJrnplE7SW4o21J18MlQC6DvVBCUQFW/752K137JPRCxKFnGga1PIYmc5z9Lv+KMKxY3FHZJiVUWdVi8SxLceCtrrRKSdF0ENyyqxVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=IxCwBaqniEL1mqsUfHyArHWkZNqcFJPHqEQYTKFn1Mw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=n8+t/lJ7ojrQO7Io/7XGul5Ta1qkxXmbAczAKYH3fg3aQ0v937jsi85zdt8axhMPD4Yk8+1hfJi7WrYHAzgc143YvHgIIpsLfRDKAM4vWVLqWaG4L/phaTokglxK3s0M9y0rcMH0cR+iZSYJ6WUgoQHeqpbPWL7eH+bDBTTQcCI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IFjmlsip; 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="IFjmlsip" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB6B7C113CF; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=IxCwBaqniEL1mqsUfHyArHWkZNqcFJPHqEQYTKFn1Mw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IFjmlsip2g6V/CfCM/eh6jTWiJiVyRk+4D4f8TfdWQsooKZhaqfUs4W8sON3uk2jY p30Weihr2QnjJfZktd7n4CHdCwE5Y9IqhrTumQkQrmt9loESqeXrvlLxdiCHq7qmum FKdP2i71NWPKSlbyzu5gx6f2vM6Z1PCSzXGUQVQcYdlNVfykxe47S3EIpv25yZ69sQ pmFZ8+gXHrT2NXg+JS9SQMgpDBeUAUIKXUtxTw8UfI8a5RJMvp1nP8TURajYFhMWz5 li3JG/076XwV6mH9WXidP53teIbuOP80g/C3O8X/x5J7yN39VAWtfH3lkvCUee242g 4Sw/nmT+633qw== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TE-00000009jPv-47la; Thu, 04 Sep 2025 09:33:24 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 12/19] docs: Makefile: document latex/PDF PAPER= parameter Date: Thu, 4 Sep 2025 09:33:12 +0200 Message-ID: <52411bce7bf0d068bfc8e33b35db3259c3ae0c64.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 4736f02b6c9e..0e1d8657a5cc 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -126,4 +126,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 Fri Oct 3 06:33:25 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 1CEEA2BE04C; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=W4G6jKI48olZLx4v2LxxHiYLAbQr6TnH1YayLTU2P3yaQtoIvFwN2RhkKW3/SvXWuRfKYjMD/f2xqgOqv4h0/UcjnCrlvIVytzRfEhj7h99eW86YFAW4B1bBESyBDser5fGolQjqzyn/S/GOf4h7mi1SEIegJ5fLpZBf4coPU2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=cbweHJfQC8VvqXB8Y5/FaxFei0KTfLWpMRtf/hEy3WI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=CTmjcEr8XQcEjeFtngT5UaCoQDgzsHh4dFBdE0i5293FoNT670hJVxkj+7YvwcoDi59Nc6+Qc2mnnl4iFZCWNGpRlfeIfXMdxEafs4vl6wFI6Tt7NKAlyLM1J3Iy086G1+qp5fI0+CCVmS0EaHGSNi3UWvm3eqzjvKSj0W1MLDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F8rlMgaK; 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="F8rlMgaK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C03F4C16AAE; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=cbweHJfQC8VvqXB8Y5/FaxFei0KTfLWpMRtf/hEy3WI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F8rlMgaK5oFmVajHWaCxEyFIWpNuHT8VxwUR75AgZxpBFLU9Il59BZvuwVOyNhGHA Ww5/CSYUE35MOZQNKjI+A6m+pwqkwg680TvCP4uyt2ouGGpoIPwVHdrcR8aMCLuk5a +NQ3CLRlegY1Hu1bF9wKQuOmRnp89Acg8NgURIMQnPLyx+9p8fBr0XK8Ff3qN8mN41 9PBa266G5Hcikf2UNcRaAJqNx8zEynn30yrLeCTuSFse/MzDsXHiQTVoOIntz2eN2W I5RGdmcV7nENtLBRuxNOuXs/hiVK2UFXXBDdOhfDTDuVkvnmB6drGsfgINc9FQ5/gi WOh1K2OKSXCrA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TF-00000009jPz-02L7; Thu, 04 Sep 2025 09:33:25 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 13/19] tools/docs: sphinx-build-wrapper: add an argument for LaTeX interactive mode Date: Thu, 4 Sep 2025 09:33:13 +0200 Message-ID: <510bc978a84b22089c2de55a24a31300346771c7.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index cf7b30bc40ff..8ce57a25696f 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -120,7 +120,8 @@ class SphinxBuilder: =20 return path =20 - def __init__(self, builddir, venv=3DNone, verbose=3DFalse, n_jobs=3DNo= ne): + 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 @@ -131,7 +132,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 "") @@ -553,6 +558,9 @@ 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") + 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})') @@ -562,7 +570,8 @@ def main(): PythonVersion.check_python(MIN_PYTHON_VERSION) =20 builder =3D SphinxBuilder(builddir=3Dargs.builddir, venv=3Dargs.venv, - 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 Fri Oct 3 06:33:25 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 1AE2E2BE048; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=f76vm8BQpe+N42NtS5IL5AGo9/hMXRNUnrNoMljaJT/awwskxMr1dymx8Vv8v6ECtkOTsEQgGGik7xmNjn9dY7tiogGBAizqQ37sywxh3uUcQnadJBg3r4J2rlvATmWVmJHjJsFcHKvQC/ho4vv2sLqV5C37Dw0ozQFVZj78+Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=Mnafdtexwy9cPkXTjcz1GKQ9wicPavf82/kQmCha3rM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=SdVkq/3vFkpaxbecnDqi07k76NMWIaJqALqJ8fQ1oXx7JCjCGEoq+amTQHkKUvBcAyivM+wLNzW2PB0QqOMrUfug+9dUHE9f8wvMYc5lQBgvPH8NU1qkyR+NZb0ZhtWle2WOeW5tTjGrutaQLKitkKCBziK7hIV4ixb2PseKwCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ee1GiGmI; 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="Ee1GiGmI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1673C116D0; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=Mnafdtexwy9cPkXTjcz1GKQ9wicPavf82/kQmCha3rM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ee1GiGmItOqoJ/yLJlGRsN3Vt0XIzTxCMyvNfaycAMAWhPa2ZW6FQTDx2Nsqiuk0W OA0DBmOMDn3kVO9z35d3DEo1fJ519ioKyo9d1O+xi2YWSVLM5grj4jXiqgGW026AC1 WaOwbGkWIUfbCc9FXCQX+l0WiY3+INKY7CV+mBrFBrM/NVaF2cg6AIvPmS1AohkmIY tRexIswos7ws/EDKmb+MEheDpfkSbOYbb1ipsdXXbPxw5vJEg0Y4AxFVNADTMA2WNe RxUdPPwktZjiRzBfiwFtB3UAk8HYQUyo53h0C8UUszDtT1OHd+gTl9n2i1vOOJLHD3 9jI4En7N/9YHQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TF-00000009jQ3-08uZ; Thu, 04 Sep 2025 09:33:25 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 14/19] tools/docs,scripts: sphinx-*: prevent sphinx-build crashes Date: Thu, 4 Sep 2025 09:33:14 +0200 Message-ID: <98f1c5983da817e4f0142ac3ec17cfa6ff7ee28c.1756969623.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 8ce57a25696f..c318af5f2af1 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 @@ -443,6 +444,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 Fri Oct 3 06:33:25 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 4555B2BE65B; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=r0K3qFqjx+a1WXU/DGr4d9RI+u1yZtX+l4ueG1ha9pKAhPiy57rmAuX9g7Xivf4dZRnEborr+yrirRHVxYNWGHLZeFKp+PN7h6ieFDgPC/P+yUKAjIupLk9aTlsGP5DIYK1pc6nfcsYqESZYcyeDAvnL2u5Ky1m6pg2ly5iI9SQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=v60pr/JeZrm7zsenH9iTuHtr7B+1quiHIKEIqzlIcb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=I9Inp2Z4I/UITt+gVuv0bPs+kHq+pq3prfZPKVQ1hcsIMaIl3cihgfEEFdPlvX2kb5ARCJq0F3mAT6zxDJhvJGLS10DxgeTBbDqtUbjuylQU+KbyOkaaCLE8zKGulgRptBHbZBEXOS0Tki4yogd0eNd21ACboDPVpsitYOJunFs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H3QE0sgS; 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="H3QE0sgS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7D2AC19421; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971207; bh=v60pr/JeZrm7zsenH9iTuHtr7B+1quiHIKEIqzlIcb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H3QE0sgSZVGeKWtFBQU5grIYOKM7nOR1/gm296C2mb+vVRaisRDgpaGBB3nuYzMYz ZHXbIw9yhMnyI8Z1J9QR7snbefr7Lwlw4IVOz6SPIiDFvLdqt8R+dd+rm+bp5svwZE UehxlVxn90zrLq4mp4QzF1TBrtgfAm15SOahykQq/hWZ9W1b7mAe9cn4swizETo2p3 cJZOpY4C4rk758qWzoTbhH/je75TaYIA6gc4wxiNMYB4JL9/C5QHcgLcl710rWZXRs dae0BDplJVZhrO/UbFiF/OAfwvj+5NQU2F2HrX+3A7d1QpvCJ9gm5aC+EvNaVyP0cv 7JC5K6a3bW0gQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TF-00000009jQ7-0FiD; Thu, 04 Sep 2025 09:33:25 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 15/19] tools/docs: sphinx-build-wrapper: allow building PDF files in parallel Date: Thu, 4 Sep 2025 09:33:15 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 | 158 +++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 41 deletions(-) diff --git a/tools/docs/sphinx-build-wrapper b/tools/docs/sphinx-build-wrap= per index c318af5f2af1..c5fcc448a275 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -52,6 +52,8 @@ import shutil import subprocess import sys =20 +from concurrent import futures + from lib.python_version import PythonVersion =20 LIB_DIR =3D "../../scripts/lib" @@ -282,6 +284,82 @@ 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) + + 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) + builds[name] =3D os.path.relpath(pdf_to, self.buil= ddir) + 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): """ Extra steps for PDF output. @@ -292,7 +370,9 @@ class SphinxBuilder: """ builds =3D {} max_len =3D 0 + tex_suffix =3D ".tex" =20 + tex_files =3D [] for from_dir in output_dirs: pdf_dir =3D os.path.join(from_dir, "../pdf") os.makedirs(pdf_dir, exist_ok=3DTrue) @@ -304,55 +384,51 @@ 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 + if entry.name.endswith(tex_suffix): + tex_files.append((from_dir, pdf_dir, entry)) =20 - name =3D entry.name[:-len(tex_suffix)] - has_tex =3D True + # + # 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 =20 - # - # 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) - except subprocess.CalledProcessError: - pass + # 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 =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) + # + # 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 =20 - 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 + # + # 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 =20 - name =3D entry.name.removesuffix(".tex") - max_len =3D max(max_len, len(name)) + if jobserver.claim: + n_jobs =3D jobserver.claim =20 - 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 + builds, build_failed, max_len =3D self.pdf_parallel_build(tex_= suffix, + latex_= cmd, + tex_fi= les, + n_jobs) =20 msg =3D "Summary" msg +=3D "\n" + "=3D" * len(msg) --=20 2.51.0 From nobody Fri Oct 3 06:33:25 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 61D862BEC21; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=bzNA5hO5EBgr0nrHj0ez16yHlpsabzkVVOo060JQCUiNc0mIK8wYmF1CZbh7eBCOdiGHAbeIXJtCqvsEp2n7MUXjIzvKXG+lnewD7qyvDM+SAXZonLMGJZ11P7Rp1ArKEQYjVMyRrTv4ol/gXUVAQcXa5FyAyiOjGo2dJyH3caE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=nr9CnFi7NZuG9xGHC2mIKw9taODTL2g8s7aUDQOWYkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=X7W28GNoJ+zsmQM0j8cQ6R6uVYR86fNAuKFCMPxxLGJJqO4WjFfHDG2uPVgP4E0WSg1G3MLUvKZ2mmHWfAEJfGofz9NKmWc5YWZi/yqAfGe0LVAgeTZBgfhlI/KTHsESPyD+f3uMu128cD3LrPWCtUSreL52+wk7q+GbUNDFSbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kjOZIb4v; 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="kjOZIb4v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BED9CC113D0; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=nr9CnFi7NZuG9xGHC2mIKw9taODTL2g8s7aUDQOWYkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kjOZIb4vMlVlOzAnqvgPf7grWf7J6ValjRXFNT4qtcj+GaRIijasLqs4muHgN7XrG 9MCnhvCJJa6oMLszhd4dUQlnilnyuUbWt3BijMN44BXqwRt8RSBmRSx4fv3zwRy9Ld RkLo/XiINuRYtDfCfZgcpq5zDastjxex/rVdfVga6ZBBSRl0a9PR5nks/7RDaZmuHU 1BRiHAeBhYnIssIx9ZvMSGlYc5hiEFNwaUxIt1OEwSO8roXtELez9dFrN031tJjNft L2HRorw0v7XKOjxpnXQtFgq4eEPSYl79qk3uNWMbN7CDEkZ8o3L+janesFjgg4pqwe UKalKhtaEZcVg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TF-00000009jQB-0Mp5; Thu, 04 Sep 2025 09:33:25 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Alice Ryhl , Masahiro Yamada , Mauro Carvalho Chehab , Miguel Ojeda , Nathan Chancellor , Nicolas Schier , Randy Dunlap , Tamir Duberstein , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 16/19] docs: add support to build manpages from kerneldoc output Date: Thu, 4 Sep 2025 09:33:16 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 0e1d8657a5cc..f9b6e9386a58 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)" \ @@ -106,6 +106,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 c5fcc448a275..183717eb6d87 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -47,6 +47,7 @@ the newer version. import argparse import locale import os +import re import shlex import shutil import subprocess @@ -55,6 +56,7 @@ import sys from concurrent import futures =20 from lib.python_version import PythonVersion +from glob import glob =20 LIB_DIR =3D "../../scripts/lib" SRC_DIR =3D os.path.dirname(os.path.realpath(__file__)) @@ -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" }, @@ -459,6 +462,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) @@ -487,7 +555,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": @@ -576,10 +644,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 Fri Oct 3 06:33:25 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 433262BE652; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=pXGVuCL80eQ1Gw8tG+1/o2k+19kQTDcRCfCH7MjbjQZDBdz7+6m3nmHsnRZBNxoaaf+Udw4aVdSKU7W0msLq6cp/uwwrMxnVYxX2/p0T+pHp2UZyBiae5pnWZF6KoI21HMtioLcbFvTX+gQUeGJz0NdlLnmrW+rUiRFRFbLCwFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=bNOmw1tzFH8Sl7kR3p+wUYP6U5+a6FHYIcsXQNkIydI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Or95LTLsoXgi5nXWn3JBvT8dV4843nwxXckQtB+GnzMBE8wleJKtw2HuL6hGb1mW7D+SDrQilnwsp7cMvyi8VjPupJSDp/UfJvJrhGpkO26E+oRGOgEyHd6CJ2vN9+SmSh74A6D+7EwNZaq9L2BsuQzNgBOa5eCD0z5L53CSUOw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qq5zxg8I; 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="Qq5zxg8I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA409C19424; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971207; bh=bNOmw1tzFH8Sl7kR3p+wUYP6U5+a6FHYIcsXQNkIydI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qq5zxg8IzHuupLu/UQcfnXZDLRYf9N1LN9Gntj5JVriB6wuGJDpDaRE3UzVXuCLuR mjEWewd2otCkDoTDYZcW8RxA/hL+SLC+aWUByRrGdUWu+zdyRR+NPen4QJ9nMwrdpY JIJtgR+PMChqHkkHqLFMORMm1Y4X/taB1ppbjtRs0JCIvHveres3qndwA3ZrtHfLRV 76cRgdSH8Xda8hFFZLrpfnQiD1JjukLpNfIhZb5qRSwla2awz8Cmx0sZsFPeg6aPdm N8hjrBeDZGFHvkTVk6PgM5QroiZAdSMTP7eHgj9E5dqAtdzA8w/2r6UOL3eL+urivm AIncoinXT3mJw== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TF-00000009jQF-0Tje; Thu, 04 Sep 2025 09:33:25 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 17/19] tools: kernel-doc: add a see also section at man pages Date: Thu, 4 Sep 2025 09:33:17 +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 Fri Oct 3 06:33:25 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 614392BE7CB; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=rWB6ojBEIZ1FGN8f61pwUO6Tt5ANQc0HEoe7A85DeSC00JI2YIO9LhDcJSyrjSpdwFKWXniTnl7UobIhVL6/etUUPcWVDt/WxNot9xXZ6rQerTJEgFhLeSb4gXRpmOvHZAFm/voGnTuG9prPYrkzege8TT8DuAi6UQ+9EByZ5Ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=4Yu1gA5/uZ+OPBNEREkXam+9wN35SUbcDazI/2U7I9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=lwj5fspyt6xyn3E1uiy5mTEjWVJ4Sjvxc1cN0lhmJn050Jf4+FZW9Bqwv5iHe42Rje/zB4XV6XdzQLUGN1tgyr+9GcU3y9TtilpS9jquCpgpb4VwXp1pbFb/dvaSRwvLh4TOqOf6A9LcYC9oeWjSia/Fc92kJERyMQ43bU/ynvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KB/g2yv2; 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="KB/g2yv2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCB22C2BCAF; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=4Yu1gA5/uZ+OPBNEREkXam+9wN35SUbcDazI/2U7I9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KB/g2yv207SLTsFdV+b+TrE3aXebjLe0+qdSjzJdHe0Y2saTM4K7RUrG9i0tpEpJ/ /AkQUxkKOXXgnrfGXUoIpRBztOqfJtLksd0lkq5DE7h9QIaUyBEZgYFQwvopWO6OFs bpkuWByKjme2oLjS3+0E2oRtURZ+Y4H6O+TFldhPS2TFCfYBe5Sd4UuAYbm3xETVvH rvHsoknvZTjXU2VqvYvPslBGYDffXm8feGhThZBfs2D8uazmlXgnfUNvj4dzL/X9By ZjNHuyzfSHDOrTJKGd/Mc35+3sPYO4PqyCkfnmg3IrZTA/ca5pHR0mPqT6Cf72ir3v fa/F3HVe5hXgw== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TF-00000009jQJ-0aW4; Thu, 04 Sep 2025 09:33:25 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH v4 18/19] scripts: kdoc_parser.py: warn about Python version only once Date: Thu, 4 Sep 2025 09:33:18 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 Fri Oct 3 06:33:25 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 618F42BE7CC; Thu, 4 Sep 2025 07:33:27 +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=1756971207; cv=none; b=SJ1t/FDDeYKyj4KUGgv0nob9ocm6mCfkbk5150y+w8n77R5heigxwKIOjYqZYY2ObciKrJdJRiDcylgzkLgo/VgUMfW0W6IcQu12pbcdalSugMXpiHBAeeeEovPjNXLfiL8kQsRQ7ARnhPzopqPxoo2pBG5spg09bGU6gPZt1LE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756971207; c=relaxed/simple; bh=HST4RGg0PfveQiwlk1hwWcTIziyW3CTk7tqSb0nnoIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Dsg/fMsv9BKnv+djmaxNIaCnIz6tdpVBpuj5y9n2KyllYUQEpzHleOTFPTWehG2EMO8J6aoX0N8rnsry43fOUhia1UR8wotVV+h+63LkEOfeYXjfit8u5FNNpq3M74Y6EmaZ6CHxgKHBgvUk2XHH3x2s4IBzXDjMJH11dghFEQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i7SfqaXp; 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="i7SfqaXp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCAB6C2BC9E; Thu, 4 Sep 2025 07:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756971206; bh=HST4RGg0PfveQiwlk1hwWcTIziyW3CTk7tqSb0nnoIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i7SfqaXpKJUPTp4O/rBXSc//derUJyxkruqqrQSBMULmwIPp6HfYK2TpDoiSK3Gn+ CNGZz5gsYS7GeR68KV8slfrBZn5xGJrnPIJWImV6FlYWgNXZPzNN5JVYRkUj2cqMcP 5mZoaVVjxw+fGnUh8jRVLruG3PTh1foiMmWH054NjNdDGDPgSKUfVz7AqptxuNiSyP qjuYB1WNYefM9cu0WGFYEZkl+zUTn1ot0TSANl6YRNMVy3szSZz96CMqQvrKewTdJz +RHnSHpTpG/VxBNaB81euW627LlC7jIJhmyGN7s1cuFAQN6yPfHZ0haVgcBWsk893e 12pZbRa9JVoIg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uu4TF-00000009jQN-0iLH; Thu, 04 Sep 2025 09:33:25 +0200 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , Boqun Feng , Danilo Krummrich , Gary Guo , Mauro Carvalho Chehab , Miguel Ojeda , Trevor Gross , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH v4 19/19] tools/docs: sphinx-* break documentation bulds on openSUSE Date: Thu, 4 Sep 2025 09:33:19 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" 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 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 183717eb6d87..897c3512d1c7 100755 --- a/tools/docs/sphinx-build-wrapper +++ b/tools/docs/sphinx-build-wrapper @@ -725,7 +725,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, venv=3Dargs.venv, 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