Skip to content

Commit 11afeab

Browse files
mchehabJonathan Corbet
authored andcommitted
scripts/kernel-doc.py: Properly handle Werror and exit codes
The original kernel-doc script has a logic to return warnings as errors, and to report the number of warnings found, if in verbose mode. Implement it to be fully compatible with the original script. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/de33b0cebd9fdf82d8b221bcfe41db7269286222.1744106242.git.mchehab+huawei@kernel.org
1 parent e4b2bd9 commit 11afeab

4 files changed

Lines changed: 35 additions & 18 deletions

File tree

scripts/kernel-doc.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
# Yacine Belkadi <yacine.belkadi.1@gmail.com>
7979
# Yujie Liu <yujie.liu@intel.com>
8080

81-
# TODO: implement warning filtering
82-
8381
"""
8482
kernel_doc
8583
==========
@@ -295,6 +293,22 @@ def main():
295293
if msg:
296294
print(msg)
297295

296+
error_count = kfiles.errors
297+
if not error_count:
298+
sys.exit(0)
299+
300+
if args.werror:
301+
print(f"{error_count} warnings as errors")
302+
sys.exit(error_count)
303+
304+
if args.verbose:
305+
print(f"{error_count} errors")
306+
307+
if args.none:
308+
sys.exit(0)
309+
310+
sys.exit(error_count)
311+
298312

299313
# Call main method
300314
if __name__ == "__main__":

scripts/lib/kdoc/kdoc_files.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import logging
1313
import os
1414
import re
15-
import sys
1615

1716
from kdoc_parser import KernelDoc
1817
from kdoc_output import OutputFormat
@@ -109,7 +108,7 @@ def process_export_file(self, fname):
109108
KernelDoc.process_export(self.config.function_table, line)
110109

111110
except IOError:
112-
print(f"Error: Cannot open fname {fname}", fname=sys.stderr)
111+
self.config.log.error("Error: Cannot open fname %s", fname)
113112
self.config.errors += 1
114113

115114
def file_not_found_cb(self, fname):
@@ -262,3 +261,12 @@ def msg(self, enable_lineno=False, export=False, internal=False,
262261
fname, ln, dtype)
263262
if msg:
264263
yield fname, msg
264+
265+
@property
266+
def errors(self):
267+
"""
268+
Return a count of the number of warnings found, including
269+
the ones displayed while interacting over self.msg.
270+
"""
271+
272+
return self.config.errors

scripts/lib/kdoc/kdoc_output.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ def out_warnings(self, args):
128128

129129
warnings = args.get('warnings', [])
130130

131-
for warning, log_msg in warnings:
132-
if warning:
133-
self.config.log.warning(log_msg)
134-
else:
135-
self.config.log.info(log_msg)
131+
for log_msg in warnings:
132+
self.config.log.warning(log_msg)
133+
self.config.errors += 1
136134

137135
def check_doc(self, name, args):
138136
"""Check if DOC should be output"""

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ def emit_warning(self, ln, msg, warning=True):
137137

138138
log_msg = f"{self.fname}:{ln} {msg}"
139139

140+
if not warning:
141+
self.config.log.info(log_msg)
142+
return
143+
140144
if self.entry:
141145
# Delegate warning output to output logic, as this way it
142146
# will report warnings/info only for symbols that are output
143147

144-
self.entry.warnings.append((warning, log_msg))
148+
self.entry.warnings.append(log_msg)
145149
return
146150

147-
if warning:
148-
self.config.log.warning(log_msg)
149-
else:
150-
self.config.log.info(log_msg)
151+
self.config.log.warning(log_msg)
151152

152153
def dump_section(self, start_new=True):
153154
"""
@@ -556,7 +557,6 @@ def dump_struct(self, ln, proto):
556557

557558
if not members:
558559
self.emit_warning(ln, f"{proto} error: Cannot parse struct or union!")
559-
self.config.errors += 1
560560
return
561561

562562
if self.entry.identifier != declaration_name:
@@ -831,7 +831,6 @@ def dump_enum(self, ln, proto):
831831

832832
if not members:
833833
self.emit_warning(ln, f"{proto}: error: Cannot parse enum!")
834-
self.config.errors += 1
835834
return
836835

837836
if self.entry.identifier != declaration_name:
@@ -1132,7 +1131,6 @@ def dump_typedef(self, ln, proto):
11321131
return
11331132

11341133
self.emit_warning(ln, "error: Cannot parse typedef!")
1135-
self.config.errors += 1
11361134

11371135
@staticmethod
11381136
def process_export(function_table, line):
@@ -1677,4 +1675,3 @@ def run(self):
16771675
self.process_docblock(ln, line)
16781676
except OSError:
16791677
self.config.log.error(f"Error: Cannot open file {self.fname}")
1680-
self.config.errors += 1

0 commit comments

Comments
 (0)