Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 34e5003

Browse files
michaeljonesfabiobaltieri
authored andcommittedJul 3, 2023
doc: Log unused log filter patterns
This allows us to identify any patterns that we can remove or that we didn't realise are no longer in use. This might happen if issues within doxygen or docleaf are resolved. This allows us to remove the pattern: .*Duplicate C declaration.*\n.*'\.\. c:.*:: uint16_t id'.* which does not match anything in the current set up. We also split the filter patterns in known-warnings out into different sections depending on their cause. Also extend the pattern parser to ignore empty lines so that we can have some formatting in the known-warnings file. Signed-off-by: Michael Jones <m.pricejones@gmail.com>
1 parent 3127d7b commit 34e5003

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed
 

‎doc/_extensions/zephyr/warnings_filter.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import logging
2626
import re
27-
from typing import Dict, Any, List
27+
from typing import Dict, Any, List, Optional
2828

2929
from sphinx.application import Sphinx
3030
from sphinx.util.logging import NAMESPACE
@@ -41,6 +41,7 @@ class WarningsFilter(logging.Filter):
4141
silent: If true, warning is hidden, otherwise it is shown as INFO.
4242
name: Filter name.
4343
"""
44+
4445
def __init__(self, expressions: List[str], silent: bool, name: str = "") -> None:
4546
super().__init__(name)
4647

@@ -53,7 +54,7 @@ def filter(self, record: logging.LogRecord) -> bool:
5354

5455
for expression in self._expressions:
5556
# The message isn't always a string so we convert it before regexing as we can only regex strings
56-
if re.match(expression, str(record.msg)):
57+
if expression.match(str(record.msg)):
5758
if self._silent:
5859
return False
5960
else:
@@ -64,6 +65,21 @@ def filter(self, record: logging.LogRecord) -> bool:
6465
return True
6566

6667

68+
class Expression:
69+
"""
70+
Encapsulate a log filter pattern and track if it ever matches a log line.
71+
"""
72+
73+
def __init__(self, pattern):
74+
self.pattern = pattern
75+
self.matched = False
76+
77+
def match(self, str):
78+
matches = bool(re.match(self.pattern, str))
79+
self.matched = matches or self.matched
80+
return matches
81+
82+
6783
def configure(app: Sphinx) -> None:
6884
"""Entry point.
6985
@@ -75,8 +91,10 @@ def configure(app: Sphinx) -> None:
7591
with open(app.config.warnings_filter_config) as f:
7692
expressions = list()
7793
for line in f.readlines():
78-
if not line.startswith("#"):
79-
expressions.append(line.rstrip())
94+
if line.strip() and not line.startswith("#"):
95+
expressions.append(Expression(line.rstrip()))
96+
97+
app.env.warnings_filter_expressions = expressions
8098

8199
# install warnings filter to all the Sphinx logger handlers
82100
filter = WarningsFilter(expressions, app.config.warnings_filter_silent)
@@ -85,11 +103,28 @@ def configure(app: Sphinx) -> None:
85103
handler.filters.insert(0, filter)
86104

87105

106+
def finished(app: Sphinx, exception: Optional[Exception]):
107+
"""
108+
Prints out any patterns that have not matched a log line to allow us to clean up any that are not used.
109+
"""
110+
if exception:
111+
# Early exit if there has been an exception as matching data is only
112+
# valid for complete builds
113+
return
114+
115+
expressions = app.env.warnings_filter_expressions
116+
117+
for expression in expressions:
118+
if not expression.matched:
119+
logging.warning(f"Unused expression: {expression.pattern}")
120+
121+
88122
def setup(app: Sphinx) -> Dict[str, Any]:
89123
app.add_config_value("warnings_filter_config", "", "")
90124
app.add_config_value("warnings_filter_silent", True, "")
91125

92126
app.connect("builder-inited", configure)
127+
app.connect("build-finished", finished)
93128

94129
return {
95130
"version": __version__,

‎doc/known-warnings.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
# Each line should contain the regular expression of a known Sphinx warning
22
# that should be filtered out
3-
.*Duplicate C declaration.*\n.*'\.\. c:.*:: dma_config'.*
3+
4+
# Function and (enum or struct) name
45
.*Duplicate C declaration.*\n.*'\.\. c:.*:: flash_img_check'.*
5-
.*Duplicate C declaration.*\n.*'\.\. c:.*:: zsock_fd_set'.*
6-
.*Duplicate C declaration.*\n.*'\.\. c:.*:: net_if_mcast_monitor'.*
76
.*Duplicate C declaration.*\n.*'\.\. c:.*:: fs_statvfs'.*
87
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*dmic_trigger.*'.*
9-
.*Duplicate C declaration.*\n.*'\.\. c:.*:: uint16_t id'.*
8+
.*Duplicate C declaration.*\n.*'\.\. c:.*:: dma_config'.*
9+
.*Duplicate C declaration.*\n.*'\.\. c:.*:: net_if_mcast_monitor'.*
10+
.*Duplicate C declaration.*\n.*'\.\. c:struct:: bt_ots_init'.*
11+
12+
# Struct and typedef name
13+
.*Duplicate C declaration.*\n.*'\.\. c:.*:: zsock_fd_set'.*
14+
15+
# Function and extern function
1016
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*net_if_ipv4_addr_mask_cmp.*'.*
1117
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*net_if_ipv4_is_addr_bcast.*'.*
1218
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*net_if_ipv4_addr_lookup.*'.*
1319
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*net_if_ipv6_addr_lookup.*'.*
1420
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*net_if_ipv6_maddr_lookup.*'.*
21+
22+
# Common field names
1523
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*struct in_addr.*'.*
1624
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*struct in6_addr.*'.*
1725
.*Duplicate C declaration.*\n.*'\.\. c:.*:: .*struct net_if.*'.*
18-
.*Duplicate C declaration.*\n.*'\.\. c:struct:: bt_ots_init'.*
26+
27+
# Clash with field of nested anonymous struct
1928
.*Duplicate C declaration.*\n.*'\.\. c:member:: enum *bt_mesh_dfd_upload_phase bt_mesh_dfd_srv.phase'.*
2029
.*Duplicate C declaration.*\n.*'\.\. c:member:: struct *bt_mesh_blob_xfer bt_mesh_dfu_cli.blob'.*
2130
.*Duplicate C declaration.*\n.*'\.\. c:member:: struct *net_if *\* net_if_mcast_monitor.iface'.

0 commit comments

Comments
 (0)
Please sign in to comment.