Module: check_mk
Branch: master
Commit: 09dc8dbf563e45f06e8cbc6d8a1618941b577d57
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=09dc8dbf563e45…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Feb 20 15:14:38 2019 +0100
Add script to run C/C++ linters in an incremental fashion.
Change-Id: Ifa3e13ae049ac5c6b24cdb3bc49e08926c2e2cd9
---
livestatus/src/Makefile.am | 5 +++--
scripts/run-cxx-linter | 27 +++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/livestatus/src/Makefile.am b/livestatus/src/Makefile.am
index 6f7cc24..920378d 100644
--- a/livestatus/src/Makefile.am
+++ b/livestatus/src/Makefile.am
@@ -178,11 +178,12 @@ compile_commands.json: Makefile $(wildcard *.cc *.h)
$(BEAR) $(MAKE) -j4
tidy: compile_commands.json
- $(RUN_CLANG_TIDY) -quiet -j6
+ $(RUN_CLANG_TIDY) -quiet -j6 $(FILES_TO_CHECK)
iwyu: compile_commands.json
- $(IWYU_TOOL) --output-format=clang -p . --
--mapping_file=$(abs_top_srcdir)/livestatus/iwyu-mappings/check_mk.imp
+ $(IWYU_TOOL) --output-format=clang -p . $(FILES_TO_CHECK) --
--mapping_file=$(abs_top_srcdir)/livestatus/iwyu-mappings/check_mk.imp
+# NOTE: cppcheck seems to ignore files on the command line when --project=... is given.
:-P
cppcheck: compile_commands.json
$(CPPCHECK) -UCMC --enable=all --suppressions-list=cppcheck-suppressions.txt
--inline-suppr --project=compile_commands.json --quiet --template=gcc
diff --git a/scripts/run-cxx-linter b/scripts/run-cxx-linter
new file mode 100755
index 0000000..ef5ff68
--- /dev/null
+++ b/scripts/run-cxx-linter
@@ -0,0 +1,27 @@
+#! /bin/sh
+set -e
+TARGET=$1
+PATCHSET_REVISION=$2
+
+# ATTENTION! Extremely cunning hack ahead! Find out which files have been
+# changed in the current directory for the given commit. Transform those file
+# names into --what-if=... options for make and do a dry run with them. This
+# outputs the compilation commands needed, which we massage a bit with grep and
+# sed to finally find out which C/C++ we need to check. Brilliant! :-D ;-)
+FILES_TO_CHECK=$(make --dry-run \
+ $(git diff-tree --no-commit-id --name-only -r --relative
"${PATCHSET_REVISION}" | \
+ sed 's/\(.*\)/--what-if=\1/') \
+ all-am | \
+ grep " || echo './'\`" | \
+ sed "s,.* || echo '\\./'\`,,")
+
+if test -z "${FILES_TO_CHECK}"; then
+ echo "==================== nothing to do"
+ exit 0
+fi
+
+echo "==================== files to check:"
+echo "${FILES_TO_CHECK}"
+
+echo "==================== ${TARGET}"
+make ${TARGET} FILES_TO_CHECK="$(echo ${FILES_TO_CHECK})"