[PATCH v3 25/33] scripts/kernel-doc.py: move modulename to man class

Mauro Carvalho Chehab
2025-04-08T10:09:56Z

Only man output requires a modulename. Move its definition
to the man class.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
scripts/kernel-doc.py | 6 +++---
scripts/lib/kdoc/kdoc_files.py | 6 +-----
scripts/lib/kdoc/kdoc_output.py | 12 ++++++------
scripts/lib/kdoc/kdoc_parser.py | 9 +--------
4 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/scripts/kernel-doc.py b/scripts/kernel-doc.py
index eca7e34f9d03..6a6bc81efd31 100755
--- a/scripts/kernel-doc.py
+++ b/scripts/kernel-doc.py
@@ -186,6 +186,7 @@ def main():
help="Enable debug messages")

parser.add_argument("-M", "-modulename", "--modulename",
+ default="Kernel API",
help="Allow setting a module name at the output.")

parser.add_argument("-l", "-enable-lineno", "--enable_lineno",
@@ -273,7 +274,7 @@ def main():
logger.addHandler(handler)

if args.man:
- out_style = ManFormat()
+ out_style = ManFormat(modulename=args.modulename)
elif args.none:
out_style = None
else:
@@ -282,8 +283,7 @@ def main():
kfiles = KernelFiles(verbose=args.verbose,
out_style=out_style, werror=args.werror,
wreturn=args.wreturn, wshort_desc=args.wshort_desc,
- wcontents_before_sections=args.wcontents_before_sections,
- modulename=args.modulename)
+ wcontents_before_sections=args.wcontents_before_sections)

kfiles.parse(args.files, export_file=args.export_file)

diff --git a/scripts/lib/kdoc/kdoc_files.py b/scripts/lib/kdoc/kdoc_files.py
index e2221db7022a..5a6e92e34d05 100644
--- a/scripts/lib/kdoc/kdoc_files.py
+++ b/scripts/lib/kdoc/kdoc_files.py
@@ -126,7 +126,7 @@ class KernelFiles():
def __init__(self, verbose=False, out_style=None,
werror=False, wreturn=False, wshort_desc=False,
wcontents_before_sections=False,
- logger=None, modulename=None):
+ logger=None):
"""
Initialize startup variables and parse all files
"""
@@ -134,9 +134,6 @@ class KernelFiles():
if not verbose:
verbose = bool(os.environ.get("KBUILD_VERBOSE", 0))

- if not modulename:
- modulename = "Kernel API"
-
if out_style is None:
out_style = OutputFormat()

@@ -168,7 +165,6 @@ class KernelFiles():
self.config.wreturn = wreturn
self.config.wshort_desc = wshort_desc
self.config.wcontents_before_sections = wcontents_before_sections
- self.config.modulename = modulename

self.config.function_table = set()
self.config.source_map = {}
diff --git a/scripts/lib/kdoc/kdoc_output.py b/scripts/lib/kdoc/kdoc_output.py
index e0ed79e4d985..8be69245c0d0 100755
--- a/scripts/lib/kdoc/kdoc_output.py
+++ b/scripts/lib/kdoc/kdoc_output.py
@@ -586,7 +586,7 @@ class ManFormat(OutputFormat):
)
blankline = ""

- def __init__(self):
+ def __init__(self, modulename):
"""
Creates class variables.

@@ -595,6 +595,7 @@ class ManFormat(OutputFormat):
"""

super().__init__()
+ self.modulename = modulename

dt = datetime.now()
if os.environ.get("KBUILD_BUILD_TIMESTAMP", None):
@@ -626,14 +627,13 @@ class ManFormat(OutputFormat):
self.data += line + "\n"

def out_doc(self, fname, name, args):
- module = args.get('module')
sectionlist = args.get('sectionlist', [])
sections = args.get('sections', {})

if not self.check_doc(name, args):
return

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

for section in sectionlist:
self.data += f'.SH "{section}"' + "\n"
@@ -697,7 +697,7 @@ class ManFormat(OutputFormat):
sectionlist = args.get('sectionlist', [])
sections = args.get('sections', {})

- self.data += f'.TH "{args["module"]}" 9 "enum {args["enum"]}" "{self.man_date}" "API Manual" LINUX' + "\n"
+ self.data += f'.TH "{self.modulename}" 9 "enum {args["enum"]}" "{self.man_date}" "API Manual" LINUX' + "\n"

self.data += ".SH NAME\n"
self.data += f"enum {args['enum']} \\- {args['purpose']}\n"
@@ -727,7 +727,7 @@ class ManFormat(OutputFormat):
self.output_highlight(sections[section])

def out_typedef(self, fname, name, args):
- module = args.get('module')
+ module = self.modulename
typedef = args.get('typedef')
purpose = args.get('purpose')
sectionlist = args.get('sectionlist', [])
@@ -743,7 +743,7 @@ class ManFormat(OutputFormat):
self.output_highlight(sections.get(section))

def out_struct(self, fname, name, args):
- module = args.get('module')
+ module = self.modulename
struct_type = args.get('type')
struct_name = args.get('struct')
purpose = args.get('purpose')
diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index e48ed128ca04..f923600561f8 100755
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -791,7 +791,6 @@ class KernelDoc:

self.output_declaration(decl_type, declaration_name,
struct=declaration_name,
- module=self.entry.modulename,
definition=declaration,
parameterlist=self.entry.parameterlist,
parameterdescs=self.entry.parameterdescs,
@@ -869,7 +868,6 @@ class KernelDoc:

self.output_declaration('enum', declaration_name,
enum=declaration_name,
- module=self.config.modulename,
parameterlist=self.entry.parameterlist,
parameterdescs=self.entry.parameterdescs,
parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
@@ -1040,7 +1038,6 @@ class KernelDoc:
self.output_declaration(decl_type, declaration_name,
function=declaration_name,
typedef=True,
- module=self.config.modulename,
functiontype=return_type,
parameterlist=self.entry.parameterlist,
parameterdescs=self.entry.parameterdescs,
@@ -1055,7 +1052,6 @@ class KernelDoc:
self.output_declaration(decl_type, declaration_name,
function=declaration_name,
typedef=False,
- module=self.config.modulename,
functiontype=return_type,
parameterlist=self.entry.parameterlist,
parameterdescs=self.entry.parameterdescs,
@@ -1102,7 +1098,6 @@ class KernelDoc:
self.output_declaration(decl_type, declaration_name,
function=declaration_name,
typedef=True,
- module=self.entry.modulename,
functiontype=return_type,
parameterlist=self.entry.parameterlist,
parameterdescs=self.entry.parameterdescs,
@@ -1130,7 +1125,6 @@ class KernelDoc:

self.output_declaration('typedef', declaration_name,
typedef=declaration_name,
- module=self.entry.modulename,
sectionlist=self.entry.sectionlist,
sections=self.entry.sections,
section_start_lines=self.entry.section_start_lines,
@@ -1619,8 +1613,7 @@ class KernelDoc:
self.output_declaration("doc", self.entry.identifier,
sectionlist=self.entry.sectionlist,
sections=self.entry.sections,
- section_start_lines=self.entry.section_start_lines,
- module=self.config.modulename)
+ section_start_lines=self.entry.section_start_lines)
self.reset_state(ln)

elif doc_content.search(line):
--
2.49.0