aboutsummaryrefslogtreecommitdiffstats
path: root/wscript
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-06-21 17:38:15 +0200
committerDavid Robillard <d@drobilla.net>2020-06-21 18:06:29 +0200
commita5ecaed57d31f68f0648464d99864b4cf0bdefac (patch)
tree3b350923ca9b76fff1c6784bd9158140a559c799 /wscript
parent4c596b02693f742a754b092285833b89036f172e (diff)
downloadserd-a5ecaed57d31f68f0648464d99864b4cf0bdefac.tar.gz
serd-a5ecaed57d31f68f0648464d99864b4cf0bdefac.tar.bz2
serd-a5ecaed57d31f68f0648464d99864b4cf0bdefac.zip
Strengthen lint target
Diffstat (limited to 'wscript')
-rw-r--r--wscript68
1 files changed, 48 insertions, 20 deletions
diff --git a/wscript b/wscript
index eb9495d0..ff20477b 100644
--- a/wscript
+++ b/wscript
@@ -4,7 +4,7 @@ import glob
import os
import sys
-from waflib import Logs, Options
+from waflib import Build, Logs, Options
from waflib.extras import autowaf
# Library and package version (UNIX style major, minor, micro)
@@ -47,6 +47,11 @@ def configure(conf):
if Options.options.strict and not conf.env.MSVC_COMPILER:
conf.env.append_unique('CFLAGS', '-Wno-cast-align')
+ # 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)
+
conf.env.update({
'BUILD_UTILS': not Options.options.no_utils,
'BUILD_SHARED': not Options.options.no_shared,
@@ -196,29 +201,52 @@ def build(bld):
bld.add_post_fun(autowaf.run_ldconfig)
+class LintContext(Build.BuildContext):
+ fun = cmd = 'lint'
+
+
def lint(ctx):
"checks code for style issues"
import subprocess
- subprocess.call(["flake8",
- "wscript",
- "--ignore=E101,E129,W191,E221,W504,E251,E241,E741"])
-
- cmd = ("clang-tidy -p=. -header-filter=.* -checks=\"*," +
- "-bugprone-suspicious-string-compare," +
- "-clang-analyzer-alpha.*," +
- "-google-readability-todo," +
- "-hicpp-signed-bitwise," +
- "-llvm-header-guard," +
- "-misc-unused-parameters," +
- "-readability-else-after-return\" " +
- "../src/*.c")
- subprocess.call(cmd, cwd='build', shell=True)
-
- try:
- subprocess.call(["iwyu_tool.py", "-o", "clang", "-p", "build"])
- except Exception:
- Logs.warn("Failed to call iwyu_tool.py")
+ st = 0
+
+ if "FLAKE8" in ctx.env:
+ Logs.info("Running flake8")
+ st = subprocess.call([ctx.env.FLAKE8[0],
+ "wscript",
+ "--ignore",
+ "E101,E129,W191,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.CC[0]:
+ Logs.info("Running clang-tidy")
+ sources = glob.glob('src/*.c') + glob.glob('tests/*.c')
+ sources = list(map(os.path.abspath, sources))
+ procs = []
+ for source in sources:
+ cmd = [ctx.env.CLANG_TIDY[0], "--quiet", "-p=.", source]
+ procs += [subprocess.Popen(cmd, cwd="build")]
+
+ for proc in procs:
+ stdout, stderr = proc.communicate()
+ st += proc.returncode
+ else:
+ Logs.warn("Not running clang-tidy")
+
+ if st != 0:
+ sys.exit(st)
def amalgamate(ctx):