def LintFiles(files, jobs=1, progress_prefix=''): if not IsCppLintAvailable(): print( printer.COLOUR_RED + \ ("cpplint.py not found. Please ensure the depot" " tools are installed and in your PATH. See" " http://dev.chromium.org/developers/how-tos/install-depot-tools for" " details.") + \ printer.NO_COLOUR) return -1 pool = multiprocessing.Pool(jobs) # The '.get(9999999)' is workaround to allow killing the test script with # ctrl+C from the shell. This bug is documented at # http://bugs.python.org/issue8296. tasks = [(f, progress_prefix) for f in files] # Run under a try-catch to avoid flooding the output when the script is # interrupted from the keyboard with ctrl+C. try: results = pool.map_async(LintWrapper, tasks).get(9999999) pool.close() pool.join() except KeyboardInterrupt: pool.terminate() sys.exit(1) n_errors = sum(results) printer.PrintOverwritableLine(progress_prefix + 'Total errors found: %d' % n_errors) printer.EnsureNewLine() return n_errors
def ClangFormatFiles(files, in_place=False, jobs=1, progress_prefix=''): if not util.IsCommandAvailable('clang-format-3.6'): print( printer.COLOUR_RED + \ ("`clang-format-3.6` not found. Please ensure it is installed " "and in your PATH.") + \ printer.NO_COLOUR) return -1 pool = multiprocessing.Pool(jobs) # The '.get(9999999)' is workaround to allow killing the test script with # ctrl+C from the shell. This bug is documented at # http://bugs.python.org/issue8296. tasks = [(f, in_place, progress_prefix) for f in files] # Run under a try-catch to avoid flooding the output when the script is # interrupted from the keyboard with ctrl+C. try: results = pool.map_async(ClangFormatWrapper, tasks).get(9999999) pool.close() pool.join() except KeyboardInterrupt: pool.terminate() sys.exit(1) rc = sum(results) printer.PrintOverwritableLine(progress_prefix + '%d files are incorrectly formatted.' % rc, type=printer.LINE_TYPE_LINTER) printer.EnsureNewLine() return rc
def ClangFormatFiles(files, clang_format, in_place=False, jobs=1, progress_prefix=''): if not ClangFormatIsAvailable(clang_format): error_message = "`{}` version {}.{} not found. Please ensure it " \ "is installed, in your PATH and the correct version." \ .format(clang_format, CLANG_FORMAT_VERSION_MAJOR, CLANG_FORMAT_VERSION_MINOR) print(printer.COLOUR_RED + error_message + printer.NO_COLOUR) return -1 pool = multiprocessing.Pool(jobs) # The '.get(9999999)' is workaround to allow killing the test script with # ctrl+C from the shell. This bug is documented at # http://bugs.python.org/issue8296. tasks = [(f, clang_format, in_place, progress_prefix) for f in files] # Run under a try-catch to avoid flooding the output when the script is # interrupted from the keyboard with ctrl+C. try: results = pool.map_async(ClangFormatWrapper, tasks).get(9999999) pool.close() pool.join() except KeyboardInterrupt: pool.terminate() sys.exit(1) rc = sum(results) printer.PrintOverwritableLine(progress_prefix + '%d files are incorrectly formatted.' % rc, type=printer.LINE_TYPE_LINTER) printer.EnsureNewLine() return rc
def ClangFormatFiles(files, clang_format, in_place=False, jobs=1, progress_prefix=''): if not ClangFormatIsAvailable(clang_format): error_message = "`{}` version {}.{} not found. Please ensure it " \ "is installed, in your PATH and the correct version." \ .format(clang_format, CLANG_FORMAT_VERSION_MAJOR, CLANG_FORMAT_VERSION_MINOR) print(printer.COLOUR_RED + error_message + printer.NO_COLOUR) return -1 queue = TestQueue(prefix=progress_prefix) for f in files: queue.AddTest(f, filename=f, clang_format=clang_format, in_place=in_place) rc = queue.Run(jobs, True, RunTest) printer.PrintOverwritableLine(progress_prefix + '%d files are incorrectly formatted.' % rc, type=printer.LINE_TYPE_LINTER) printer.EnsureNewLine() return rc
def LintFiles(files, jobs = 1, progress_prefix = '', cached_results = None): if not IsCppLintAvailable(): print( printer.COLOUR_RED + \ ("cpplint.py not found. Please ensure the depot" " tools are installed and in your PATH. See" " http://dev.chromium.org/developers/how-tos/install-depot-tools for" " details.") + \ printer.NO_COLOUR) return -1 # Filter out directories. files = filter(os.path.isfile, files) # Filter out files for which we have a cached correct result. if cached_results is not None and len(cached_results) != 0: n_input_files = len(files) files = filter(lambda f: ShouldLint(f, cached_results), files) n_skipped_files = n_input_files - len(files) if n_skipped_files != 0: printer.Print( progress_prefix + 'Skipping %d correct files that were already processed.' % n_skipped_files) pool = multiprocessing.Pool(jobs) # The '.get(9999999)' is workaround to allow killing the test script with # ctrl+C from the shell. This bug is documented at # http://bugs.python.org/issue8296. tasks = [(f, progress_prefix) for f in files] # Run under a try-catch to avoid flooding the output when the script is # interrupted from the keyboard with ctrl+C. try: results = pool.map_async(LintWrapper, tasks).get(9999999) pool.close() pool.join() except KeyboardInterrupt: pool.terminate() sys.exit(1) n_errors = sum(map(lambda (filename, errors): errors, results)) if cached_results is not None: for filename, errors in results: if errors == 0: with open(filename, 'rb') as f: filename = os.path.realpath(filename) file_hash = hashlib.md5(f.read()).hexdigest() cached_results[filename] = file_hash printer.PrintOverwritableLine( progress_prefix + 'Total errors found: %d' % n_errors) printer.EnsureNewLine() return n_errors
def Lint(filename, progress_prefix=''): command = ['cpplint.py', filename] process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Use a lock to avoid mixing the output for different files. with __lint_results_lock__: # Process the output as the process is running, until it exits. LINT_ERROR_LINE_REGEXP = re.compile('\[[1-5]\]$') LINT_DONE_PROC_LINE_REGEXP = re.compile('Done processing') LINT_STATUS_LINE_REGEXP = re.compile('Total errors found') while True: retcode = process.poll() while True: line = process.stderr.readline() if line == '': break output_line = progress_prefix + line.rstrip('\r\n') if LINT_ERROR_LINE_REGEXP.search(line): printer.PrintOverwritableLine( output_line, type=printer.LINE_TYPE_LINTER) printer.EnsureNewLine() elif LINT_DONE_PROC_LINE_REGEXP.search(line): printer.PrintOverwritableLine( output_line, type=printer.LINE_TYPE_LINTER) elif LINT_STATUS_LINE_REGEXP.search(line): status_line = line if retcode != None: break if retcode == 0: return 0 # Return the number of errors in this file. res = re.search('\d+$', status_line) n_errors_str = res.string[res.start():res.end()] n_errors = int(n_errors_str) status_line = \ progress_prefix + 'Total errors found in %s : %d' % (filename, n_errors) printer.PrintOverwritableLine(status_line, type=printer.LINE_TYPE_LINTER) printer.EnsureNewLine() return n_errors
def LintFiles(files, lint_args=CPP_LINTER_RULES, jobs=1, verbose=False, progress_prefix=''): lint_options = '--filter=-,+' + ',+'.join(lint_args) pool = multiprocessing.Pool(jobs) # The '.get(9999999)' is workaround to allow killing the test script with # ctrl+C from the shell. This bug is documented at # http://bugs.python.org/issue8296. tasks = [(f, lint_options, progress_prefix, verbose) for f in files] results = pool.map_async(LintWrapper, tasks).get(9999999) n_errors = sum(results) printer.PrintOverwritableLine(progress_prefix + 'Total errors found: %d' % n_errors) printer.EnsureNewLine() return n_errors