1eba6ffd1SJonathan Corbet#!/usr/bin/env python3 2eba6ffd1SJonathan Corbet# SPDX-License-Identifier: GPL-2.0 3eba6ffd1SJonathan Corbet# Copyright(c) 2025: Mauro Carvalho Chehab <mchehab@kernel.org>. 4eba6ffd1SJonathan Corbet# 5eba6ffd1SJonathan Corbet# pylint: disable=C0103,R0912,R0914,R0915 6eba6ffd1SJonathan Corbet# 7eba6ffd1SJonathan Corbet# NOTE: While kernel-doc requires at least version 3.6 to run, the 8eba6ffd1SJonathan Corbet# command line should work with Python 3.2+ (tested with 3.4). 9eba6ffd1SJonathan Corbet# The rationale is that it shall fail gracefully during Kernel 10eba6ffd1SJonathan Corbet# compilation with older Kernel versions. Due to that: 11eba6ffd1SJonathan Corbet# - encoding line is needed here; 12eba6ffd1SJonathan Corbet# - f-strings cannot be used in this file. 13eba6ffd1SJonathan Corbet# - libraries that require newer versions can only be included 14eba6ffd1SJonathan Corbet# after the Python version has been checked. 15eba6ffd1SJonathan Corbet# 16eba6ffd1SJonathan Corbet# Converted from the kernel-doc script originally written in Perl 17eba6ffd1SJonathan Corbet# under GPLv2, copyrighted since 1998 by the following authors: 18eba6ffd1SJonathan Corbet# 19eba6ffd1SJonathan Corbet# Aditya Srivastava <yashsri421@gmail.com> 20eba6ffd1SJonathan Corbet# Akira Yokosawa <akiyks@gmail.com> 21eba6ffd1SJonathan Corbet# Alexander A. Klimov <grandmaster@al2klimov.de> 22eba6ffd1SJonathan Corbet# Alexander Lobakin <aleksander.lobakin@intel.com> 23eba6ffd1SJonathan Corbet# André Almeida <andrealmeid@igalia.com> 24eba6ffd1SJonathan Corbet# Andy Shevchenko <andriy.shevchenko@linux.intel.com> 25eba6ffd1SJonathan Corbet# Anna-Maria Behnsen <anna-maria@linutronix.de> 26eba6ffd1SJonathan Corbet# Armin Kuster <akuster@mvista.com> 27eba6ffd1SJonathan Corbet# Bart Van Assche <bart.vanassche@sandisk.com> 28eba6ffd1SJonathan Corbet# Ben Hutchings <ben@decadent.org.uk> 29eba6ffd1SJonathan Corbet# Borislav Petkov <bbpetkov@yahoo.de> 30eba6ffd1SJonathan Corbet# Chen-Yu Tsai <wenst@chromium.org> 31eba6ffd1SJonathan Corbet# Coco Li <lixiaoyan@google.com> 32eba6ffd1SJonathan Corbet# Conchúr Navid <conchur@web.de> 33eba6ffd1SJonathan Corbet# Daniel Santos <daniel.santos@pobox.com> 34eba6ffd1SJonathan Corbet# Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> 35eba6ffd1SJonathan Corbet# Dan Luedtke <mail@danrl.de> 36eba6ffd1SJonathan Corbet# Donald Hunter <donald.hunter@gmail.com> 37eba6ffd1SJonathan Corbet# Gabriel Krisman Bertazi <krisman@collabora.co.uk> 38eba6ffd1SJonathan Corbet# Greg Kroah-Hartman <gregkh@linuxfoundation.org> 39eba6ffd1SJonathan Corbet# Harvey Harrison <harvey.harrison@gmail.com> 40eba6ffd1SJonathan Corbet# Horia Geanta <horia.geanta@freescale.com> 41eba6ffd1SJonathan Corbet# Ilya Dryomov <idryomov@gmail.com> 42eba6ffd1SJonathan Corbet# Jakub Kicinski <kuba@kernel.org> 43eba6ffd1SJonathan Corbet# Jani Nikula <jani.nikula@intel.com> 44eba6ffd1SJonathan Corbet# Jason Baron <jbaron@redhat.com> 45eba6ffd1SJonathan Corbet# Jason Gunthorpe <jgg@nvidia.com> 46eba6ffd1SJonathan Corbet# Jérémy Bobbio <lunar@debian.org> 47eba6ffd1SJonathan Corbet# Johannes Berg <johannes.berg@intel.com> 48eba6ffd1SJonathan Corbet# Johannes Weiner <hannes@cmpxchg.org> 49eba6ffd1SJonathan Corbet# Jonathan Cameron <Jonathan.Cameron@huawei.com> 50eba6ffd1SJonathan Corbet# Jonathan Corbet <corbet@lwn.net> 51eba6ffd1SJonathan Corbet# Jonathan Neuschäfer <j.neuschaefer@gmx.net> 52eba6ffd1SJonathan Corbet# Kamil Rytarowski <n54@gmx.com> 53eba6ffd1SJonathan Corbet# Kees Cook <kees@kernel.org> 54eba6ffd1SJonathan Corbet# Laurent Pinchart <laurent.pinchart@ideasonboard.com> 55eba6ffd1SJonathan Corbet# Levin, Alexander (Sasha Levin) <alexander.levin@verizon.com> 56eba6ffd1SJonathan Corbet# Linus Torvalds <torvalds@linux-foundation.org> 57eba6ffd1SJonathan Corbet# Lucas De Marchi <lucas.demarchi@profusion.mobi> 58eba6ffd1SJonathan Corbet# Mark Rutland <mark.rutland@arm.com> 59eba6ffd1SJonathan Corbet# Markus Heiser <markus.heiser@darmarit.de> 60eba6ffd1SJonathan Corbet# Martin Waitz <tali@admingilde.org> 61eba6ffd1SJonathan Corbet# Masahiro Yamada <masahiroy@kernel.org> 62eba6ffd1SJonathan Corbet# Matthew Wilcox <willy@infradead.org> 63eba6ffd1SJonathan Corbet# Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 64eba6ffd1SJonathan Corbet# Michal Wajdeczko <michal.wajdeczko@intel.com> 65eba6ffd1SJonathan Corbet# Michael Zucchi 66eba6ffd1SJonathan Corbet# Mike Rapoport <rppt@linux.ibm.com> 67eba6ffd1SJonathan Corbet# Niklas Söderlund <niklas.soderlund@corigine.com> 68eba6ffd1SJonathan Corbet# Nishanth Menon <nm@ti.com> 69eba6ffd1SJonathan Corbet# Paolo Bonzini <pbonzini@redhat.com> 70eba6ffd1SJonathan Corbet# Pavan Kumar Linga <pavan.kumar.linga@intel.com> 71eba6ffd1SJonathan Corbet# Pavel Pisa <pisa@cmp.felk.cvut.cz> 72eba6ffd1SJonathan Corbet# Peter Maydell <peter.maydell@linaro.org> 73eba6ffd1SJonathan Corbet# Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> 74eba6ffd1SJonathan Corbet# Randy Dunlap <rdunlap@infradead.org> 75eba6ffd1SJonathan Corbet# Richard Kennedy <richard@rsk.demon.co.uk> 76eba6ffd1SJonathan Corbet# Rich Walker <rw@shadow.org.uk> 77eba6ffd1SJonathan Corbet# Rolf Eike Beer <eike-kernel@sf-tec.de> 78eba6ffd1SJonathan Corbet# Sakari Ailus <sakari.ailus@linux.intel.com> 79eba6ffd1SJonathan Corbet# Silvio Fricke <silvio.fricke@gmail.com> 80eba6ffd1SJonathan Corbet# Simon Huggins 81eba6ffd1SJonathan Corbet# Tim Waugh <twaugh@redhat.com> 82eba6ffd1SJonathan Corbet# Tomasz Warniełło <tomasz.warniello@gmail.com> 83eba6ffd1SJonathan Corbet# Utkarsh Tripathi <utripathi2002@gmail.com> 84eba6ffd1SJonathan Corbet# valdis.kletnieks@vt.edu <valdis.kletnieks@vt.edu> 85eba6ffd1SJonathan Corbet# Vegard Nossum <vegard.nossum@oracle.com> 86eba6ffd1SJonathan Corbet# Will Deacon <will.deacon@arm.com> 87eba6ffd1SJonathan Corbet# Yacine Belkadi <yacine.belkadi.1@gmail.com> 88eba6ffd1SJonathan Corbet# Yujie Liu <yujie.liu@intel.com> 89eba6ffd1SJonathan Corbet 90eba6ffd1SJonathan Corbet""" 91eba6ffd1SJonathan CorbetPrint formatted kernel documentation to stdout. 92eba6ffd1SJonathan Corbet 93eba6ffd1SJonathan CorbetRead C language source or header FILEs, extract embedded 94eba6ffd1SJonathan Corbetdocumentation comments, and print formatted documentation 95eba6ffd1SJonathan Corbetto standard output. 96eba6ffd1SJonathan Corbet 97eba6ffd1SJonathan CorbetThe documentation comments are identified by the ``/**`` 98eba6ffd1SJonathan Corbetopening comment mark. 99eba6ffd1SJonathan Corbet 100eba6ffd1SJonathan CorbetSee Documentation/doc-guide/kernel-doc.rst for the 101eba6ffd1SJonathan Corbetdocumentation comment syntax. 102eba6ffd1SJonathan Corbet""" 103eba6ffd1SJonathan Corbet 104eba6ffd1SJonathan Corbetimport argparse 105eba6ffd1SJonathan Corbetimport logging 106eba6ffd1SJonathan Corbetimport os 107eba6ffd1SJonathan Corbetimport sys 108eba6ffd1SJonathan Corbet 109eba6ffd1SJonathan Corbet# Import Python modules 110eba6ffd1SJonathan Corbet 111eba6ffd1SJonathan CorbetLIB_DIR = "../lib/python" 112eba6ffd1SJonathan CorbetSRC_DIR = os.path.dirname(os.path.realpath(__file__)) 113eba6ffd1SJonathan Corbet 114eba6ffd1SJonathan Corbetsys.path.insert(0, os.path.join(SRC_DIR, LIB_DIR)) 115eba6ffd1SJonathan Corbet 116eba6ffd1SJonathan CorbetWERROR_RETURN_CODE = 3 117eba6ffd1SJonathan Corbet 118eba6ffd1SJonathan CorbetDESC = """ 119eba6ffd1SJonathan CorbetRead C language source or header FILEs, extract embedded documentation comments, 120eba6ffd1SJonathan Corbetand print formatted documentation to standard output. 121eba6ffd1SJonathan Corbet 122eba6ffd1SJonathan CorbetThe documentation comments are identified by the "/**" opening comment mark. 123eba6ffd1SJonathan Corbet 124eba6ffd1SJonathan CorbetSee Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 125eba6ffd1SJonathan Corbet""" 126eba6ffd1SJonathan Corbet 127eba6ffd1SJonathan CorbetEXPORT_FILE_DESC = """ 128eba6ffd1SJonathan CorbetSpecify an additional FILE in which to look for EXPORT_SYMBOL information. 129eba6ffd1SJonathan Corbet 130eba6ffd1SJonathan CorbetMay be used multiple times. 131eba6ffd1SJonathan Corbet""" 132eba6ffd1SJonathan Corbet 133eba6ffd1SJonathan CorbetEXPORT_DESC = """ 134eba6ffd1SJonathan CorbetOnly output documentation for symbols that have been 135eba6ffd1SJonathan Corbetexported using EXPORT_SYMBOL() and related macros in any input 136eba6ffd1SJonathan CorbetFILE or -export-file FILE. 137eba6ffd1SJonathan Corbet""" 138eba6ffd1SJonathan Corbet 139eba6ffd1SJonathan CorbetINTERNAL_DESC = """ 140eba6ffd1SJonathan CorbetOnly output documentation for symbols that have NOT been 141eba6ffd1SJonathan Corbetexported using EXPORT_SYMBOL() and related macros in any input 142eba6ffd1SJonathan CorbetFILE or -export-file FILE. 143eba6ffd1SJonathan Corbet""" 144eba6ffd1SJonathan Corbet 145eba6ffd1SJonathan CorbetFUNCTION_DESC = """ 146eba6ffd1SJonathan CorbetOnly output documentation for the given function or DOC: section 147eba6ffd1SJonathan Corbettitle. All other functions and DOC: sections are ignored. 148eba6ffd1SJonathan Corbet 149eba6ffd1SJonathan CorbetMay be used multiple times. 150eba6ffd1SJonathan Corbet""" 151eba6ffd1SJonathan Corbet 152eba6ffd1SJonathan CorbetNOSYMBOL_DESC = """ 153eba6ffd1SJonathan CorbetExclude the specified symbol from the output documentation. 154eba6ffd1SJonathan Corbet 155eba6ffd1SJonathan CorbetMay be used multiple times. 156eba6ffd1SJonathan Corbet""" 157eba6ffd1SJonathan Corbet 158eba6ffd1SJonathan CorbetFILES_DESC = """ 159eba6ffd1SJonathan CorbetHeader and C source files to be parsed. 160eba6ffd1SJonathan Corbet""" 161eba6ffd1SJonathan Corbet 162eba6ffd1SJonathan CorbetWARN_CONTENTS_BEFORE_SECTIONS_DESC = """ 163eba6ffd1SJonathan CorbetWarn if there are contents before sections (deprecated). 164eba6ffd1SJonathan Corbet 165eba6ffd1SJonathan CorbetThis option is kept just for backward-compatibility, but it does nothing, 166eba6ffd1SJonathan Corbetneither here nor at the original Perl script. 167eba6ffd1SJonathan Corbet""" 168eba6ffd1SJonathan Corbet 16932e9a424SMauro Carvalho ChehabEPILOG = """ 17032e9a424SMauro Carvalho ChehabThe return value is: 17132e9a424SMauro Carvalho Chehab 17232e9a424SMauro Carvalho Chehab- 0: success or Python version is not compatible with 17332e9a424SMauro Carvalho Chehabkernel-doc. If -Werror is not used, it will also 17432e9a424SMauro Carvalho Chehabreturn 0 if there are issues at kernel-doc markups; 17532e9a424SMauro Carvalho Chehab 17632e9a424SMauro Carvalho Chehab- 1: an abnormal condition happened; 17732e9a424SMauro Carvalho Chehab 17832e9a424SMauro Carvalho Chehab- 2: argparse issued an error; 17932e9a424SMauro Carvalho Chehab 18032e9a424SMauro Carvalho Chehab- 3: When -Werror is used, it means that one or more unfiltered parse 18132e9a424SMauro Carvalho Chehab warnings happened. 18232e9a424SMauro Carvalho Chehab""" 183eba6ffd1SJonathan Corbet 184eba6ffd1SJonathan Corbetclass MsgFormatter(logging.Formatter): 185*35c0f975SMauro Carvalho Chehab """ 186*35c0f975SMauro Carvalho Chehab Helper class to capitalize errors and warnings, the same way 187*35c0f975SMauro Carvalho Chehab the venerable (now retired) kernel-doc.pl used to do. 188*35c0f975SMauro Carvalho Chehab """ 189eba6ffd1SJonathan Corbet 190eba6ffd1SJonathan Corbet def format(self, record): 191eba6ffd1SJonathan Corbet record.levelname = record.levelname.capitalize() 192eba6ffd1SJonathan Corbet return logging.Formatter.format(self, record) 193eba6ffd1SJonathan Corbet 194eba6ffd1SJonathan Corbetdef main(): 195eba6ffd1SJonathan Corbet """ 196eba6ffd1SJonathan Corbet Main program. 197eba6ffd1SJonathan Corbet 198eba6ffd1SJonathan Corbet """ 199eba6ffd1SJonathan Corbet 200eba6ffd1SJonathan Corbet parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, 20132e9a424SMauro Carvalho Chehab description=DESC, epilog=EPILOG) 202eba6ffd1SJonathan Corbet 203eba6ffd1SJonathan Corbet # 204eba6ffd1SJonathan Corbet # Normal arguments 205eba6ffd1SJonathan Corbet # 206eba6ffd1SJonathan Corbet parser.add_argument("-v", "-verbose", "--verbose", action="store_true", 207eba6ffd1SJonathan Corbet help="Verbose output, more warnings and other information.") 208eba6ffd1SJonathan Corbet 209eba6ffd1SJonathan Corbet parser.add_argument("-d", "-debug", "--debug", action="store_true", 210eba6ffd1SJonathan Corbet help="Enable debug messages") 211eba6ffd1SJonathan Corbet 212eba6ffd1SJonathan Corbet parser.add_argument("-M", "-modulename", "--modulename", 213eba6ffd1SJonathan Corbet default="Kernel API", 214eba6ffd1SJonathan Corbet help="Allow setting a module name at the output.") 215eba6ffd1SJonathan Corbet 216eba6ffd1SJonathan Corbet parser.add_argument("-l", "-enable-lineno", "--enable_lineno", 217eba6ffd1SJonathan Corbet action="store_true", 218eba6ffd1SJonathan Corbet help="Enable line number output (only in ReST mode)") 219eba6ffd1SJonathan Corbet 220eba6ffd1SJonathan Corbet # 221eba6ffd1SJonathan Corbet # Arguments to control the warning behavior 222eba6ffd1SJonathan Corbet # 223eba6ffd1SJonathan Corbet parser.add_argument("-Wreturn", "--wreturn", action="store_true", 224eba6ffd1SJonathan Corbet help="Warns about the lack of a return markup on functions.") 225eba6ffd1SJonathan Corbet 226eba6ffd1SJonathan Corbet parser.add_argument("-Wshort-desc", "-Wshort-description", "--wshort-desc", 227eba6ffd1SJonathan Corbet action="store_true", 228eba6ffd1SJonathan Corbet help="Warns if initial short description is missing") 229eba6ffd1SJonathan Corbet 230eba6ffd1SJonathan Corbet parser.add_argument("-Wcontents-before-sections", 231eba6ffd1SJonathan Corbet "--wcontents-before-sections", action="store_true", 232eba6ffd1SJonathan Corbet help=WARN_CONTENTS_BEFORE_SECTIONS_DESC) 233eba6ffd1SJonathan Corbet 234eba6ffd1SJonathan Corbet parser.add_argument("-Wall", "--wall", action="store_true", 235eba6ffd1SJonathan Corbet help="Enable all types of warnings") 236eba6ffd1SJonathan Corbet 237eba6ffd1SJonathan Corbet parser.add_argument("-Werror", "--werror", action="store_true", 238eba6ffd1SJonathan Corbet help="Treat warnings as errors.") 239eba6ffd1SJonathan Corbet 240eba6ffd1SJonathan Corbet parser.add_argument("-export-file", "--export-file", action='append', 241eba6ffd1SJonathan Corbet help=EXPORT_FILE_DESC) 242eba6ffd1SJonathan Corbet 243eba6ffd1SJonathan Corbet # 244eba6ffd1SJonathan Corbet # Output format mutually-exclusive group 245eba6ffd1SJonathan Corbet # 246eba6ffd1SJonathan Corbet out_group = parser.add_argument_group("Output format selection (mutually exclusive)") 247eba6ffd1SJonathan Corbet 248eba6ffd1SJonathan Corbet out_fmt = out_group.add_mutually_exclusive_group() 249eba6ffd1SJonathan Corbet 250eba6ffd1SJonathan Corbet out_fmt.add_argument("-m", "-man", "--man", action="store_true", 251eba6ffd1SJonathan Corbet help="Output troff manual page format.") 252eba6ffd1SJonathan Corbet out_fmt.add_argument("-r", "-rst", "--rst", action="store_true", 253eba6ffd1SJonathan Corbet help="Output reStructuredText format (default).") 254eba6ffd1SJonathan Corbet out_fmt.add_argument("-N", "-none", "--none", action="store_true", 255eba6ffd1SJonathan Corbet help="Do not output documentation, only warnings.") 256eba6ffd1SJonathan Corbet 257eba6ffd1SJonathan Corbet # 258eba6ffd1SJonathan Corbet # Output selection mutually-exclusive group 259eba6ffd1SJonathan Corbet # 260eba6ffd1SJonathan Corbet sel_group = parser.add_argument_group("Output selection (mutually exclusive)") 261eba6ffd1SJonathan Corbet sel_mut = sel_group.add_mutually_exclusive_group() 262eba6ffd1SJonathan Corbet 263eba6ffd1SJonathan Corbet sel_mut.add_argument("-e", "-export", "--export", action='store_true', 264eba6ffd1SJonathan Corbet help=EXPORT_DESC) 265eba6ffd1SJonathan Corbet 266eba6ffd1SJonathan Corbet sel_mut.add_argument("-i", "-internal", "--internal", action='store_true', 267eba6ffd1SJonathan Corbet help=INTERNAL_DESC) 268eba6ffd1SJonathan Corbet 269eba6ffd1SJonathan Corbet sel_mut.add_argument("-s", "-function", "--symbol", action='append', 270eba6ffd1SJonathan Corbet help=FUNCTION_DESC) 271eba6ffd1SJonathan Corbet 272eba6ffd1SJonathan Corbet # 273eba6ffd1SJonathan Corbet # Those are valid for all 3 types of filter 274eba6ffd1SJonathan Corbet # 275eba6ffd1SJonathan Corbet parser.add_argument("-n", "-nosymbol", "--nosymbol", action='append', 276eba6ffd1SJonathan Corbet help=NOSYMBOL_DESC) 277eba6ffd1SJonathan Corbet 278eba6ffd1SJonathan Corbet parser.add_argument("-D", "-no-doc-sections", "--no-doc-sections", 279eba6ffd1SJonathan Corbet action='store_true', help="Don't output DOC sections") 280eba6ffd1SJonathan Corbet 281eba6ffd1SJonathan Corbet parser.add_argument("files", metavar="FILE", 282eba6ffd1SJonathan Corbet nargs="+", help=FILES_DESC) 283eba6ffd1SJonathan Corbet 284eba6ffd1SJonathan Corbet args = parser.parse_args() 285eba6ffd1SJonathan Corbet 286eba6ffd1SJonathan Corbet if args.wall: 287eba6ffd1SJonathan Corbet args.wreturn = True 288eba6ffd1SJonathan Corbet args.wshort_desc = True 289eba6ffd1SJonathan Corbet args.wcontents_before_sections = True 290eba6ffd1SJonathan Corbet 291eba6ffd1SJonathan Corbet logger = logging.getLogger() 292eba6ffd1SJonathan Corbet 293eba6ffd1SJonathan Corbet if not args.debug: 294eba6ffd1SJonathan Corbet logger.setLevel(logging.INFO) 295eba6ffd1SJonathan Corbet else: 296eba6ffd1SJonathan Corbet logger.setLevel(logging.DEBUG) 297eba6ffd1SJonathan Corbet 298eba6ffd1SJonathan Corbet formatter = MsgFormatter('%(levelname)s: %(message)s') 299eba6ffd1SJonathan Corbet 300eba6ffd1SJonathan Corbet handler = logging.StreamHandler() 301eba6ffd1SJonathan Corbet handler.setFormatter(formatter) 302eba6ffd1SJonathan Corbet 303eba6ffd1SJonathan Corbet logger.addHandler(handler) 304eba6ffd1SJonathan Corbet 305eba6ffd1SJonathan Corbet python_ver = sys.version_info[:2] 306eba6ffd1SJonathan Corbet if python_ver < (3,6): 307eba6ffd1SJonathan Corbet # 308eba6ffd1SJonathan Corbet # Depending on the Kernel configuration, kernel-doc --none is called at 309eba6ffd1SJonathan Corbet # build time. As we don't want to break compilation due to the 310eba6ffd1SJonathan Corbet # usage of an old Python version, return 0 here. 311eba6ffd1SJonathan Corbet # 312eba6ffd1SJonathan Corbet if args.none: 313eba6ffd1SJonathan Corbet logger.error("Python 3.6 or later is required by kernel-doc. Skipping checks") 314eba6ffd1SJonathan Corbet sys.exit(0) 315eba6ffd1SJonathan Corbet 316eba6ffd1SJonathan Corbet sys.exit("Python 3.6 or later is required by kernel-doc. Aborting.") 317eba6ffd1SJonathan Corbet 318eba6ffd1SJonathan Corbet if python_ver < (3,7): 319eba6ffd1SJonathan Corbet logger.warning("Python 3.7 or later is required for correct results") 320eba6ffd1SJonathan Corbet 321eba6ffd1SJonathan Corbet # 322eba6ffd1SJonathan Corbet # Import kernel-doc libraries only after checking the Python version 323eba6ffd1SJonathan Corbet # 324eba6ffd1SJonathan Corbet from kdoc.kdoc_files import KernelFiles # pylint: disable=C0415 325eba6ffd1SJonathan Corbet from kdoc.kdoc_output import RestFormat, ManFormat # pylint: disable=C0415 326eba6ffd1SJonathan Corbet 327eba6ffd1SJonathan Corbet if args.man: 328eba6ffd1SJonathan Corbet out_style = ManFormat(modulename=args.modulename) 329eba6ffd1SJonathan Corbet elif args.none: 330eba6ffd1SJonathan Corbet out_style = None 331eba6ffd1SJonathan Corbet else: 332eba6ffd1SJonathan Corbet out_style = RestFormat() 333eba6ffd1SJonathan Corbet 334eba6ffd1SJonathan Corbet kfiles = KernelFiles(verbose=args.verbose, 335eba6ffd1SJonathan Corbet out_style=out_style, werror=args.werror, 336eba6ffd1SJonathan Corbet wreturn=args.wreturn, wshort_desc=args.wshort_desc, 337eba6ffd1SJonathan Corbet wcontents_before_sections=args.wcontents_before_sections) 338eba6ffd1SJonathan Corbet 339eba6ffd1SJonathan Corbet kfiles.parse(args.files, export_file=args.export_file) 340eba6ffd1SJonathan Corbet 341eba6ffd1SJonathan Corbet for t in kfiles.msg(enable_lineno=args.enable_lineno, export=args.export, 342eba6ffd1SJonathan Corbet internal=args.internal, symbol=args.symbol, 343eba6ffd1SJonathan Corbet nosymbol=args.nosymbol, export_file=args.export_file, 344eba6ffd1SJonathan Corbet no_doc_sections=args.no_doc_sections): 345eba6ffd1SJonathan Corbet msg = t[1] 346eba6ffd1SJonathan Corbet if msg: 347eba6ffd1SJonathan Corbet print(msg) 348eba6ffd1SJonathan Corbet 349eba6ffd1SJonathan Corbet error_count = kfiles.errors 350eba6ffd1SJonathan Corbet if not error_count: 351eba6ffd1SJonathan Corbet sys.exit(0) 352eba6ffd1SJonathan Corbet 353eba6ffd1SJonathan Corbet if args.werror: 354eba6ffd1SJonathan Corbet print("%s warnings as errors" % error_count) # pylint: disable=C0209 355eba6ffd1SJonathan Corbet sys.exit(WERROR_RETURN_CODE) 356eba6ffd1SJonathan Corbet 357eba6ffd1SJonathan Corbet if args.verbose: 358eba6ffd1SJonathan Corbet print("%s errors" % error_count) # pylint: disable=C0209 359eba6ffd1SJonathan Corbet 360eba6ffd1SJonathan Corbet sys.exit(0) 361eba6ffd1SJonathan Corbet 362eba6ffd1SJonathan Corbet# 363eba6ffd1SJonathan Corbet# Call main method 364eba6ffd1SJonathan Corbet# 365eba6ffd1SJonathan Corbetif __name__ == "__main__": 366eba6ffd1SJonathan Corbet main() 367