From 8c6533a4bb74a03cc44e01099f577d83272001c0 Mon Sep 17 00:00:00 2001 From: quicksilver Date: Tue, 11 Aug 2020 11:43:57 +0800 Subject: [PATCH] Enable/Disable output of compile commands for clang-tidy (#3214) Signed-off-by: quicksilver --- .clang-tidy | 2 +- core/CMakeLists.txt | 7 +++++++ core/build-support/run_clang_tidy.py | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 1695fa66..492260dd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -18,7 +18,7 @@ Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,google-*,modernize-*,readability-*' # produce HeaderFilterRegex from cpp/build-support/lint_exclusions.txt with: # echo -n '^('; sed -e 's/*/\.*/g' cpp/build-support/lint_exclusions.txt | tr '\n' '|'; echo ')$' -HeaderFilterRegex: '^(.*cmake-build-debug.*|.*cmake-build-release.*|.*cmake_build.*|.*src/core/thirdparty.*|.*thirdparty.*|.*easylogging++.*|.*SqliteMetaImpl.cpp|.*src/grpc.*|.*src/core.*|.*src/wrapper.*)$' +HeaderFilterRegex: '^(.*core/cmake-build-debug.*|.*core/cmake-build-release.*|.*core/cmake_build.*)$' AnalyzeTemporaryDtors: true ChainedConditionalReturn: 1 ChainedConditionalAssignment: 1 diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e441a906..c24eea0c 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -160,6 +160,13 @@ find_package( Python COMPONENTS Interpreter Development ) find_package( ClangTools ) set( BUILD_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/build-support" ) +if("$ENV{CMAKE_EXPORT_COMPILE_COMMANDS}" STREQUAL "1" OR CLANG_TIDY_FOUND) + # Generate a Clang compile_commands.json "compilation database" file for use + # with various development tools, such as Vim's YouCompleteMe plugin. + # See http://clang.llvm.org/docs/JSONCompilationDatabase.html + set(CMAKE_EXPORT_COMPILE_COMMANDS 1) +endif() + # # "make lint" target # diff --git a/core/build-support/run_clang_tidy.py b/core/build-support/run_clang_tidy.py index 6df17d53..788e7e09 100755 --- a/core/build-support/run_clang_tidy.py +++ b/core/build-support/run_clang_tidy.py @@ -57,7 +57,7 @@ def _check_all(cmd, filenames): if problem_files: msg = "clang-tidy suggested fixes for {}" print("\n".join(map(msg.format, problem_files))) - print(stdout) + print(stdout.decode("utf-8")) error = True except Exception: error = True @@ -123,4 +123,3 @@ if __name__ == "__main__": else: _check_all(cmd, linted_filenames) - -- GitLab