From 18c30e6bdd219dc34963d8145d14ab8f81c5d3f8 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 27 Jul 2018 11:22:22 +0100
Subject: Add clang-tidy support

This adds a single check (which is already enough to fail).
clang-tidy < 7 requires absolute paths in the
compile-commands.json, which isn't what will happen here. If you
want to run with a previous version (6 is latest, 7 expected in a
month), apply this patch (which will break normal ninja
compilation, thus not applying it properly, and I'm not sure
it's worth any time getting it work when the clang-tidy bug is
fixed imminently):

diff --git a/BuildTools/scons2ninja.py b/BuildTools/scons2ninja.py
index df4c6559d..13e78d650 100755
--- a/BuildTools/scons2ninja.py
+++ b/BuildTools/scons2ninja.py
@@ -168,8 +168,16 @@ class NinjaBuilder :
         self.variables += str(name) + " = " + str(value) + "\n"

     def build(self, target, rule, sources = None, **kwargs) :
+        if is_list(target):
+            target = [os.path.abspath(x) for x in target]
+        else:
+            target = os.path.abspath(target)
         self._build += "build " + self.to_string(target) + ": " + rule
         if sources :
+            if is_list(sources):
+                sources = [os.path.abspath(x) for x in sources]
+            elif isinstance(sources, basestring):
+                sources = os.path.abspath(sources)
             self._build += " " + self.to_string(sources)
         if 'deps' in kwargs and kwargs['deps'] :
             self._build += " | " + self.to_string(kwargs["deps"])

Test-Information:
Running make clang-tidy spits out complaints about the code.

Change-Id: Ic9f43fd2e11ebd595b4b8a5cee8d290cd5349abf

diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..7d7f4ca
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,113 @@
+---
+Checks: >
+  -*,
+  boost-use-to-string,
+  # M-Link checks to enable later
+  # clang-diagnostic-*,
+  # misc-definitions-in-headers,
+  # misc-forwarding-reference-overload,
+  # misc-incorrect-roundings,
+  # misc-lambda-function-name,
+  # misc-macro-repeated-side-effects,
+  # misc-misplaced-const,
+  # misc-misplaced-widening-cast,
+  # misc-new-delete-overloads,
+  # misc-non-copyable-objects,
+  # misc-redundant-expression,
+  # misc-sizeof-container,
+  # misc-sizeof-expression,
+  # misc-static-assert,
+  # misc-string-compare,
+  # misc-string-integer-assignment,
+  # misc-string-literal-with-embedded-nul,
+  # misc-suspicious-enum-usage,
+  # misc-suspicious-missing-comma,
+  # misc-suspicious-semicolon,
+  # misc-suspicious-string-compare,
+  # misc-swapped-arguments,
+  # misc-throw-by-value-catch-by-reference,
+  # misc-unconventional-assign-operator,
+  # misc-undelegated-constructor,
+  # misc-uniqueptr-reset-release,
+  # misc-unused-alias-decls,
+  # misc-unused-raii,
+  # misc-unused-using-decls,
+  # modernize-avoid-bind,
+  # modernize-deprecated-headers,
+  # modernize-loop-convert,
+  # modernize-make-shared,
+  # modernize-make-unique,
+  # modernize-raw-string-literal,
+  # modernize-redundant-void-arg,
+  # modernize-replace-auto-ptr,
+  # modernize-replace-random-shuffle,
+  # modernize-return-braced-init-list,
+  # modernize-shrink-to-fit,
+  # modernize-unary-static-assert,
+  # modernize-use-bool-literals,
+  # modernize-use-default-member-init,
+  # modernize-use-equals-delete,
+  # modernize-use-noexcept,
+  # modernize-use-transparent-functors,
+  # modernize-use-uncaught-exceptions,
+  # modernize-use-using,
+  # performance-faster-string-find,
+  # performance-implicit-conversion-in-loop,
+  # performance-inefficient-algorithm,
+  # performance-inefficient-string-concatenation,
+  # performance-inefficient-vector-operation,
+  # performance-move-constructor-init,
+  # performance-noexcept-move-constructor,
+  # performance-type-promotion-in-math-fn,
+  # performance-unnecessary-copy-initialization,
+  # readability-avoid-const-params-in-decls,
+  # readability-delete-null-pointer,
+  # readability-deleted-default,
+  # readability-function-size,
+  # readability-identifier-naming,
+  # readability-inconsistent-declaration-parameter-name,
+  # readability-misleading-indentation,
+  # readability-misplaced-array-index,
+  # readability-non-const-parameter,
+  # readability-redundant-control-flow,
+  # readability-redundant-declaration,
+  # readability-redundant-function-ptr-dereference,
+  # readability-redundant-member-init,
+  # readability-redundant-smartptr-get,
+  # readability-redundant-string-cstr,
+  # readability-redundant-string-init,
+  # readability-simplify-subscript-expr,
+  # readability-static-accessed-through-instance,
+  # readability-static-definition-in-anonymous-namespace,
+  # readability-string-compare,
+  # readability-uniqueptr-delete-release
+# Fix code and enable checks:
+#  misc-unused-parameters,
+#  modernize-pass-by-value,
+#  modernize-use-auto,
+#  modernize-use-emplace,
+#  modernize-use-equals-default,
+#  modernize-use-nullptr,
+#  modernize-use-override,
+#  performance-for-range-copy,
+#  performance-move-const-arg,
+#  performance-unnecessary-value-param,
+#  readability-braces-around-statements,
+#  readability-container-size-empty,
+#  readability-else-after-return,
+#  readability-implicit-bool-conversion,
+#  readability-named-parameter,
+#  readability-redundant-smartptr-get,
+#  readability-simplify-boolean-expr,
+WarningsAsErrors: '*'
+HeaderFilterRegex: '(Swift|Swiften|Sluift)/.*'
+AnalyzeTemporaryDtors: false
+CheckOptions:
+  - key: modernize-loop-convert.MaxCopySize
+    value: '16'
+  - key: modernize-loop-convert.MinConfidence
+    value: reasonable
+  - key: modernize-use-nullptr.NullMacros
+    value: 'NULL'
+  - key: readability-identifier-naming.PrivateMemberSuffix
+    value: '_'
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d72f311
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+.PHONY: all
+all: build.ninja
+	ninja
+
+.PHONY: clang-tidy
+clang-tidy: compile_commands.json
+	ninja -t targets all | grep cxx | grep -v 3rdParty | sed -e's/\.o: cxx/.cpp/' | xargs -n 1 clang-tidy
+
+compile_commands.json: build.ninja
+	ninja -t compdb cxx > compile_commands.json
+
+build.ninja:
+	./BuildTools/scons2ninja.py check=1 build_examples=0
-- 
cgit v0.10.2-6-g49f6