def _check_dir(arguments, source_dir, exclude_globs): formatted_filenames = [] for path in lintutils.get_sources(source_dir, exclude_globs): formatted_filenames.append(str(path)) if arguments.fix: if not arguments.quiet: print("\n".join( map(lambda x: "Formatting {}".format(x), formatted_filenames))) # Break clang-format invocations into chunks: each invocation formats # 16 files. Wait for all processes to complete results = lintutils.run_parallel( [[arguments.clang_format_binary, "-style=file", "-i"] + some for some in lintutils.chunk(formatted_filenames, 16)]) for returncode, stdout, stderr in results: # if any clang-format reported a parse error, bubble it if returncode != 0: sys.exit(returncode) else: # run an instance of clang-format for each source file in parallel, # then wait for all processes to complete results = lintutils.run_parallel( [[arguments.clang_format_binary, "-style=file", filename] for filename in formatted_filenames], stdout=PIPE, stderr=PIPE) checker_args = [] for filename, res in zip(formatted_filenames, results): # if any clang-format reported a parse error, bubble it returncode, stdout, stderr = res if returncode != 0: print(stderr) sys.exit(returncode) checker_args.append((filename, stdout)) error = False pool = mp.Pool() try: # check the output from each invocation of clang-format in parallel for filename, diff in pool.starmap(_check_one_file, checker_args): if not arguments.quiet: print("Checking {}".format(filename)) if diff: print("{} had clang-format style issues".format(filename)) # Print out the diff to stderr error = True # pad with a newline print(file=sys.stderr) sys.stderr.writelines(diff) except Exception: error = True raise finally: pool.terminate() pool.join() sys.exit(1 if error else 0)
help="If specified, will re-format the source " "code instead of comparing the re-formatted " "output, defaults to %(default)s") parser.add_argument("--quiet", default=False, action="store_true", help="If specified, only print errors") arguments = parser.parse_args() exclude_globs = [] if arguments.exclude_globs: for line in open(arguments.exclude_globs): exclude_globs.append(line.strip()) formatted_filenames = [] for path in lintutils.get_sources(arguments.source_dir, exclude_globs): formatted_filenames.append(str(path)) if arguments.fix: if not arguments.quiet: print("\n".join( map(lambda x: "Formatting {}".format(x), formatted_filenames))) # Break clang-format invocations into chunks: each invocation formats # 16 files. Wait for all processes to complete results = lintutils.run_parallel( [[arguments.clang_format_binary, "-i"] + some for some in lintutils.chunk(formatted_filenames, 16)]) for returncode, stdout, stderr in results: # if any clang-format reported a parse error, bubble it if returncode != 0:
"that should be excluded from the checks") parser.add_argument("--source_dir", required=True, help="Root directory of the source code") parser.add_argument("--quiet", default=False, action="store_true", help="If specified, only print errors") arguments = parser.parse_args() exclude_globs = [] if arguments.exclude_globs: for line in open(arguments.exclude_globs): exclude_globs.append(line.strip()) linted_filenames = [] for path in lintutils.get_sources(arguments.source_dir, exclude_globs): linted_filenames.append(str(path)) cmd = [ arguments.cpplint_binary, '--verbose=2', '--linelength=90', '--filter=' + ','.join(_filters) ] if (arguments.cpplint_binary.endswith('.py') and platform.system() == 'Windows'): # Windows doesn't support executable scripts; execute with # sys.executable cmd.insert(0, sys.executable) if arguments.quiet: cmd.append('--quiet')
help="compile_commands.json to pass clang-tidy") parser.add_argument("--source_dir", required=True, help="Root directory of the source code") parser.add_argument("--fix", default=False, action="store_true", help="If specified, will attempt to fix the " "source code instead of recommending fixes, " "defaults to %(default)s") parser.add_argument("--quiet", default=False, action="store_true", help="If specified, only print errors") arguments = parser.parse_args() linted_filenames = [] for path in lintutils.get_sources(arguments.source_dir): linted_filenames.append(path) if not arguments.quiet: msg = 'Tidying {}' if arguments.fix else 'Checking {}' print("\n".join(map(msg.format, linted_filenames))) cmd = [ arguments.clang_tidy_binary, '-p', arguments.compile_commands ] if arguments.fix: cmd.append('-fix') results = lintutils.run_parallel( [cmd + some for some in lintutils.chunk(linted_filenames, 16)])
"source code instead of recommending fixes, " "defaults to %(default)s") parser.add_argument("--quiet", default=False, action="store_true", help="If specified, only print errors") arguments = parser.parse_args() exclude_globs = [] if arguments.exclude_globs: for line in open(arguments.exclude_globs): exclude_globs.append(line.strip()) linted_filenames = [] for source_dir in arguments.source_dir: for path in lintutils.get_sources(source_dir, exclude_globs): linted_filenames.append(path) if not arguments.quiet: msg = 'Tidying {}' if arguments.fix else 'Checking {}' print("\n".join(map(msg.format, linted_filenames))) cmd = [arguments.clang_tidy_binary, '-p', arguments.compile_commands] if arguments.fix: cmd.append('-fix') results = lintutils.run_parallel( [cmd + some for some in lintutils.chunk(linted_filenames, 16)]) for returncode, stdout, stderr in results: if returncode != 0: sys.exit(returncode)
required=True, help="Root directory of the source code") parser.add_argument("--fix", default=False, action="store_true", help="If specified, will attempt to fix the " "source code instead of recommending fixes, " "defaults to %(default)s") parser.add_argument("--quiet", default=False, action="store_true", help="If specified, only print errors") arguments = parser.parse_args() linted_filenames = [] for path in lintutils.get_sources(arguments.source_dir): linted_filenames.append(path) if not arguments.quiet: msg = 'Tidying {}' if arguments.fix else 'Checking {}' print("\n".join(map(msg.format, linted_filenames))) cmd = [arguments.clang_tidy_binary, '-p', arguments.compile_commands] if arguments.fix: cmd.append('-fix') results = lintutils.run_parallel( [cmd + some for some in lintutils.chunk(linted_filenames, 16)]) for result in results: result.check_returncode() else: