diff options
author | David Robillard <d@drobilla.net> | 2020-11-27 17:57:32 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-27 21:42:51 +0100 |
commit | ad2624362adea4c998eb64b6b4d6bf458599e18a (patch) | |
tree | 0d16ba8d5582424db34fc00bebefc821521aba8e /wscript | |
parent | 40e84ba67cb7ae2b9a3b02889ec5c80ada639f85 (diff) | |
download | patchage-ad2624362adea4c998eb64b6b4d6bf458599e18a.tar.gz patchage-ad2624362adea4c998eb64b6b4d6bf458599e18a.tar.bz2 patchage-ad2624362adea4c998eb64b6b4d6bf458599e18a.zip |
Add lint target
Diffstat (limited to 'wscript')
-rw-r--r-- | wscript | 62 |
1 files changed, 61 insertions, 1 deletions
@@ -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) |