aboutsummaryrefslogtreecommitdiffstats
path: root/wscript
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-07-02 00:01:14 +0200
committerDavid Robillard <d@drobilla.net>2020-07-02 00:01:14 +0200
commit6422c76a31f8dd73acebc5f6dca34f8423e78ecc (patch)
treeef9171c46b418206f9bcd9cb24dfe6278dafb474 /wscript
parent3b43e447d61e937ce5a56cf976c737d8aac270b2 (diff)
downloadpugl-6422c76a31f8dd73acebc5f6dca34f8423e78ecc.tar.gz
pugl-6422c76a31f8dd73acebc5f6dca34f8423e78ecc.tar.bz2
pugl-6422c76a31f8dd73acebc5f6dca34f8423e78ecc.zip
Strengthen lint target
Diffstat (limited to 'wscript')
-rw-r--r--wscript85
1 files changed, 66 insertions, 19 deletions
diff --git a/wscript b/wscript
index f23bf78..2cf68dd 100644
--- a/wscript
+++ b/wscript
@@ -3,7 +3,7 @@
import os
import sys
-from waflib import Logs, Options, TaskGen
+from waflib import Build, Logs, Options, TaskGen
from waflib.extras import autowaf
# Library and package version (UNIX style major, minor, micro)
@@ -56,6 +56,12 @@ def configure(conf):
conf.env.TARGET_PLATFORM = Options.options.target or sys.platform
platform = conf.env.TARGET_PLATFORM
+ 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)
+
def append_cflags(flags):
conf.env.append_value('CFLAGS', flags)
conf.env.append_value('CXXFLAGS', flags)
@@ -414,31 +420,72 @@ def test(tst):
check(['test/test_%s' % test])
+class LintContext(Build.BuildContext):
+ fun = cmd = 'lint'
+
+
def lint(ctx):
"checks code for style issues"
import json
import subprocess
- subprocess.call("flake8 wscript --ignore E221,W504,E251,E241,E741",
- shell=True)
-
- with open('build/compile_commands.json', 'r') as db:
- commands = json.load(db)
- files = [c['file'] for c in commands
- if os.path.basename(c['file']) != 'glad.c']
-
- c_files = [f for f in files if f.endswith('.c')]
- cpp_files = [f for f in files if f.endswith('.cpp')]
-
- subprocess.call(['clang-tidy'] + c_files, cwd='build')
+ st = 0
- subprocess.call(['clang-tidy', '--header-filter=".*\\.hpp'] + cpp_files,
- cwd='build')
+ 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.CC[0]:
+ Logs.info("Running clang-tidy")
+ with open('build/compile_commands.json', 'r') as db:
+ commands = json.load(db)
+ files = [c['file'] for c in commands
+ if os.path.basename(c['file']) != 'glad.c']
+
+ c_files = [os.path.join('build', f)
+ for f in files if f.endswith('.c')]
+
+ cpp_files = [os.path.join('build', f)
+ for f in files if f.endswith('.cpp')]
+
+ c_files = list(map(os.path.abspath, c_files))
+ cpp_files = list(map(os.path.abspath, cpp_files))
+
+ procs = []
+ for c_file in c_files:
+ cmd = [ctx.env.CLANG_TIDY[0], "--quiet", "-p=.", c_file]
+ procs += [subprocess.Popen(cmd, cwd="build")]
+
+ for cpp_file in cpp_files:
+ cmd = [ctx.env.CLANG_TIDY[0],
+ '--header-filter=".*\\.hpp"',
+ "--quiet",
+ "-p=.", cpp_file]
+ procs += [subprocess.Popen(cmd, cwd="build")]
+
+ for proc in procs:
+ stdout, stderr = proc.communicate()
+ st += proc.returncode
+ else:
+ Logs.warn("Not running clang-tidy")
- try:
- subprocess.call(['iwyu_tool.py', '-o', 'clang', '-p', 'build'])
- except Exception:
- Logs.warn('Failed to call iwyu_tool.py')
+ if st != 0:
+ sys.exit(st)
# Alias .m files to be compiled like .c files, gcc will do the right thing.