diff options
-rw-r--r-- | .clang-tidy | 66 | ||||
-rw-r--r-- | wscript | 62 |
2 files changed, 127 insertions, 1 deletions
diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..8e7c23d --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,66 @@ +Checks: > + *, + -*-braces-around-statements, + -*-c-arrays, + -*-else-after-return, + -*-magic-numbers, + -*-member-init, + -*-narrowing-conversions, + -*-no-malloc, + -*-non-private-member-variables-in-classes, + -*-special-member-functions, + -*-unused-macros, + -*-uppercase-literal-suffix, + -*-use-auto, + -*-use-emplace, + -*-use-equals-default, + -*-use-override, + -*-use-override, + -*-vararg, + -bugprone-branch-clone, + -bugprone-forward-declaration-namespace, + -cert-msc30-c, + -cert-msc50-cpp, + -clang-analyzer-optin.cplusplus.VirtualCall, + -clang-diagnostic-unreachable-code-return, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-explicit-virtual-functions, + -cppcoreguidelines-init-variables, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-reinterpret-cast, + -cppcoreguidelines-pro-type-union-access, + -fuchsia-default-arguments-calls, + -fuchsia-default-arguments-declarations, + -fuchsia-multiple-inheritance, + -fuchsia-overloaded-operator, + -google-default-arguments, + -google-explicit-constructor, + -google-readability-casting, + -google-runtime-references, + -hicpp-explicit-conversions, + -hicpp-no-array-decay, + -hicpp-signed-bitwise, + -llvm-header-guard, + -llvmlibc-*, + -misc-unused-parameters, + -modernize-loop-convert, + -modernize-use-nullptr, + -modernize-use-trailing-return-type, + -modernize-use-using, + -performance-faster-string-find, + -performance-unnecessary-value-param, + -readability-convert-member-functions-to-static, + -readability-implicit-bool-conversion, + -readability-inconsistent-declaration-parameter-name, + -readability-isolate-declaration, + -readability-make-member-function-const, + -readability-redundant-smartptr-get, + -readability-static-accessed-through-instance, +FormatStyle: file +WarningsAsErrors: '*' +HeaderFilterRegex: 'src/.*'
\ No newline at end of file @@ -5,7 +5,7 @@ import os -from waflib import Options, Utils +from waflib import Build, Logs, Options, Utils from waflib.extras import autowaf # Version of this package (even if built as a child) @@ -50,6 +50,12 @@ def configure(conf): conf.load('autowaf', cache=True) autowaf.set_cxx_lang(conf, 'c++11') + if Options.options.strict: + # Check for programs used by lint target + conf.find_program("flake8", var="FLAKE8", mandatory=False) + conf.find_program("clang-tidy", var="CLANG_TIDY", mandatory=False) + conf.find_program("iwyu_tool", var="IWYU_TOOL", mandatory=False) + if Options.options.ultra_strict: autowaf.add_compiler_flags(conf.env, '*', { 'clang': [ @@ -306,3 +312,57 @@ def build(bld): os.path.join('icons', 'scalable', 'patchage.svg')) bld.install_files('${MANDIR}/man1', bld.path.ant_glob('doc/*.1')) + + +class LintContext(Build.BuildContext): + fun = cmd = 'lint' + + +def lint(ctx): + "checks code for style issues" + import subprocess + import sys + + st = 0 + + if "FLAKE8" in ctx.env: + Logs.info("Running flake8") + st = subprocess.call([ctx.env.FLAKE8[0], + "wscript", + "--ignore", + "E221,W504,E251,E241,E741"]) + else: + Logs.warn("Not running flake8") + + if "IWYU_TOOL" in ctx.env: + Logs.info("Running include-what-you-use") + cmd = [ctx.env.IWYU_TOOL[0], "-o", "clang", "-p", "build"] + output = subprocess.check_output(cmd).decode('utf-8') + if 'error: ' in output: + sys.stdout.write(output) + st += 1 + else: + Logs.warn("Not running include-what-you-use") + + if "CLANG_TIDY" in ctx.env and "clang" in ctx.env.CXX[0]: + Logs.info("Running clang-tidy") + + import json + + with open('build/compile_commands.json', 'r') as db: + commands = json.load(db) + files = [c['file'] for c in commands] + + procs = [] + for f in files: + cmd = [ctx.env.CLANG_TIDY[0], '--quiet', '-p=.', f] + procs += [subprocess.Popen(cmd, cwd='build')] + + for proc in procs: + proc.communicate() + st += proc.returncode + else: + Logs.warn("Not running clang-tidy") + + if st != 0: + sys.exit(st) |