From 7d2af9f8dc7a3206709df261915dae9434a9fc4a Mon Sep 17 00:00:00 2001 From: Aki Van Ness Date: Mon, 22 Aug 2022 06:12:49 -0400 Subject: [PATCH 1/2] misc: add .clang_tidy --- .clang-tidy | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..ff4223542 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,30 @@ +--- +Checks: 'bugprone-*,cert-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,portability-*,clang-analyzer-unix,clang-analyzer-security,clang-analyzer-deadcode,clang-analyzer-core,clang-analyzer-cplusplus,clang-analyzer-optin,-modernize-use-trailing-return-type,-cppcoreguidelines-avoid-magic-numbers,-readability-redundant-member-init,-readability-else-after-return,-readability-implicit-bool-conversion,-cppcoreguidelines-pro-type-vararg,-readability-named-parameter,-readability-magic-numbers,-clang-diagnostic-c++17-extensions' +WarningsAsErrors: '' +HeaderFilterRegex: '(backends|frontends|kernel|passes|techlibs)/.*' +FormatStyle: 'none' +AnalyzeTemporaryDtors: false +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: '0' + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: '0' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: camelBack + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' + - key: readability-braces-around-statements.ShortStatementLines + value: '4' +... From fac71a215cfe7d6d9ecdeead81e929f62f1c3223 Mon Sep 17 00:00:00 2001 From: Aki Van Ness Date: Thu, 15 Sep 2022 05:39:17 -0400 Subject: [PATCH 2/2] misc: added clang-tidy wrapper --- misc/run-clang-tidy.py | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 misc/run-clang-tidy.py diff --git a/misc/run-clang-tidy.py b/misc/run-clang-tidy.py new file mode 100755 index 000000000..52db1df97 --- /dev/null +++ b/misc/run-clang-tidy.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import sys + +from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter +from pathlib import Path +from subprocess import run +from concurrent.futures import ThreadPoolExecutor + +def main() -> int: + parser = ArgumentParser( + formatter_class = ArgumentDefaultsHelpFormatter, + description = 'clang-tidy runner', + prog = 'run-clang-tidy.py', + ) + + parser.add_argument( + '--source-path', '-s', + required = True, + type = Path, + metavar = 'source_path', + help = 'Path to the source directory to run clang-tidy in' + ) + + parser.add_argument( + '--build-path', '-p', + required = True, + type = Path, + metavar = 'build_path', + help = 'Path to the build directory containing a compile_commands.json' + ) + + args = parser.parse_args() + + def glob_files(): + paths = {'backends', 'frontend', 'kernel', 'passes', 'techlibs'} + suffixes = {'cc', 'h'} + + for path in paths: + for suffix in suffixes: + yield args.source_path.glob(f'{path}/**/*.{suffix}') + + def gather_files(): + for file_glob in glob_files(): + for file in file_glob: + yield file + + extra_args = () + futures = [] + + with ThreadPoolExecutor() as pool: + for file in gather_files(): + futures.append(pool.submit( + run, ['clang-tidy', *extra_args, '-p', args.build_path, file] + )) + + return max((future.result().returncode for future in futures)) + + +if __name__ == '__main__': + sys.exit(main())