mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Linux Doc Mailing List <linux-doc@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Sean Anderson <sean.anderson@linux.dev>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 28/33] scripts/kernel-doc.py: Properly handle Werror and exit codes
Date: Tue,  8 Apr 2025 18:09:31 +0800	[thread overview]
Message-ID: <de33b0cebd9fdf82d8b221bcfe41db7269286222.1744106242.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1744106241.git.mchehab+huawei@kernel.org>

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>
---
 scripts/kernel-doc.py           | 18 ++++++++++++++++--
 scripts/lib/kdoc/kdoc_files.py  | 12 ++++++++++--
 scripts/lib/kdoc/kdoc_output.py |  8 +++-----
 scripts/lib/kdoc/kdoc_parser.py | 15 ++++++---------
 4 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/scripts/kernel-doc.py b/scripts/kernel-doc.py
index 6a6bc81efd31..2f2fad813024 100755
--- a/scripts/kernel-doc.py
+++ b/scripts/kernel-doc.py
@@ -78,8 +78,6 @@
 #    Yacine Belkadi <yacine.belkadi.1@gmail.com>
 #    Yujie Liu <yujie.liu@intel.com>
 
-# TODO: implement warning filtering
-
 """
 kernel_doc
 ==========
@@ -295,6 +293,22 @@ def main():
         if msg:
             print(msg)
 
+    error_count = kfiles.errors
+    if not error_count:
+        sys.exit(0)
+
+    if args.werror:
+        print(f"{error_count} warnings as errors")
+        sys.exit(error_count)
+
+    if args.verbose:
+        print(f"{error_count} errors")
+
+    if args.none:
+        sys.exit(0)
+
+    sys.exit(error_count)
+
 
 # Call main method
 if __name__ == "__main__":
diff --git a/scripts/lib/kdoc/kdoc_files.py b/scripts/lib/kdoc/kdoc_files.py
index e52a6d05237e..182d9ed58a72 100644
--- a/scripts/lib/kdoc/kdoc_files.py
+++ b/scripts/lib/kdoc/kdoc_files.py
@@ -12,7 +12,6 @@ import argparse
 import logging
 import os
 import re
-import sys
 
 from kdoc_parser import KernelDoc
 from kdoc_output import OutputFormat
@@ -109,7 +108,7 @@ class KernelFiles():
                     KernelDoc.process_export(self.config.function_table, line)
 
         except IOError:
-            print(f"Error: Cannot open fname {fname}", fname=sys.stderr)
+            self.config.log.error("Error: Cannot open fname %s", fname)
             self.config.errors += 1
 
     def file_not_found_cb(self, fname):
@@ -262,3 +261,12 @@ class KernelFiles():
                                             fname, ln, dtype)
             if msg:
                 yield fname, msg
+
+    @property
+    def errors(self):
+        """
+        Return a count of the number of warnings found, including
+        the ones displayed while interacting over self.msg.
+        """
+
+        return self.config.errors
diff --git a/scripts/lib/kdoc/kdoc_output.py b/scripts/lib/kdoc/kdoc_output.py
index eb013075da84..e9b4d0093084 100755
--- a/scripts/lib/kdoc/kdoc_output.py
+++ b/scripts/lib/kdoc/kdoc_output.py
@@ -128,11 +128,9 @@ class OutputFormat:
 
         warnings = args.get('warnings', [])
 
-        for warning, log_msg in warnings:
-            if warning:
-                self.config.log.warning(log_msg)
-            else:
-                self.config.log.info(log_msg)
+        for log_msg in warnings:
+            self.config.log.warning(log_msg)
+            self.config.errors += 1
 
     def check_doc(self, name, args):
         """Check if DOC should be output"""
diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index 77e8bfeccc8e..43e6ffbdcc2c 100755
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -137,17 +137,18 @@ class KernelDoc:
 
         log_msg = f"{self.fname}:{ln} {msg}"
 
+        if not warning:
+            self.config.log.info(log_msg)
+            return
+
         if self.entry:
             # Delegate warning output to output logic, as this way it
             # will report warnings/info only for symbols that are output
 
-            self.entry.warnings.append((warning, log_msg))
+            self.entry.warnings.append(log_msg)
             return
 
-        if warning:
-            self.config.log.warning(log_msg)
-        else:
-            self.config.log.info(log_msg)
+        self.config.log.warning(log_msg)
 
     def dump_section(self, start_new=True):
         """
@@ -556,7 +557,6 @@ class KernelDoc:
 
         if not members:
             self.emit_warning(ln, f"{proto} error: Cannot parse struct or union!")
-            self.config.errors += 1
             return
 
         if self.entry.identifier != declaration_name:
@@ -831,7 +831,6 @@ class KernelDoc:
 
         if not members:
             self.emit_warning(ln, f"{proto}: error: Cannot parse enum!")
-            self.config.errors += 1
             return
 
         if self.entry.identifier != declaration_name:
@@ -1132,7 +1131,6 @@ class KernelDoc:
             return
 
         self.emit_warning(ln, "error: Cannot parse typedef!")
-        self.config.errors += 1
 
     @staticmethod
     def process_export(function_table, line):
@@ -1677,4 +1675,3 @@ class KernelDoc:
                         self.process_docblock(ln, line)
         except OSError:
             self.config.log.error(f"Error: Cannot open file {self.fname}")
-            self.config.errors += 1
-- 
2.49.0


  parent reply	other threads:[~2025-04-08 10:09 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 10:09 [PATCH v3 00/33] Implement kernel-doc in Python Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 01/33] scripts/kernel-doc: rename it to scripts/kernel-doc.pl Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 02/33] scripts/kernel-doc: add a symlink to the Perl version of kernel-doc Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 03/33] scripts/kernel-doc.py: add a Python parser Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 04/33] scripts/kernel-doc.py: output warnings the same way as kerneldoc Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 05/33] scripts/kernel-doc.py: better handle empty sections Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 06/33] scripts/kernel-doc.py: properly handle struct_group macros Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 07/33] scripts/kernel-doc.py: move regex methods to a separate file Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 08/33] scripts/kernel-doc.py: move KernelDoc class " Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 09/33] scripts/kernel-doc.py: move KernelFiles " Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 10/33] scripts/kernel-doc.py: move output classes " Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 11/33] scripts/kernel-doc.py: convert message output to an interactor Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 12/33] scripts/kernel-doc.py: move file lists to the parser function Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 13/33] scripts/kernel-doc.py: implement support for -no-doc-sections Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 14/33] scripts/kernel-doc.py: fix line number output Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 15/33] scripts/kernel-doc.py: fix handling of doc output check Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 16/33] scripts/kernel-doc.py: properly handle out_section for ReST Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 17/33] scripts/kernel-doc.py: postpone warnings to the output plugin Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 18/33] docs: add a .pylintrc file with sys path for docs scripts Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 19/33] docs: sphinx: kerneldoc: verbose kernel-doc command if V=1 Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 20/33] docs: sphinx: kerneldoc: ignore "\" characters from options Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 21/33] docs: sphinx: kerneldoc: use kernel-doc.py script Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 22/33] scripts/kernel-doc.py: Set an output format for --none Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 23/33] scripts/kernel-doc.py: adjust some coding style issues Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 24/33] scripts/lib/kdoc/kdoc_parser.py: fix Python compat with < v3.13 Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 25/33] scripts/kernel-doc.py: move modulename to man class Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 26/33] scripts/kernel-doc.py: properly handle KBUILD_BUILD_TIMESTAMP Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 27/33] scripts/lib/kdoc/kdoc_parser.py: remove a python 3.9 dependency Mauro Carvalho Chehab
2025-04-08 10:09 ` Mauro Carvalho Chehab [this message]
2025-04-08 10:09 ` [PATCH v3 29/33] scripts/kernel-doc: switch to use kernel-doc.py Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 30/33] scripts/lib/kdoc/kdoc_files.py: allow filtering output per fname Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 31/33] scripts/kernel_doc.py: better handle exported symbols Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 32/33] scripts/kernel-doc.py: Rename the kernel doc Re class to KernRe Mauro Carvalho Chehab
2025-04-08 10:09 ` [PATCH v3 33/33] scripts: kernel-doc: fix parsing function-like typedefs (again) Mauro Carvalho Chehab
2025-04-09  5:29 ` [PATCH v3 00/33] Implement kernel-doc in Python Mauro Carvalho Chehab
2025-04-09 10:16 ` Jani Nikula
2025-04-09 11:44   ` Mauro Carvalho Chehab
2025-04-09 18:30 ` Jonathan Corbet
2025-04-14  9:41   ` Andy Shevchenko
2025-04-14 15:17     ` Jonathan Corbet
2025-04-14 15:54       ` Jonathan Corbet
2025-04-15  7:01       ` Andy Shevchenko
2025-04-15  7:03         ` Andy Shevchenko
2025-04-15  7:49           ` Jani Nikula
2025-04-15  8:17             ` Andy Shevchenko
2025-04-15  8:19               ` Andy Shevchenko
2025-04-15  8:40                 ` Mauro Carvalho Chehab
2025-04-15  8:51                   ` Mauro Carvalho Chehab
2025-04-15  9:53                     ` Andy Shevchenko
2025-04-15  9:51                   ` Andy Shevchenko
2025-04-15  9:54                     ` Andy Shevchenko
2025-04-15 10:06                       ` Mauro Carvalho Chehab
2025-04-15 11:13                         ` Andy Shevchenko
2025-04-15 13:34                         ` Jonathan Corbet
2025-04-16  6:44                           ` Mauro Carvalho Chehab
2025-04-15  8:30           ` Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=de33b0cebd9fdf82d8b221bcfe41db7269286222.1744106242.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sean.anderson@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®