Skip to content

Commit 56b0f45

Browse files
jmberg-intelmasahir0y
authored andcommitted
kernel-doc: don't let V=1 change outcome
The kernel-doc script currently reports a number of issues only in "verbose" mode, but that's initialized from V=1 (via KBUILD_VERBOSE), so if you use KDOC_WERROR=1 then adding V=1 might actually break the build. This is rather unexpected. Change kernel-doc to not change its behaviour wrt. errors (or warnings) when verbose mode is enabled, but rather add separate warning flags (and -Wall) for it. Allow enabling those flags via environment/make variables in the kernel's build system for easier user use, but to not have to parse them in the script itself. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Acked-by: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 3a3f1e5 commit 56b0f45

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

Documentation/kbuild/kbuild.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ the UTS_MACHINE variable, and on some architectures also the kernel config.
150150
The value of KBUILD_DEBARCH is assumed (not checked) to be a valid Debian
151151
architecture.
152152

153+
KDOCFLAGS
154+
---------
155+
Specify extra (warning/error) flags for kernel-doc checks during the build,
156+
see scripts/kernel-doc for which flags are supported. Note that this doesn't
157+
(currently) apply to documentation builds.
158+
153159
ARCH
154160
----
155161
Set ARCH to the architecture to be built.

scripts/Makefile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ else ifeq ($(KBUILD_CHECKSRC),2)
101101
endif
102102

103103
ifneq ($(KBUILD_EXTRA_WARN),)
104-
cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
104+
cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $(KDOCFLAGS) $<
105105
endif
106106

107107
# Compile C sources (.c)

scripts/kernel-doc

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ kernel-doc - Print formatted kernel documentation to stdout
2323
2424
=head1 SYNOPSIS
2525
26-
kernel-doc [-h] [-v] [-Werror]
26+
kernel-doc [-h] [-v] [-Werror] [-Wall] [-Wreturn] [-Wshort-description] [-Wcontents-before-sections]
2727
[ -man |
2828
-rst [-sphinx-version VERSION] [-enable-lineno] |
2929
-none
@@ -133,6 +133,9 @@ my $dohighlight = "";
133133

134134
my $verbose = 0;
135135
my $Werror = 0;
136+
my $Wreturn = 0;
137+
my $Wshort_desc = 0;
138+
my $Wcontents_before_sections = 0;
136139
my $output_mode = "rst";
137140
my $output_preformatted = 0;
138141
my $no_doc_sections = 0;
@@ -187,9 +190,14 @@ if (defined($ENV{'KCFLAGS'})) {
187190
}
188191
}
189192

193+
# reading this variable is for backwards compat just in case
194+
# someone was calling it with the variable from outside the
195+
# kernel's build system
190196
if (defined($ENV{'KDOC_WERROR'})) {
191197
$Werror = "$ENV{'KDOC_WERROR'}";
192198
}
199+
# other environment variables are converted to command-line
200+
# arguments in cmd_checkdoc in the build system
193201

194202
# Generated docbook code is inserted in a template at a point where
195203
# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
@@ -318,6 +326,16 @@ while ($ARGV[0] =~ m/^--?(.*)/) {
318326
$verbose = 1;
319327
} elsif ($cmd eq "Werror") {
320328
$Werror = 1;
329+
} elsif ($cmd eq "Wreturn") {
330+
$Wreturn = 1;
331+
} elsif ($cmd eq "Wshort-desc") {
332+
$Wshort_desc = 1;
333+
} elsif ($cmd eq "Wcontents-before-sections") {
334+
$Wcontents_before_sections = 1;
335+
} elsif ($cmd eq "Wall") {
336+
$Wreturn = 1;
337+
$Wshort_desc = 1;
338+
$Wcontents_before_sections = 1;
321339
} elsif (($cmd eq "h") || ($cmd eq "help")) {
322340
pod2usage(-exitval => 0, -verbose => 2);
323341
} elsif ($cmd eq 'no-doc-sections') {
@@ -1748,9 +1766,9 @@ sub dump_function($$) {
17481766
# This check emits a lot of warnings at the moment, because many
17491767
# functions don't have a 'Return' doc section. So until the number
17501768
# of warnings goes sufficiently down, the check is only performed in
1751-
# verbose mode.
1769+
# -Wreturn mode.
17521770
# TODO: always perform the check.
1753-
if ($verbose && !$noret) {
1771+
if ($Wreturn && !$noret) {
17541772
check_return_section($file, $declaration_name, $return_type);
17551773
}
17561774

@@ -2054,7 +2072,7 @@ sub process_name($$) {
20542072
$state = STATE_NORMAL;
20552073
}
20562074

2057-
if (($declaration_purpose eq "") && $verbose) {
2075+
if (($declaration_purpose eq "") && $Wshort_desc) {
20582076
emit_warning("${file}:$.", "missing initial short description on line:\n$_");
20592077
}
20602078

@@ -2103,7 +2121,7 @@ sub process_body($$) {
21032121
}
21042122

21052123
if (($contents ne "") && ($contents ne "\n")) {
2106-
if (!$in_doc_sect && $verbose) {
2124+
if (!$in_doc_sect && $Wcontents_before_sections) {
21072125
emit_warning("${file}:$.", "contents before sections\n");
21082126
}
21092127
dump_section($file, $section, $contents);

0 commit comments

Comments
 (0)