From 154dd24a549c7f8df1280eae997a4671e01b46fb Mon Sep 17 00:00:00 2001 From: Thibault Kruse Date: Wed, 7 Sep 2016 21:19:33 +0900 Subject: [PATCH] improve cpplint check by invoking python just once. Reduces time from 1m to 6s --- scripts/python/Makefile.in | 6 ++---- scripts/python/cpplint_wrap.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 scripts/python/cpplint_wrap.py diff --git a/scripts/python/Makefile.in b/scripts/python/Makefile.in index 46e809f..4ecff78 100644 --- a/scripts/python/Makefile.in +++ b/scripts/python/Makefile.in @@ -11,8 +11,6 @@ CXX_SRCS := $(wildcard *.cpp) CXX_LINT := ${CXX_SRCS:.cpp=.lint} .PHONY: cpplint-all -cpplint-all: $(CXX_LINT) - -%.lint: %.cpp - @python ../../python/cpplint.py --verbose=0 --linelength=100 --filter=-legal/copyright,-build/include_order,-build/c++11,-build/namespaces,-build/class,-build/include,-build/include_subdir,-readability/inheritance,-readability/function,-readability/casting,-readability/namespace,-readability/alt_tokens,-readability/braces,-readability/fn_size,-whitespace/comments,-whitespace/braces,-whitespace/empty_loop_body,-whitespace/indent,-whitespace/newline,-runtime/explicit,-runtime/arrays,-runtime/int,-runtime/references,-runtime/string,-runtime/operator $< || (cat $< | nl -ba | grep -v 'md-split' && false) +cpplint-all: + @python ../../python/cpplint_wrap.py *.cpp diff --git a/scripts/python/cpplint_wrap.py b/scripts/python/cpplint_wrap.py new file mode 100644 index 0000000..fd7a9f9 --- /dev/null +++ b/scripts/python/cpplint_wrap.py @@ -0,0 +1,32 @@ +## wraps local cpplint to produce verbose output without code harness +import cpplint +import sys + +def main(): + FILTERS='cpplint --verbose=0 --linelength=100 --filter=-legal/copyright,-build/include_order,-build/c++11,-build/namespaces,-build/class,-build/include,-build/include_subdir,-readability/inheritance,-readability/function,-readability/casting,-readability/namespace,-readability/alt_tokens,-readability/braces,-readability/fn_size,-whitespace/comments,-whitespace/braces,-whitespace/empty_loop_body,-whitespace/indent,-whitespace/newline,-runtime/explicit,-runtime/arrays,-runtime/int,-runtime/references,-runtime/string,-runtime/operator'.split(' ') + + result = False + files = sys.argv[1:] + for loopfile in files: + newargs = FILTERS + [loopfile] + sys.argv = newargs + + try: + cpplint.main() + except SystemExit as e: + last_result = e.args[0] + result = result or last_result + if (last_result): + write_code_lines(loopfile) + sys.exit(result) + +def write_code_lines(filename): + with open(filename, 'r') as f: + linenum = 1 + for line in f: + if (not '// by md-split' in line): + sys.stdout.write('%3d %s' % (linenum, line)) + linenum += 1 + +if __name__ == '__main__': + main()