[PATCH 0/6] patman: Fixes to allow patman to work with Zephyr OS

At present patman doesn't correctly parse the output of checkpatch if the --emacs and --show-types options are given in the .checkpatch.conf file.
This series corrects these problems, allowing patman to be used to check patches intended for Zephyr OS.
Simon Glass (6): patman: Fix 'warning' typo patman: Support emacs mode with checkpatch patman: Don't try to process checkpatch lines twice patman: Handle checkpatch output with notes and code patman: Support warnings in the patch subject patman: Complain if a checkpatch line is not understood
tools/patman/checkpatch.py | 43 ++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-)

If no warnings are detected due to checkpatch having unexpected options, patman currently shows an error:
TypeError: unsupported operand type(s) for +=: 'int' and 'property'
Fix this by initing the variable correctly.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index 795b519314..a2611a8a82 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -59,7 +59,7 @@ def CheckPatch(fname, verbose=False): 'stdout'] result = collections.namedtuple('CheckPatchResult', fields) result.ok = False - result.errors, result.warning, result.checks = 0, 0, 0 + result.errors, result.warnings, result.checks = 0, 0, 0 result.lines = 0 result.problems = [] chk = FindCheckPatch()

If no warnings are detected due to checkpatch having unexpected options, patman currently shows an error:
TypeError: unsupported operand type(s) for +=: 'int' and 'property'
Fix this by initing the variable correctly.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm, thanks!

If checkpatch is run in 'emacs' mode it shows the filename at the start of each line. Add support for this so that the warnings and errors are correctly detected.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index a2611a8a82..16d534b6ae 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -72,13 +72,17 @@ def CheckPatch(fname, verbose=False): # total: 0 errors, 0 warnings, 159 lines checked # or: # total: 0 errors, 2 warnings, 7 checks, 473 lines checked - re_stats = re.compile('total: (\d+) errors, (\d+) warnings, (\d+)') - re_stats_full = re.compile('total: (\d+) errors, (\d+) warnings, (\d+)' + emacs_prefix = '(?:[0-9]{4}.*.patch:[0-9]+: )?' + emacs_stats = '(?:[0-9]{4}.*.patch )?' + re_stats = re.compile(emacs_stats + + 'total: (\d+) errors, (\d+) warnings, (\d+)') + re_stats_full = re.compile(emacs_stats + + 'total: (\d+) errors, (\d+) warnings, (\d+)' ' checks, (\d+)') re_ok = re.compile('.*has no obvious style problems') re_bad = re.compile('.*has style problems, please review') re_error = re.compile('ERROR: (.*)') - re_warning = re.compile('WARNING: (.*)') + re_warning = re.compile(emacs_prefix + 'WARNING:(?:[A-Z_]+:)? (.*)') re_check = re.compile('CHECK: (.*)') re_file = re.compile('#\d+: FILE: ([^:]*):(\d+):')

If checkpatch is run in 'emacs' mode it shows the filename at the start of each line. Add support for this so that the warnings and errors are correctly detected.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Applied to u-boot-dm, thanks!

Once we have determined what the line refers to there is no point in processing it further. Update the logic to continue to the next line in these cases.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index 16d534b6ae..2cfa9778c6 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -91,9 +91,11 @@ def CheckPatch(fname, verbose=False): print(line)
# A blank line indicates the end of a message - if not line and item: - result.problems.append(item) - item = {} + if not line: + if item: + result.problems.append(item) + item = {} + continue match = re_stats_full.match(line) if not match: match = re_stats.match(line) @@ -105,10 +107,13 @@ def CheckPatch(fname, verbose=False): result.lines = int(match.group(4)) else: result.lines = int(match.group(3)) + continue elif re_ok.match(line): result.ok = True + continue elif re_bad.match(line): result.ok = False + continue err_match = re_error.match(line) warn_match = re_warning.match(line) file_match = re_file.match(line)

Once we have determined what the line refers to there is no point in processing it further. Update the logic to continue to the next line in these cases.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Applied to u-boot-dm, thanks!

If checkpatch is configured to output code we should ignore it. Similarly, notes should be ignored.
Update the logic to handle these situations.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index 2cfa9778c6..5426bb9e9e 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -85,7 +85,8 @@ def CheckPatch(fname, verbose=False): re_warning = re.compile(emacs_prefix + 'WARNING:(?:[A-Z_]+:)? (.*)') re_check = re.compile('CHECK: (.*)') re_file = re.compile('#\d+: FILE: ([^:]*):(\d+):') - + re_note = re.compile('NOTE: (.*)') + indent = ' ' * 6 for line in result.stdout.splitlines(): if verbose: print(line) @@ -96,6 +97,14 @@ def CheckPatch(fname, verbose=False): result.problems.append(item) item = {} continue + if re_note.match(line): + continue + # Skip lines which quote code + if line.startswith(indent): + continue + # Skip code quotes and #<n> + if line.startswith('+') or line.startswith('#'): + continue match = re_stats_full.match(line) if not match: match = re_stats.match(line)

If checkpatch is configured to output code we should ignore it. Similarly, notes should be ignored.
Update the logic to handle these situations.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!

Sometimes checkpatch outputs problems in the patch subject. Add support for parsing this output and reporting it correctly.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index 5426bb9e9e..5ae450d771 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -127,6 +127,7 @@ def CheckPatch(fname, verbose=False): warn_match = re_warning.match(line) file_match = re_file.match(line) check_match = re_check.match(line) + subject_match = line.startswith('Subject:') if err_match: item['msg'] = err_match.group(1) item['type'] = 'error' @@ -139,6 +140,9 @@ def CheckPatch(fname, verbose=False): elif file_match: item['file'] = file_match.group(1) item['line'] = int(file_match.group(2)) + elif subject_match: + item['file'] = '<patch subject>' + item['line'] = None
return result
@@ -157,7 +161,8 @@ def GetWarningMsg(col, msg_type, fname, line, msg): msg_type = col.Color(col.RED, msg_type) elif msg_type == 'check': msg_type = col.Color(col.MAGENTA, msg_type) - return '%s:%d: %s: %s\n' % (fname, line, msg_type, msg) + line_str = '' if line is None else '%d' % line + return '%s:%s: %s: %s\n' % (fname, line_str, msg_type, msg)
def CheckPatches(verbose, args): '''Run the checkpatch.pl script on each patch'''

Sometimes checkpatch outputs problems in the patch subject. Add support for parsing this output and reporting it correctly.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!

Rather than suffering in silence, output a warning if something about the checkpatch output cannot be understood.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index 5ae450d771..98c63af1dd 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -143,6 +143,8 @@ def CheckPatch(fname, verbose=False): elif subject_match: item['file'] = '<patch subject>' item['line'] = None + else: + print('bad line "%s", %d' % (line, len(line)))
return result

Rather than suffering in silence, output a warning if something about the checkpatch output cannot be understood.
Signed-off-by: Simon Glass sjg@chromium.org ---
tools/patman/checkpatch.py | 2 ++ 1 file changed, 2 insertions(+)
Applied to u-boot-dm, thanks!
participants (2)
-
Simon Glass
-
sjg@google.com