Skip to content

Commit 9cbc2d3

Browse files
mchehabJonathan Corbet
authored andcommitted
scripts/kernel-doc.py: postpone warnings to the output plugin
We don't want to have warnings displayed for symbols that weren't output. So, postpone warnings print to the output plugin, where symbol output is validated. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/e6344711e390cf22af02a56bb5dd51ca67c0afb6.1744106242.git.mchehab+huawei@kernel.org
1 parent 9235ec5 commit 9cbc2d3

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

scripts/lib/kdoc/kdoc_output.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ def highlight_block(self, block):
116116

117117
return block
118118

119-
def check_doc(self, name):
119+
def out_warnings(self, args):
120+
warnings = args.get('warnings', [])
121+
122+
for warning, log_msg in warnings:
123+
if warning:
124+
self.config.log.warning(log_msg)
125+
else:
126+
self.config.log.info(log_msg)
127+
128+
def check_doc(self, name, args):
120129
"""Check if DOC should be output"""
121130

122131
if self.no_doc_sections:
@@ -126,19 +135,22 @@ def check_doc(self, name):
126135
return False
127136

128137
if self.out_mode == self.OUTPUT_ALL:
138+
self.out_warnings(args)
129139
return True
130140

131141
if self.out_mode == self.OUTPUT_INCLUDE:
132142
if name in self.function_table:
143+
self.out_warnings(args)
133144
return True
134145

135146
return False
136147

137-
def check_declaration(self, dtype, name):
148+
def check_declaration(self, dtype, name, args):
138149
if name in self.nosymbol:
139150
return False
140151

141152
if self.out_mode == self.OUTPUT_ALL:
153+
self.out_warnings(args)
142154
return True
143155

144156
if self.out_mode in [self.OUTPUT_INCLUDE, self.OUTPUT_EXPORTED]:
@@ -147,9 +159,11 @@ def check_declaration(self, dtype, name):
147159

148160
if self.out_mode == self.OUTPUT_INTERNAL:
149161
if dtype != "function":
162+
self.out_warnings(args)
150163
return True
151164

152165
if name not in self.function_table:
166+
self.out_warnings(args)
153167
return True
154168

155169
return False
@@ -163,7 +177,7 @@ def msg(self, fname, name, args):
163177
self.out_doc(fname, name, args)
164178
return self.data
165179

166-
if not self.check_declaration(dtype, name):
180+
if not self.check_declaration(dtype, name, args):
167181
return self.data
168182

169183
if dtype == "function":
@@ -328,7 +342,7 @@ def out_section(self, args, out_docblock=False):
328342
self.data += "\n"
329343

330344
def out_doc(self, fname, name, args):
331-
if not self.check_doc(name):
345+
if not self.check_doc(name, args):
332346
return
333347
self.out_section(args, out_docblock=True)
334348

@@ -586,7 +600,7 @@ def out_doc(self, fname, name, args):
586600
sectionlist = args.get('sectionlist', [])
587601
sections = args.get('sections', {})
588602

589-
if not self.check_doc(name):
603+
if not self.check_doc(name, args):
590604
return
591605

592606
self.data += f'.TH "{module}" 9 "{module}" "{self.man_date}" "API Manual" LINUX' + "\n"

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,23 @@ def __init__(self, config, fname):
131131
# Place all potential outputs into an array
132132
self.entries = []
133133

134-
def show_warnings(self, dtype, declaration_name): # pylint: disable=W0613
135-
"""
136-
Allow filtering out warnings
137-
"""
138-
139-
# TODO: implement it
140-
141-
return True
142-
143134
# TODO: rename to emit_message
144135
def emit_warning(self, ln, msg, warning=True):
145136
"""Emit a message"""
146137

138+
log_msg = f"{self.fname}:{ln} {msg}"
139+
140+
if self.entry:
141+
# Delegate warning output to output logic, as this way it
142+
# will report warnings/info only for symbols that are output
143+
144+
self.entry.warnings.append((warning, log_msg))
145+
return
146+
147147
if warning:
148-
self.config.log.warning("%s:%d %s", self.fname, ln, msg)
148+
self.config.log.warning(log_msg)
149149
else:
150-
self.config.log.info("%s:%d %s", self.fname, ln, msg)
150+
self.config.log.info(log_msg)
151151

152152
def dump_section(self, start_new=True):
153153
"""
@@ -221,10 +221,9 @@ def output_declaration(self, dtype, name, **args):
221221
# For now, we're keeping the same name of the function just to make
222222
# easier to compare the source code of both scripts
223223

224-
if "declaration_start_line" not in args:
225-
args["declaration_start_line"] = self.entry.declaration_start_line
226-
224+
args["declaration_start_line"] = self.entry.declaration_start_line
227225
args["type"] = dtype
226+
args["warnings"] = self.entry.warnings
228227

229228
# TODO: use colletions.OrderedDict
230229

@@ -257,6 +256,8 @@ def reset_state(self, ln):
257256
self.entry.struct_actual = ""
258257
self.entry.prototype = ""
259258

259+
self.entry.warnings = []
260+
260261
self.entry.parameterlist = []
261262
self.entry.parameterdescs = {}
262263
self.entry.parametertypes = {}
@@ -328,7 +329,7 @@ def push_parameter(self, ln, decl_type, param, dtype,
328329
if param not in self.entry.parameterdescs and not param.startswith("#"):
329330
self.entry.parameterdescs[param] = self.undescribed
330331

331-
if self.show_warnings(dtype, declaration_name) and "." not in param:
332+
if "." not in param:
332333
if decl_type == 'function':
333334
dname = f"{decl_type} parameter"
334335
else:
@@ -868,16 +869,14 @@ def dump_enum(self, ln, proto):
868869
self.entry.parameterlist.append(arg)
869870
if arg not in self.entry.parameterdescs:
870871
self.entry.parameterdescs[arg] = self.undescribed
871-
if self.show_warnings("enum", declaration_name):
872-
self.emit_warning(ln,
873-
f"Enum value '{arg}' not described in enum '{declaration_name}'")
872+
self.emit_warning(ln,
873+
f"Enum value '{arg}' not described in enum '{declaration_name}'")
874874
member_set.add(arg)
875875

876876
for k in self.entry.parameterdescs:
877877
if k not in member_set:
878-
if self.show_warnings("enum", declaration_name):
879-
self.emit_warning(ln,
880-
f"Excess enum value '%{k}' description in '{declaration_name}'")
878+
self.emit_warning(ln,
879+
f"Excess enum value '%{k}' description in '{declaration_name}'")
881880

882881
self.output_declaration('enum', declaration_name,
883882
enum=declaration_name,

0 commit comments

Comments
 (0)