Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp316067pxu; Tue, 6 Oct 2020 07:09:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbYw7xhnPGtwI4Cahwpw5XL+fDAtrYPRuuvYZG2gLGboE2mOgHuYaztDIhROnrHFsxJAjY X-Received: by 2002:a17:906:a59:: with SMTP id x25mr5262151ejf.489.1601993396261; Tue, 06 Oct 2020 07:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601993396; cv=none; d=google.com; s=arc-20160816; b=LKTHAtJLFbRBdgx02o2SrXuptnNtvUzyfnzhQlqQ6uN1PTBQWpygB/0S8jqWvRQpaa HYA5NhuNgJajSP4Egomobmzvij09Xok4XxfB7Kd0PSjRw5pBvl/btphOcqE4CJRkUcac HYHIJpNfUuhuBtO/U5BPgwYMU4EF1v6too3IU5rCBRA7JZX6x0N1L/R7pAYmA0dQ0I4c lCGuAdjQRVop72ilnZ7BZ+m3GNQMmqvcIuOiDFVHfzZzVErsbpCxieuqUngnKGLkMrCr xYpqI4nOrX3YFQl1oXOPLyMQqgIXYdKefHgJGpzP7Sg/4BnCyhw/inwRbpedMa35VqxX mM5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8hEkzV6zlfXcnpi3l/eeU1ln0gGAtPmNJaI1ZZ0l6As=; b=eg5bvOqi+ULsxWivuibxMmTjvLGSk6QTXTosngIYO4JMNo++HBFuo7KLWlIxhdN8x4 w0/n/mvA83JzhvA+jmiTlpCr8fKWpHO0TX7UZdpGtLFy6GOX/c+HtFb+LZ0kbfL2HfFJ ChGUbBrzGl4OZY/kNxl1PDPLZ1eBXd6838XexwVRZTTC2Fnkrmiu7CtBXq2QbeaCbw42 2T53lCEYxWa7GCXQfaYX8D8tjrkPANp1IfJ0yCzXw9VRQXHzVvwKCVINSKDsXAixJfA3 sM96NBp8IQaHrnWXxbkkDYFb1ASEGm/1qMhBmWh4YYptpsKhJ4nOZCp79GoE0MKUGWhz K/BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ibb5VP+r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si2910370edy.300.2020.10.06.07.09.28; Tue, 06 Oct 2020 07:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ibb5VP+r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727095AbgJFOHN (ORCPT + 99 others); Tue, 6 Oct 2020 10:07:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:33164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726241AbgJFODz (ORCPT ); Tue, 6 Oct 2020 10:03:55 -0400 Received: from mail.kernel.org (ip5f5ad5bd.dynamic.kabel-deutschland.de [95.90.213.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7FEDA2087E; Tue, 6 Oct 2020 14:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601993033; bh=KNCXzYh/acJnJFeYKV6JscUEBLkELaNTa2VvLuVSoNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ibb5VP+rgYK3FD13BMcSxiNut08JYy/i3E+lgrykCTnoh9u9nJc38m7OcByhCM+Uc KjeSQAb9xrMHRtN3STIPpEqbsz6oie4LIuNphPAQ0qW35q383bsvHHu1rsNXAlwO2b NbBxdrq6jbWv4COEVi+R6FZddTEpod/TUhNV6ePs= Received: from mchehab by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1kPnZH-0019Et-BP; Tue, 06 Oct 2020 16:03:51 +0200 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , Changbin Du , linux-kernel@vger.kernel.org Subject: [PATCH v5 10/52] scripts: kernel-doc: allow passing desired Sphinx C domain dialect Date: Tue, 6 Oct 2020 16:03:07 +0200 Message-Id: <9e9301fadc02986b9c2709db50a4d6b98db3d9fa.1601992016.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Documentation/sphinx/kerneldoc.py | 5 ++++ scripts/kernel-doc | 44 +++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerneldoc.py index 4bcbd6ae01cd..1a1b12242a45 100644 --- a/Documentation/sphinx/kerneldoc.py +++ b/Documentation/sphinx/kerneldoc.py @@ -70,6 +70,11 @@ class KernelDocDirective(Directive): env = self.state.document.settings.env cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno'] + # Pass the version string to kernel-doc, as it needs to use a different + # dialect, depending what the C domain supports for each specific + # Sphinx versions + cmd += ['-sphinx-version', sphinx.__version__] + filename = env.config.kerneldoc_srctree + '/' + self.arguments[0] export_file_patterns = [] diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 09e3e78b9723..9881f08cf75c 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. +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 == -1) { } my $kernelversion; -my $sphinx_major; +my ($sphinx_major, $sphinx_minor, $sphinx_patch); my $dohighlight = ""; @@ -457,6 +464,19 @@ while ($ARGV[0] =~ m/^--?(.*)/) { $enable_lineno = 1; } elsif ($cmd eq 'show-not-found') { $show_not_found = 1; # A no-op but don't fail + } elsif ($cmd eq "sphinx-version") { + my $ver_string = shift @ARGV; + if ($ver_string =~ m/^(\d+)\.(\d+)(\.\d+)?/) { + $sphinx_major = $1; + $sphinx_minor = $2; + if (defined($3)) { + $sphinx_patch = substr($3,1); + } else { + $sphinx_patch = 0; + } + } else { + die "Sphinx version should either major.minor or major.minor.patch format\n"; + } } else { # Unknown argument usage(); @@ -477,29 +497,37 @@ sub findprog($) sub get_sphinx_version() { my $ver; - my $major = 1; my $cmd = "sphinx-build"; if (!findprog($cmd)) { my $cmd = "sphinx-build3"; - return $major if (!findprog($cmd)); + if (!findprog($cmd)) { + $sphinx_major = 1; + $sphinx_minor = 2; + $sphinx_patch = 0; + printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", + $sphinx_major, $sphinx_minor, $sphinx_patch; + return; + } } open IN, "$cmd --version 2>&1 |"; while () { if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { - $major=$1; + $sphinx_major = $1; + $sphinx_minor = $2; + $sphinx_patch = $3; last; } # Sphinx 1.2.x uses a different format if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { - $major=$1; + $sphinx_major = $1; + $sphinx_minor = $2; + $sphinx_patch = $3; last; } } close IN; - - return $major; } # get kernel version from env @@ -2333,7 +2361,7 @@ sub process_file($) { } -$sphinx_major = get_sphinx_version(); +get_sphinx_version() if (!$sphinx_major); $kernelversion = get_kernel_version(); # generate a sequence of code that will splice in highlighting information -- 2.26.2