This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit dfa5b85f6f874998150b28fd38897ebce51a5e9f
Author: wangmingrong1 <[email protected]>
AuthorDate: Mon Nov 2 16:08:34 2026 +0800

    tools/gcov.py: fix genhtml compat with lcov 1.x
    
    The 'category' error type for --ignore-errors is only
    supported by lcov >= 2. Add version detection to select
    the correct --ignore-errors value dynamically.
    
    Signed-off-by: wangmingrong1 <[email protected]>
---
 tools/gcov.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/gcov.py b/tools/gcov.py
index 6ff25a1cb24..4c871ecde6c 100755
--- a/tools/gcov.py
+++ b/tools/gcov.py
@@ -198,14 +198,33 @@ def run_lcov(data_dir, gcov_tool):
     return output
 
 
+def get_lcov_major_version():
+    """Get the major version number of the installed lcov/genhtml."""
+    try:
+        result = subprocess.run(
+            ["lcov", "--version"], capture_output=True, text=True, timeout=5
+        )
+        match = re.search(r"LCOV version (\d+)", result.stdout)
+        if match:
+            return int(match.group(1))
+    except (subprocess.TimeoutExpired, OSError, FileNotFoundError):
+        pass
+    return 1
+
+
 def run_genhtml(info, report):
+    # 'category' is only supported by lcov >= 2
+    ignore_errors = "source"
+    if get_lcov_major_version() >= 2:
+        ignore_errors = "source,category"
+
     cmd = [
         "genhtml",
         "--branch-coverage",
         "-o",
         report,
         "--ignore-errors",
-        "source,category",
+        ignore_errors,
         info,
     ]
     print(cmd)

Reply via email to