From a29ec8486677a2797c3bf85d86da54abe169ac7e Mon Sep 17 00:00:00 2001 From: Thibault Kruse Date: Sat, 23 Apr 2016 23:03:07 +0200 Subject: [PATCH] The cpplint returns non-zero when there is at least one message. If the cpplint is started from a make file, the non-zero return value will stop. Proposal is to add "--return=value" option that forces the script return the given value even when there is messages (see PC-lint -zero). Attached batch adds the option to the cpplint and it has been tested with cmake + Visual Studio 2013. Based on https://github.com/google/styleguide/issues/28 by ksole...@gmail.com --- cpplint.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/cpplint.py b/cpplint.py index b756f7a..c51ffce 100644 --- a/cpplint.py +++ b/cpplint.py @@ -60,7 +60,7 @@ _USAGE = """ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] [--counting=total|toplevel|detailed] [--root=subdir] - [--linelength=digits] + [--linelength=digits] [--return=return value] [file] ... The style guidelines this tries to follow are those in @@ -139,6 +139,14 @@ Examples: --extensions=hpp,cpp + return=return value + The return value of the script is forced to given value for + preventing make files to stop too early. + + Examples: + --return=0 + + cpplint.py supports per-directory configurations specified in CPPLINT.cfg files. CPPLINT.cfg file can contain a number of key=value pairs. Currently the following options are supported: @@ -525,6 +533,10 @@ def u(x): itervalues = dict.values iteritems = dict.items +# The forces return value of the script to given value if defined. +# This is set by --return flag. +_return = None + def ParseNolintSuppressions(filename, raw_line, linenum, error): """Updates the global list of error-suppressions. @@ -6282,7 +6294,8 @@ def ParseArguments(args): 'filter=', 'root=', 'linelength=', - 'extensions=']) + 'extensions=', + 'return=']) except getopt.GetoptError: PrintUsage('Invalid arguments.') @@ -6322,8 +6335,13 @@ def ParseArguments(args): try: _valid_extensions = set(val.split(',')) except ValueError: - PrintUsage('Extensions must be comma seperated list.') - + PrintUsage('Extensions must be comma separated list.') + elif opt == '--return': + global _return + try: + _return = int(val) + except ValueError: + PrintUsage('Return value shall be integer.') if not filenames: PrintUsage('No files were specified.') @@ -6350,6 +6368,8 @@ def main(): finally: sys.stderr = backup_err + if _return is not None: + sys.exit(_return) sys.exit(_cpplint_state.error_count > 0)