Skip to content

Commit 2c12c81

Browse files
plbossartJonathan Corbet
authored andcommitted
scripts/kernel-doc: optionally treat warnings as errors
The kbuild bot recently added the W=1 option, which triggered documentation cleanups to squelch hundreds of kernel-doc warnings. To make sure new kernel contributions don't add regressions to kernel-doc descriptors, this patch suggests an option to treat warnings as errors in CI/automated tests. A -Werror command-line option is added to the kernel-doc script. When this option is set, the script will return the number of warnings found. The caller can then treat this positive return value as an error and stop the build. Using this command line option is however not straightforward when the kernel-doc script is called from other scripts. To align with typical kernel compilation or documentation generation, the Werror option is also set by checking the KCFLAGS environment variable, or if KDOC_WERROR is defined, as in the following examples: KCFLAGS="-Wall -Werror" make W=1 sound/ KCFLAGS="-Wall -Werror" make W=1 drivers/soundwire/ KDOC_WERROR=1 make htmldocs Note that in the last example the documentation build does not stop, only an additional log is provided. Credits to Randy Dunlap for suggesting the use of environment variables. Suggested-by: Randy Dunlap <[email protected]> Signed-off-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Corbet <[email protected]>
1 parent d4210f7 commit 2c12c81

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

scripts/kernel-doc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Output selection modifiers:
8181
Other parameters:
8282
-v Verbose output, more warnings and other information.
8383
-h Print this help.
84+
-Werror Treat warnings as errors.
8485
8586
EOF
8687
print $message;
@@ -273,6 +274,7 @@ my $kernelversion;
273274
my $dohighlight = "";
274275

275276
my $verbose = 0;
277+
my $Werror = 0;
276278
my $output_mode = "rst";
277279
my $output_preformatted = 0;
278280
my $no_doc_sections = 0;
@@ -319,6 +321,18 @@ if (defined($ENV{'KBUILD_VERBOSE'})) {
319321
$verbose = "$ENV{'KBUILD_VERBOSE'}";
320322
}
321323

324+
if (defined($ENV{'KDOC_WERROR'})) {
325+
$Werror = "$ENV{'KDOC_WERROR'}";
326+
}
327+
328+
if (defined($ENV{'KCFLAGS'})) {
329+
my $kcflags = "$ENV{'KCFLAGS'}";
330+
331+
if ($kcflags =~ /Werror/) {
332+
$Werror = 1;
333+
}
334+
}
335+
322336
# Generated docbook code is inserted in a template at a point where
323337
# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
324338
# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
@@ -433,6 +447,8 @@ while ($ARGV[0] =~ m/^--?(.*)/) {
433447
push(@export_file_list, $file);
434448
} elsif ($cmd eq "v") {
435449
$verbose = 1;
450+
} elsif ($cmd eq "Werror") {
451+
$Werror = 1;
436452
} elsif (($cmd eq "h") || ($cmd eq "help")) {
437453
usage();
438454
} elsif ($cmd eq 'no-doc-sections') {
@@ -2262,4 +2278,9 @@ if ($verbose && $warnings) {
22622278
print STDERR "$warnings warnings\n";
22632279
}
22642280

2265-
exit($output_mode eq "none" ? 0 : $errors);
2281+
if ($Werror && $warnings) {
2282+
print STDERR "$warnings warnings as Errors\n";
2283+
exit($warnings);
2284+
} else {
2285+
exit($output_mode eq "none" ? 0 : $errors)
2286+
}

0 commit comments

Comments
 (0)