From patchwork Wed May 6 22:29:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 245250 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Wed, 6 May 2020 16:29:04 -0600 Subject: [PATCH 1/6] patman: Fix 'warning' typo In-Reply-To: <20200506222910.152322-1-sjg@chromium.org> References: <20200506222910.152322-1-sjg@chromium.org> Message-ID: <20200506222910.152322-2-sjg@chromium.org> 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 --- 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() From patchwork Wed May 6 22:29:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 245251 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Wed, 6 May 2020 16:29:05 -0600 Subject: [PATCH 2/6] patman: Support emacs mode with checkpatch In-Reply-To: <20200506222910.152322-1-sjg@chromium.org> References: <20200506222910.152322-1-sjg@chromium.org> Message-ID: <20200506222910.152322-3-sjg@chromium.org> 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 --- 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+):') From patchwork Wed May 6 22:29:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 245252 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Wed, 6 May 2020 16:29:06 -0600 Subject: [PATCH 3/6] patman: Don't try to process checkpatch lines twice In-Reply-To: <20200506222910.152322-1-sjg@chromium.org> References: <20200506222910.152322-1-sjg@chromium.org> Message-ID: <20200506222910.152322-4-sjg@chromium.org> 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 --- 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) From patchwork Wed May 6 22:29:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 245254 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Wed, 6 May 2020 16:29:07 -0600 Subject: [PATCH 4/6] patman: Handle checkpatch output with notes and code In-Reply-To: <20200506222910.152322-1-sjg@chromium.org> References: <20200506222910.152322-1-sjg@chromium.org> Message-ID: <20200506222910.152322-5-sjg@chromium.org> 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 --- 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 # + if line.startswith('+') or line.startswith('#'): + continue match = re_stats_full.match(line) if not match: match = re_stats.match(line) From patchwork Wed May 6 22:29:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 245253 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Wed, 6 May 2020 16:29:08 -0600 Subject: [PATCH 5/6] patman: Support warnings in the patch subject In-Reply-To: <20200506222910.152322-1-sjg@chromium.org> References: <20200506222910.152322-1-sjg@chromium.org> Message-ID: <20200506222910.152322-6-sjg@chromium.org> Sometimes checkpatch outputs problems in the patch subject. Add support for parsing this output and reporting it correctly. Signed-off-by: Simon Glass --- 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'] = '' + 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''' From patchwork Wed May 6 22:29:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 245255 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Wed, 6 May 2020 16:29:09 -0600 Subject: [PATCH 6/6] patman: Complain if a checkpatch line is not understood In-Reply-To: <20200506222910.152322-1-sjg@chromium.org> References: <20200506222910.152322-1-sjg@chromium.org> Message-ID: <20200506222910.152322-7-sjg@chromium.org> Rather than suffering in silence, output a warning if something about the checkpatch output cannot be understood. Signed-off-by: Simon Glass --- 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'] = '' item['line'] = None + else: + print('bad line "%s", %d' % (line, len(line))) return result