patman: Fix checkpatch message parsing for consecutive messages
Checkpatch.pl doesn't always output blank lines between messages. The current parser splits on '\n\n' which fails to separate consecutive messages, causing "Internal error: some problems lost" warnings. Fix by splitting on message-starting patterns (ERROR:, WARNING:, CHECK:, etc.) instead of blank lines. Add a test that verifies consecutive messages are parsed correctly. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
@@ -157,9 +157,24 @@ def check_patch_parse(checkpatch_output, verbose=False):
|
||||
r' checks, (\d+)')
|
||||
re_ok = re.compile(r'.*has no obvious style problems')
|
||||
re_bad = re.compile(r'.*has style problems, please review')
|
||||
# Patterns that start a new message block
|
||||
re_message_start = re.compile(
|
||||
r'^(ERROR|WARNING|CHECK):|^total:|^NOTE:|.* has (no obvious )?style')
|
||||
|
||||
# A blank line indicates the end of a message
|
||||
for message in result.stdout.split('\n\n'):
|
||||
# Split output into individual messages by looking for message-starting
|
||||
# patterns at the start of lines, since messages may not be separated by
|
||||
# blank lines
|
||||
messages = []
|
||||
current = []
|
||||
for line in result.stdout.splitlines():
|
||||
if re_message_start.match(line) and current:
|
||||
messages.append('\n'.join(current))
|
||||
current = []
|
||||
current.append(line)
|
||||
if current:
|
||||
messages.append('\n'.join(current))
|
||||
|
||||
for message in messages:
|
||||
if verbose:
|
||||
print(message)
|
||||
|
||||
|
||||
@@ -532,5 +532,37 @@ index 0000000..2234c87
|
||||
pm.add_line('arch/sandbox/dts/sandbox.dtsi', '\tu-boot,dm-pre-proper;')
|
||||
self.check_single_message(pm, 'PRE_SCHEMA', 'error')
|
||||
|
||||
def test_parse_consecutive_messages(self):
|
||||
"""Test parsing of consecutive checkpatch messages without blank lines
|
||||
|
||||
Checkpatch.pl doesn't always output blank lines between messages.
|
||||
Verify that the parser correctly separates consecutive messages.
|
||||
"""
|
||||
# Simulated checkpatch output with two warnings not separated by blank
|
||||
# line - this is how checkpatch actually outputs consecutive messages
|
||||
output = '''WARNING: please write a help paragraph
|
||||
#10: FILE: scripts/Makefile:1:
|
||||
+config FOO
|
||||
WARNING: please define a type for config
|
||||
#15: FILE: scripts/Makefile:5:
|
||||
+config BAR
|
||||
|
||||
total: 0 errors, 2 warnings, 0 checks, 20 lines checked
|
||||
|
||||
test.patch has style problems, please review.'''
|
||||
|
||||
result = checkpatch.check_patch_parse(output)
|
||||
self.assertEqual(result.ok, False)
|
||||
self.assertEqual(result.errors, 0)
|
||||
self.assertEqual(result.warnings, 2)
|
||||
self.assertEqual(result.checks, 0)
|
||||
# Both warnings should be parsed as separate problems
|
||||
# pylint: disable=E1136
|
||||
self.assertEqual(len(result.problems), 2)
|
||||
self.assertEqual(result.problems[0]['msg'],
|
||||
'please write a help paragraph')
|
||||
self.assertEqual(result.problems[1]['msg'],
|
||||
'please define a type for config')
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user