Call clang-tidy based on WITH_TIDY* variables.
* Call clang-tidy before every C/C++ compilation if
(1) clang-tidy is found at $(PATH_TO_CLANG_TIDY)
(2) $(my_clang) is true
(3) LOCAL_TIDY is 1 or true, or
LOCAL_TIDY is undefined and WITH_TIDY is 1 or true.
* clang-tidy is called with -checks=$(my_tidy_checks),
which has default '-*,google*,-google-readability*'
and can be overwritten by WITH_TIDY_CHECKS.
* LOCAL_TIDY_CHECKS is appended to $(my_tidy_checks)
* Extra flags are passed to clang-tidy through
WITH_TIDY_FLAGS or LOCAL_TIDY_FLAGS.
* To quickly find and fix clang-tidy warnings, set $(WITH_TIDY_ONLY)
to 1 or true to skip compilation of C/C++ files.
* Add a PHONY tidy_only target,
which includes all $(cpp_objects) and $(c_objects).
* The 'mm' and 'mmm' functions are changed to call make with
the 'tidy_only' target when WITH_TIDY_ONLY is true or 1.
In that case, only clang-tidy is called for C and C++ files.
Bug: http://b/27779618
Change-Id: I8adcfff217d68af49849b79aacee7d7654cafb1b
diff --git a/core/config.mk b/core/config.mk
index e63a135..eae66d3 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -348,6 +348,20 @@
# define clang/llvm versions and base directory.
include $(BUILD_SYSTEM)/clang/versions.mk
+# Unset WITH_TIDY_ONLY if global WITH_TIDY_ONLY is not true nor 1.
+ifeq (,$(filter 1 true,$(WITH_TIDY_ONLY)))
+ WITH_TIDY_ONLY :=
+endif
+
+PATH_TO_CLANG_TIDY := \
+ $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/bin/clang-tidy
+ifeq ($(wildcard $(PATH_TO_CLANG_TIDY)),)
+ ifneq (,$(filter 1 true,$(WITH_TIDY)))
+ $(warning *** Disable WITH_TIDY because $(PATH_TO_CLANG_TIDY) does not exist)
+ endif
+ PATH_TO_CLANG_TIDY :=
+endif
+
# Disable WITH_STATIC_ANALYZER and WITH_SYNTAX_CHECK if tool can't be found
SYNTAX_TOOLS_PREFIX := \
$(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/tools/scan-build/libexec