From 21407a5ce0165d343c9fc192eac1765c4a245dfc Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Sat, 22 Aug 2020 17:44:57 +0800 Subject: [PATCH] enable clang-tidy check (#3396) * enable clang-tidy check Signed-off-by: yudong.cai * update run_clang_tidy.py Signed-off-by: yudong.cai * enable clang-tidy check Signed-off-by: yudong.cai * update run_clang_tidy.py Signed-off-by: yudong.cai * update run_clang_tidy.py Signed-off-by: yudong.cai * update run_clang_tidy.py Signed-off-by: yudong.cai * remove rule modernize-use-equals-default Signed-off-by: yudong.cai --- .clang-tidy | 2 +- ci/scripts/build.sh | 18 +++++++++++------- core/build-support/run_clang_tidy.py | 17 ++++++++++++++++- core/build.sh | 12 ++++++------ core/src/db/wal/WalOperationCodec.cpp | 2 +- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 88e28ad1..0ffc8c2d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,7 +20,7 @@ Checks: > -*, clang-diagnostic-*, -clang-diagnostic-error, clang-analyzer-*, -clang-analyzer-alpha*, google-*, -google-runtime-references, -google-readability-todo, - modernize-*, -modernize-pass-by-value + modernize-*, -modernize-pass-by-value, -modernize-use-equals-default # produce HeaderFilterRegex from core/build-support/lint_exclusions.txt with: # echo -n '^?!('; sed -e 's/*/\.*/g' core/build-support/lint_exclusions.txt | tr '\n' '|'; echo ')$' diff --git a/ci/scripts/build.sh b/ci/scripts/build.sh index fc33828a..c212a417 100755 --- a/ci/scripts/build.sh +++ b/ci/scripts/build.sh @@ -161,13 +161,17 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then echo "clang-format check passed!" # clang-tidy check -# make check-clang-tidy -# if [ $? -ne 0 ]; then -# echo "ERROR! clang-tidy check failed" -# rm -f CMakeCache.txt -# exit 1 -# fi -# echo "clang-tidy check passed!" + if [[ ${GPU_VERSION} == "ON" ]]; then + make check-clang-tidy + if [ $? -ne 0 ]; then + echo "ERROR! clang-tidy check failed" + rm -f CMakeCache.txt + exit 1 + fi + echo "clang-tidy check passed!" + else + echo "CPU version skip clang-tidy check!" + fi fi if [[ ${COMPILE_BUILD} == "ON" ]];then diff --git a/core/build-support/run_clang_tidy.py b/core/build-support/run_clang_tidy.py index 788e7e09..9db1ece7 100755 --- a/core/build-support/run_clang_tidy.py +++ b/core/build-support/run_clang_tidy.py @@ -23,12 +23,16 @@ import lintutils from subprocess import PIPE import sys from functools import partial +import re def _get_chunk_key(filenames): # lists are not hashable so key on the first filename in a chunk return filenames[0] +def _count_key(str, key): + m = re.findall(key, str) + return len(m) # clang-tidy outputs complaints in '/path:line_number: complaint' format, # so we can scan its output to get a list of files to fix @@ -51,14 +55,25 @@ def _check_all(cmd, filenames): } checker = partial(_check_some_files, completed_processes) pool = mp.Pool() + error = False try: + cnt_error = 0 + cnt_warning = 0 + cnt_ignore = 0 # check output of completed clang-tidy invocations in parallel for problem_files, stdout in pool.imap(checker, chunks): if problem_files: msg = "clang-tidy suggested fixes for {}" print("\n".join(map(msg.format, problem_files))) print(stdout.decode("utf-8")) - error = True + # ignore thirdparty header file not found issue, such as: + # error: 'fiu.h' file not found [clang-diagnostic-error] + cnt_error += _count_key(stdout, "error:") + cnt_warning += _count_key(stdout, "warning:") + cnt_ignore += _count_key(stdout, "clang-diagnostic-error") + print("clang-tidy - error: {}, warning: {}, ignore {}". + format(cnt_error, cnt_warning, cnt_ignore)) + error = error or (cnt_error > cnt_ignore or cnt_warning > 0) except Exception: error = True raise diff --git a/core/build.sh b/core/build.sh index ba18c1a9..4417ca5f 100755 --- a/core/build.sh +++ b/core/build.sh @@ -144,12 +144,12 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then echo "clang-format check passed!" # clang-tidy check -# make check-clang-tidy -# if [ $? -ne 0 ]; then -# echo "ERROR! clang-tidy check failed" -# exit 1 -# fi -# echo "clang-tidy check passed!" + make check-clang-tidy + if [ $? -ne 0 ]; then + echo "ERROR! clang-tidy check failed" + exit 1 + fi + echo "clang-tidy check passed!" else # compile and build make -j ${jobs} install || exit 1 diff --git a/core/src/db/wal/WalOperationCodec.cpp b/core/src/db/wal/WalOperationCodec.cpp index 11e2b193..c1c3a408 100644 --- a/core/src/db/wal/WalOperationCodec.cpp +++ b/core/src/db/wal/WalOperationCodec.cpp @@ -189,7 +189,7 @@ WalOperationCodec::IterateOperation(const WalFilePtr& file, WalOperationPtr& ope // read partition name int32_t part_name_length = 0; std::string partition_name; - read_bytes = file->Read(&part_name_length); + file->Read(&part_name_length); if (part_name_length > 0) { read_bytes = file->ReadStr(partition_name, part_name_length); if (read_bytes <= 0) { -- GitLab