From nobody Mon Feb 9 19:37:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606901397; cv=none; d=zohomail.com; s=zohoarc; b=SwfJfCnVDz1BYIpKp9l/HPJNlIFxaLIVFfS2h9dI0dy7nTeecqkYkdOpIl17ZBjwFClj8/OgmcodThkSIRCCWC7ohXOKugmSlv7h2Uuj+lnOveqHwHg2SO3YOzaMvZ5cGx9C9C4YHvtlwSPS8MVgncYKq6NXujPKxUyzuqvoUfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606901397; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ukg5Y1cAgqxZBGLArhGZ7RHHMiikRdI3w0My8dsythw=; b=X1H2iy/CuAckRXcJTk6xDxeR5M1tToEuMdL2y4rcYu53bZksx0Im8WCc+NxPZn6o3/ohcVd1q+Ez8Qcf1vVQ5Y7p4gXWjFoS5Lb1eC/lyeTCYH8N9hYxJo1B01NGLk9ex8ps3jDU0PNap8Voec7vH4zJrnSq+Q7UtNqyi1jKK0g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606901397216471.83122328125046; Wed, 2 Dec 2020 01:29:57 -0800 (PST) Received: from localhost ([::1]:56902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkOCn-0007t2-4Q for importer@patchew.org; Wed, 02 Dec 2020 04:13:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkNDQ-00042E-Ew for qemu-devel@nongnu.org; Wed, 02 Dec 2020 03:10:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36330) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkNCf-0003rp-0H for qemu-devel@nongnu.org; Wed, 02 Dec 2020 03:10:20 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-382-UlrWcBnZN4O6CLkRHc-x6w-1; Wed, 02 Dec 2020 03:09:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24535185E48B for ; Wed, 2 Dec 2020 08:09:29 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC4FA60854 for ; Wed, 2 Dec 2020 08:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606896572; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ukg5Y1cAgqxZBGLArhGZ7RHHMiikRdI3w0My8dsythw=; b=T4a+YT11iGOWVAU8T0dFT2JUOjtsHRJm8YHMHOO2sj3D0AWOWLx2JliYFmnB9oSph2nS+V xBV0Ihr/GZoMXB9qnEYkwTg6CJv7CMKOA0Iop8ivqWkIw3MM4BOf0VIypGzSFX7xkkHja7 FFMY3vDbBqZiCo94U/GlFJQaXBpTyVo= X-MC-Unique: UlrWcBnZN4O6CLkRHc-x6w-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 104/113] scripts: kernel-doc: allow passing desired Sphinx C domain dialect Date: Wed, 2 Dec 2020 03:08:40 -0500 Message-Id: <20201202080849.4125477-105-pbonzini@redhat.com> In-Reply-To: <20201202080849.4125477-1-pbonzini@redhat.com> References: <20201202080849.4125477-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Mauro Carvalho Chehab When kernel-doc is called via kerneldoc.py, there's no need to auto-detect the Sphinx version, as the Sphinx module already knows it. So, add an optional parameter to allow changing the Sphinx dialect. As kernel-doc can also be manually called, keep the auto-detection logic if the parameter was not specified. On such case, emit a warning if sphinx-build can't be found at PATH. I ended using a suggestion from Joe for using a more readable regex, instead of using a complex one with a hidden group like: m/^(\d+)\.(\d+)(?:\.?(\d+)?)/ in order to get the optional argument. Thanks-to: Joe Perches Suggested-by: Jonathan Corbet Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Paolo Bonzini Message-Id: <20201117165312.118257-23-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- docs/sphinx/kerneldoc.py | 5 ++++ scripts/kernel-doc | 51 +++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py index c0180e02a2..079aadced3 100644 --- a/docs/sphinx/kerneldoc.py +++ b/docs/sphinx/kerneldoc.py @@ -69,6 +69,11 @@ class KernelDocDirective(Directive): env =3D self.state.document.settings.env cmd =3D env.config.kerneldoc_bin + ['-rst', '-enable-lineno'] =20 + # Pass the version string to kernel-doc, as it needs to use a diff= erent + # dialect, depending what the C domain supports for each specific + # Sphinx versions + cmd +=3D ['-sphinx-version', sphinx.__version__] + filename =3D env.config.kerneldoc_srctree + '/' + self.arguments[0] export_file_patterns =3D [] =20 diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 478037f736..667ad3169c 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -56,6 +56,13 @@ Output format selection (mutually exclusive): -rst Output reStructuredText format. -none Do not output documentation, only warnings. =20 +Output format selection modifier (affects only ReST output): + + -sphinx-version Use the ReST C domain dialect compatible with an + specific Sphinx Version. + If not specified, kernel-doc will auto-detect using + the sphinx-build version found on PATH. + Output selection (mutually exclusive): -export Only output documentation for symbols that have been exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() @@ -270,7 +277,7 @@ if ($#ARGV =3D=3D -1) { } =20 my $kernelversion; -my $sphinx_major; +my ($sphinx_major, $sphinx_minor, $sphinx_patch); =20 my $dohighlight =3D ""; =20 @@ -457,6 +464,23 @@ while ($ARGV[0] =3D~ m/^--?(.*)/) { $enable_lineno =3D 1; } elsif ($cmd eq 'show-not-found') { $show_not_found =3D 1; # A no-op but don't fail + } elsif ($cmd eq "sphinx-version") { + my $ver_string =3D shift @ARGV; + if ($ver_string =3D~ m/^(\d+)(\.\d+)?(\.\d+)?/) { + $sphinx_major =3D $1; + if (defined($2)) { + $sphinx_minor =3D substr($2,1); + } else { + $sphinx_minor =3D 0; + } + if (defined($3)) { + $sphinx_patch =3D substr($3,1) + } else { + $sphinx_patch =3D 0; + } + } else { + die "Sphinx version should either major.minor or major.minor.patch fo= rmat\n"; + } } else { # Unknown argument usage(); @@ -477,29 +501,37 @@ sub findprog($) sub get_sphinx_version() { my $ver; - my $major =3D 1; =20 my $cmd =3D "sphinx-build"; if (!findprog($cmd)) { my $cmd =3D "sphinx-build3"; - return $major if (!findprog($cmd)); + if (!findprog($cmd)) { + $sphinx_major =3D 1; + $sphinx_minor =3D 2; + $sphinx_patch =3D 0; + printf STDERR "Warning: Sphinx version not found. Using default (Sphinx= version %d.%d.%d)\n", + $sphinx_major, $sphinx_minor, $sphinx_patch; + return; + } } =20 open IN, "$cmd --version 2>&1 |"; while () { if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { - $major=3D$1; + $sphinx_major =3D $1; + $sphinx_minor =3D $2; + $sphinx_patch =3D $3; last; } # Sphinx 1.2.x uses a different format if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { - $major=3D$1; + $sphinx_major =3D $1; + $sphinx_minor =3D $2; + $sphinx_patch =3D $3; last; } } close IN; - - return $major; } =20 # get kernel version from env @@ -2333,7 +2365,10 @@ sub process_file($) { } =20 =20 -$sphinx_major =3D get_sphinx_version(); +if ($output_mode eq "rst") { + get_sphinx_version() if (!$sphinx_major); +} + $kernelversion =3D get_kernel_version(); =20 # generate a sequence of code that will splice in highlighting information --=20 2.26.2