Skip to content

Commit 152d196

Browse files
committed
kernel-doc: Use c:struct for Sphinx 3.0 and later
The kernel-doc Sphinx plugin and associated script currently emit 'c:type' directives for "struct foo" documentation. Sphinx 3.0 warns about this: /home/petmay01/linaro/qemu-from-laptop/qemu/docs/../include/exec/memory.h:3: WARNING: Type must be either just a name or a typedef-like declaration. If just a name: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name, got keyword: struct [error at 6] struct MemoryListener ------^ If typedef-like declaration: Error in declarator or parameters Invalid C declaration: Expected identifier in nested name. [error at 21] struct MemoryListener ---------------------^ because it wants us to use the new-in-3.0 'c:struct' instead. Plumb the Sphinx version through to the kernel-doc script and use it to select 'c:struct' for newer versions than 3.0. Fixes: LP:1872113 Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Alex Bennée <[email protected]>
1 parent a62d563 commit 152d196

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docs/sphinx/kerneldoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def run(self):
9999
env.note_dependency(os.path.abspath(f))
100100
cmd += ['-export-file', f]
101101

102+
cmd += ['-sphinx-version', sphinx.__version__]
102103
cmd += [filename]
103104

104105
try:

scripts/kernel-doc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Output selection (mutually exclusive):
7171
DOC: sections. May be specified multiple times.
7272
7373
Output selection modifiers:
74+
-sphinx-version VER Generate rST syntax for the specified Sphinx version.
75+
Only works with reStructuredTextFormat.
7476
-no-doc-sections Do not output DOC: sections.
7577
-enable-lineno Enable output of #define LINENO lines. Only works with
7678
reStructuredText format.
@@ -286,6 +288,7 @@ use constant {
286288
};
287289
my $output_selection = OUTPUT_ALL;
288290
my $show_not_found = 0; # No longer used
291+
my $sphinx_version = "0.0"; # if not specified, assume old
289292

290293
my @export_file_list;
291294

@@ -436,6 +439,8 @@ while ($ARGV[0] =~ m/^--?(.*)/) {
436439
$enable_lineno = 1;
437440
} elsif ($cmd eq 'show-not-found') {
438441
$show_not_found = 1; # A no-op but don't fail
442+
} elsif ($cmd eq 'sphinx-version') {
443+
$sphinx_version = shift @ARGV;
439444
} else {
440445
# Unknown argument
441446
usage();
@@ -963,7 +968,16 @@ sub output_struct_rst(%) {
963968
my $oldprefix = $lineprefix;
964969
my $name = $args{'type'} . " " . $args{'struct'};
965970

966-
print "\n\n.. c:type:: " . $name . "\n\n";
971+
# Sphinx 3.0 and up will emit warnings for "c:type:: struct Foo".
972+
# It wants to see "c:struct:: Foo" (and will add the word 'struct' in
973+
# the rendered output).
974+
if ((split(/\./, $sphinx_version))[0] >= 3) {
975+
my $sname = $name;
976+
$sname =~ s/^struct //;
977+
print "\n\n.. c:struct:: " . $sname . "\n\n";
978+
} else {
979+
print "\n\n.. c:type:: " . $name . "\n\n";
980+
}
967981
print_lineno($declaration_start_line);
968982
$lineprefix = " ";
969983
output_highlight_rst($args{'purpose'});

0 commit comments

Comments
 (0)