summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-09-27 15:36:31 +0200
committerDavid Robillard <d@drobilla.net>2020-09-27 15:38:06 +0200
commit734e1b81413a948a0948c9ea8fee278b2ff3645b (patch)
tree365971bb135d597031742c48ef3fdb58e6c33eac
parente102c25959461d5b961bdb42c725cedfb91ba2df (diff)
downloadsuil-734e1b81413a948a0948c9ea8fee278b2ff3645b.tar.gz
suil-734e1b81413a948a0948c9ea8fee278b2ff3645b.tar.bz2
suil-734e1b81413a948a0948c9ea8fee278b2ff3645b.zip
Strengthen lint target
-rw-r--r--.clang-tidy15
-rw-r--r--NEWS1
-rw-r--r--wscript73
3 files changed, 75 insertions, 14 deletions
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..6daa935
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,15 @@
+Checks: >
+ *,
+ -*-magic-numbers,
+ -*-uppercase-literal-suffix,
+ -bugprone-suspicious-string-compare,
+ -clang-analyzer-core.CallAndMessage,
+ -cppcoreguidelines-init-variables,
+ -hicpp-signed-bitwise,
+ -llvm-header-guard,
+ -readability-else-after-return,
+ -readability-isolate-declaration,
+ -readability-non-const-parameter,
+WarningsAsErrors: '*'
+HeaderFilterRegex: '.*'
+FormatStyle: file
diff --git a/NEWS b/NEWS
index 024350d..9c27dee 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ suil (0.10.7) unstable;
* Fix X11 in Gtk size regressions (thanks Robin Gareus)
* Fix compilation on MacOS older than 10.12
* Fix drag and drop for X11 in Gtk
+ * Fix various minor warnings and other code quality issues
-- David Robillard <d@drobilla.net> Wed, 12 Feb 2020 19:12:01 +0000
diff --git a/wscript b/wscript
index e8df3ba..76fb014 100644
--- a/wscript
+++ b/wscript
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-from waflib import Options, TaskGen
+from waflib import Build, Logs, Options, TaskGen
from waflib.extras import autowaf
# Semver package/library version
@@ -55,6 +55,12 @@ def configure(conf):
if not conf.env.BUILD_SHARED and not conf.env.BUILD_STATIC:
conf.fatal('Neither a shared nor a static build requested')
+ 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, '*', {
'gcc': [
@@ -471,22 +477,61 @@ 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 glob
+ import os
import subprocess
- cmd = ("clang-tidy -p=. -header-filter=suil/ -checks=\"*," +
- "-clang-analyzer-alpha.*," +
- "-cppcoreguidelines-*," +
- "-google-readability-todo," +
- "-llvm-header-guard," +
- "-llvm-include-order," +
- "-misc-unused-parameters," +
- "-misc-unused-parameters," +
- "-modernize-*," +
- "-readability-else-after-return," +
- "-readability-implicit-bool-cast\" " +
- "$(find .. -name '*.c' -or -name '*.cpp' -or -name '*.mm')")
- subprocess.call(cmd, cwd='build', shell=True)
+ import sys
+
+ 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")
+
+ qt_mapping_file = "/usr/share/include-what-you-use/qt5_11.imp"
+ extra_args = []
+ if os.path.exists(qt_mapping_file):
+ extra_args += ["--", "-Xiwyu", "--mapping_file=" + qt_mapping_file]
+
+ cmd = [ctx.env.IWYU_TOOL[0], "-o", "clang", "-p", "build"] + extra_args
+ 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 dist(ctx):