未验证 提交 21407a5c 编写于 作者: C Cai Yudong 提交者: GitHub

enable clang-tidy check (#3396)

* enable clang-tidy check
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* update run_clang_tidy.py
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* enable clang-tidy check
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* update run_clang_tidy.py
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* update run_clang_tidy.py
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* update run_clang_tidy.py
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* remove rule modernize-use-equals-default
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>
上级 c66e40cc
...@@ -20,7 +20,7 @@ Checks: > ...@@ -20,7 +20,7 @@ Checks: >
-*, clang-diagnostic-*, -clang-diagnostic-error, -*, clang-diagnostic-*, -clang-diagnostic-error,
clang-analyzer-*, -clang-analyzer-alpha*, clang-analyzer-*, -clang-analyzer-alpha*,
google-*, -google-runtime-references, -google-readability-todo, 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: # 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 ')$' # echo -n '^?!('; sed -e 's/*/\.*/g' core/build-support/lint_exclusions.txt | tr '\n' '|'; echo ')$'
......
...@@ -161,13 +161,17 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then ...@@ -161,13 +161,17 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then
echo "clang-format check passed!" echo "clang-format check passed!"
# clang-tidy check # clang-tidy check
# make check-clang-tidy if [[ ${GPU_VERSION} == "ON" ]]; then
# if [ $? -ne 0 ]; then make check-clang-tidy
# echo "ERROR! clang-tidy check failed" if [ $? -ne 0 ]; then
# rm -f CMakeCache.txt echo "ERROR! clang-tidy check failed"
# exit 1 rm -f CMakeCache.txt
# fi exit 1
# echo "clang-tidy check passed!" fi
echo "clang-tidy check passed!"
else
echo "CPU version skip clang-tidy check!"
fi
fi fi
if [[ ${COMPILE_BUILD} == "ON" ]];then if [[ ${COMPILE_BUILD} == "ON" ]];then
......
...@@ -23,12 +23,16 @@ import lintutils ...@@ -23,12 +23,16 @@ import lintutils
from subprocess import PIPE from subprocess import PIPE
import sys import sys
from functools import partial from functools import partial
import re
def _get_chunk_key(filenames): def _get_chunk_key(filenames):
# lists are not hashable so key on the first filename in a chunk # lists are not hashable so key on the first filename in a chunk
return filenames[0] 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, # clang-tidy outputs complaints in '/path:line_number: complaint' format,
# so we can scan its output to get a list of files to fix # so we can scan its output to get a list of files to fix
...@@ -51,14 +55,25 @@ def _check_all(cmd, filenames): ...@@ -51,14 +55,25 @@ def _check_all(cmd, filenames):
} }
checker = partial(_check_some_files, completed_processes) checker = partial(_check_some_files, completed_processes)
pool = mp.Pool() pool = mp.Pool()
error = False
try: try:
cnt_error = 0
cnt_warning = 0
cnt_ignore = 0
# check output of completed clang-tidy invocations in parallel # check output of completed clang-tidy invocations in parallel
for problem_files, stdout in pool.imap(checker, chunks): for problem_files, stdout in pool.imap(checker, chunks):
if problem_files: if problem_files:
msg = "clang-tidy suggested fixes for {}" msg = "clang-tidy suggested fixes for {}"
print("\n".join(map(msg.format, problem_files))) print("\n".join(map(msg.format, problem_files)))
print(stdout.decode("utf-8")) 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: except Exception:
error = True error = True
raise raise
......
...@@ -144,12 +144,12 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then ...@@ -144,12 +144,12 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then
echo "clang-format check passed!" echo "clang-format check passed!"
# clang-tidy check # clang-tidy check
# make check-clang-tidy make check-clang-tidy
# if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# echo "ERROR! clang-tidy check failed" echo "ERROR! clang-tidy check failed"
# exit 1 exit 1
# fi fi
# echo "clang-tidy check passed!" echo "clang-tidy check passed!"
else else
# compile and build # compile and build
make -j ${jobs} install || exit 1 make -j ${jobs} install || exit 1
......
...@@ -189,7 +189,7 @@ WalOperationCodec::IterateOperation(const WalFilePtr& file, WalOperationPtr& ope ...@@ -189,7 +189,7 @@ WalOperationCodec::IterateOperation(const WalFilePtr& file, WalOperationPtr& ope
// read partition name // read partition name
int32_t part_name_length = 0; int32_t part_name_length = 0;
std::string partition_name; std::string partition_name;
read_bytes = file->Read<int32_t>(&part_name_length); file->Read<int32_t>(&part_name_length);
if (part_name_length > 0) { if (part_name_length > 0) {
read_bytes = file->ReadStr(partition_name, part_name_length); read_bytes = file->ReadStr(partition_name, part_name_length);
if (read_bytes <= 0) { if (read_bytes <= 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册