Commit 089e06c3 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Jonathan Corbet
Browse files

scripts/kernel-doc: drop Sphinx version check



As the current minimal supported Sphinx version is 3.4.3, drop
support for older versions.

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: default avatarKees Cook <kees@kernel.org>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/0d002e7550476a68547ee53ad06cfd8fdcaf7c3a.1739254187.git.mchehab+huawei@kernel.org
parent 8def4042
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -45,9 +45,6 @@ import re

__version__  = '1.1'

# Get Sphinx version
major, minor, patch = sphinx.version_info[:3]

# Namespace to be prepended to the full name
namespace = None

+0 −5
Original line number Diff line number Diff line
@@ -62,11 +62,6 @@ 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 = []

+16 −113
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ kernel-doc - Print formatted kernel documentation to stdout

 kernel-doc [-h] [-v] [-Werror] [-Wall] [-Wreturn] [-Wshort-desc[ription]] [-Wcontents-before-sections]
   [ -man |
     -rst [-sphinx-version VERSION] [-enable-lineno] |
     -rst [-enable-lineno] |
     -none
   ]
   [
@@ -130,7 +130,6 @@ if ($#ARGV == -1) {
}

my $kernelversion;
my ($sphinx_major, $sphinx_minor, $sphinx_patch);

my $dohighlight = "";

@@ -347,23 +346,6 @@ 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;
            if (defined($2)) {
                $sphinx_minor = substr($2,1);
            } else {
                $sphinx_minor = 0;
            }
            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
        pod2usage(
@@ -387,8 +369,6 @@ while ($ARGV[0] =~ m/^--?(.*)/) {

# continue execution near EOF;

# The C domain dialect changed on Sphinx 3. So, we need to check the
# version in order to produce the right tags.
sub findprog($)
{
    foreach(split(/:/, $ENV{PATH})) {
@@ -396,42 +376,6 @@ sub findprog($)
    }
}

sub get_sphinx_version()
{
    my $ver;

    my $cmd = "sphinx-build";
    if (!findprog($cmd)) {
        my $cmd = "sphinx-build3";
        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 (<IN>) {
        if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) {
            $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\.]+)$/) {
            $sphinx_major = $1;
            $sphinx_minor = $2;
            $sphinx_patch = $3;
            last;
        }
    }
    close IN;
}

# get kernel version from env
sub get_kernel_version() {
    my $version = 'unknown kernel version';
@@ -859,19 +803,6 @@ sub output_function_rst(%) {
    	$signature .= ")";
    }

    if ($sphinx_major < 3) {
        if ($args{'typedef'}) {
            print ".. c:type:: ". $args{'function'} . "\n\n";
            print_lineno($declaration_start_line);
            print "   **Typedef**: ";
            $lineprefix = "";
            output_highlight_rst($args{'purpose'});
            print "\n\n**Syntax**\n\n";
            print "  ``$signature``\n\n";
        } else {
            print ".. c:function:: $signature\n\n";
        }
    } else {
    if ($args{'typedef'} || $args{'functiontype'} eq "") {
        print ".. c:macro:: ". $args{'function'} . "\n\n";

@@ -888,7 +819,6 @@ sub output_function_rst(%) {
    } else {
        print ".. c:function:: $signature\n\n";
    }
    }

    if (!$args{'typedef'}) {
        print_lineno($declaration_start_line);
@@ -955,13 +885,9 @@ sub output_enum_rst(%) {
    my $count;
    my $outer;

    if ($sphinx_major < 3) {
        my $name = "enum " . $args{'enum'};
        print "\n\n.. c:type:: " . $name . "\n\n";
    } else {
    my $name = $args{'enum'};
    print "\n\n.. c:enum:: " . $name . "\n\n";
    }

    print_lineno($declaration_start_line);
    $lineprefix = "  ";
    output_highlight_rst($args{'purpose'});
@@ -992,11 +918,8 @@ sub output_typedef_rst(%) {
    my $oldprefix = $lineprefix;
    my $name;

    if ($sphinx_major < 3) {
        $name = "typedef " . $args{'typedef'};
    } else {
    $name = $args{'typedef'};
    }

    print "\n\n.. c:type:: " . $name . "\n\n";
    print_lineno($declaration_start_line);
    $lineprefix = "   ";
@@ -1012,17 +935,13 @@ sub output_struct_rst(%) {
    my ($parameter);
    my $oldprefix = $lineprefix;

    if ($sphinx_major < 3) {
        my $name = $args{'type'} . " " . $args{'struct'};
        print "\n\n.. c:type:: " . $name . "\n\n";
    } else {
    my $name = $args{'struct'};
    if ($args{'type'} eq 'union') {
        print "\n\n.. c:union:: " . $name . "\n\n";
    } else {
        print "\n\n.. c:struct:: " . $name . "\n\n";
    }
    }

    print_lineno($declaration_start_line);
    $lineprefix = "  ";
    output_highlight_rst($args{'purpose'});
@@ -2383,11 +2302,6 @@ sub process_file($) {
    close IN_FILE;
}


if ($output_mode eq "rst") {
    get_sphinx_version() if (!$sphinx_major);
}

$kernelversion = get_kernel_version();

# generate a sequence of code that will splice in highlighting information
@@ -2454,17 +2368,6 @@ Do not output documentation, only warnings.

=head3 reStructuredText only

=over 8

=item -sphinx-version VERSION

Use the ReST C domain dialect compatible with a specific Sphinx Version.

If not specified, kernel-doc will auto-detect using the sphinx-build version
found on PATH.

=back

=head2 Output selection (mutually exclusive):

=over 8