Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
4c944e1b
M
milvus
项目概览
milvus
/
milvus
12 个月 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4c944e1b
编写于
9月 20, 2019
作者:
T
test
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MS-575 Add Clang-format & Clang-tidy & Cpplint
Former-commit-id: f72da7918b3696f906d0f3a2ef8590b6bd16d3d2
上级
7f121170
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
168 addition
and
0 deletion
+168
-0
cpp/CMakeLists.txt
cpp/CMakeLists.txt
+41
-0
cpp/build-support/run_clang_tidy.py
cpp/build-support/run_clang_tidy.py
+126
-0
cpp/build.sh
cpp/build.sh
+1
-0
未找到文件。
cpp/CMakeLists.txt
浏览文件 @
4c944e1b
...
...
@@ -45,6 +45,13 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]" MILVUS_VERSION "${MILVUS_VERSION}")
set
(
CLANG_FORMAT_VERSION
"6.0"
)
find_package
(
ClangTools
)
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
()
set
(
BUILD_SUPPORT_DIR
"
${
CMAKE_SOURCE_DIR
}
/build-support"
)
if
(
CMAKE_BUILD_TYPE STREQUAL
"Release"
)
...
...
@@ -203,3 +210,37 @@ if(${CLANG_FORMAT_FOUND})
${
MILVUS_LINT_QUIET
}
)
endif
()
#
# "make clang-tidy" and "make check-clang-tidy" targets
#
if
(
${
CLANG_TIDY_FOUND
}
)
# runs clang-tidy and attempts to fix any warning automatically
add_custom_target
(
clang-tidy
${
PYTHON_EXECUTABLE
}
${
BUILD_SUPPORT_DIR
}
/run_clang_tidy.py
--clang_tidy_binary
${
CLANG_TIDY_BIN
}
--exclude_globs
${
LINT_EXCLUSIONS_FILE
}
--compile_commands
${
CMAKE_BINARY_DIR
}
/compile_commands.json
--source_dir
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
--fix
${
MILVUS_LINT_QUIET
}
)
# runs clang-tidy and exits with a non-zero exit code if any errors are found.
add_custom_target
(
check-clang-tidy
${
PYTHON_EXECUTABLE
}
${
BUILD_SUPPORT_DIR
}
/run_clang_tidy.py
--clang_tidy_binary
${
CLANG_TIDY_BIN
}
--exclude_globs
${
LINT_EXCLUSIONS_FILE
}
--compile_commands
${
CMAKE_BINARY_DIR
}
/compile_commands.json
--source_dir
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
${
MILVUS_LINT_QUIET
}
)
endif
()
cpp/build-support/run_clang_tidy.py
0 → 100755
浏览文件 @
4c944e1b
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from
__future__
import
print_function
import
argparse
import
multiprocessing
as
mp
import
lintutils
from
subprocess
import
PIPE
import
sys
from
functools
import
partial
def
_get_chunk_key
(
filenames
):
# lists are not hashable so key on the first filename in a chunk
return
filenames
[
0
]
# clang-tidy outputs complaints in '/path:line_number: complaint' format,
# so we can scan its output to get a list of files to fix
def
_check_some_files
(
completed_processes
,
filenames
):
result
=
completed_processes
[
_get_chunk_key
(
filenames
)]
return
lintutils
.
stdout_pathcolonline
(
result
,
filenames
)
def
_check_all
(
cmd
,
filenames
):
# each clang-tidy instance will process 16 files
chunks
=
lintutils
.
chunk
(
filenames
,
16
)
cmds
=
[
cmd
+
some
for
some
in
chunks
]
results
=
lintutils
.
run_parallel
(
cmds
,
stderr
=
PIPE
,
stdout
=
PIPE
)
error
=
False
# record completed processes (keyed by the first filename in the input
# chunk) for lookup in _check_some_files
completed_processes
=
{
_get_chunk_key
(
some
):
result
for
some
,
result
in
zip
(
chunks
,
results
)
}
checker
=
partial
(
_check_some_files
,
completed_processes
)
pool
=
mp
.
Pool
()
try
:
# 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
)
error
=
True
except
Exception
:
error
=
True
raise
finally
:
pool
.
terminate
()
pool
.
join
()
if
error
:
sys
.
exit
(
1
)
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"Runs clang-tidy on all "
)
parser
.
add_argument
(
"--clang_tidy_binary"
,
required
=
True
,
help
=
"Path to the clang-tidy binary"
)
parser
.
add_argument
(
"--exclude_globs"
,
help
=
"Filename containing globs for files "
"that should be excluded from the checks"
)
parser
.
add_argument
(
"--compile_commands"
,
required
=
True
,
help
=
"compile_commands.json to pass clang-tidy"
)
parser
.
add_argument
(
"--source_dir"
,
required
=
True
,
help
=
"Root directory of the source code"
)
parser
.
add_argument
(
"--fix"
,
default
=
False
,
action
=
"store_true"
,
help
=
"If specified, will attempt to fix the "
"source code instead of recommending fixes, "
"defaults to %(default)s"
)
parser
.
add_argument
(
"--quiet"
,
default
=
False
,
action
=
"store_true"
,
help
=
"If specified, only print errors"
)
arguments
=
parser
.
parse_args
()
exclude_globs
=
[]
if
arguments
.
exclude_globs
:
for
line
in
open
(
arguments
.
exclude_globs
):
exclude_globs
.
append
(
line
.
strip
())
linted_filenames
=
[]
for
path
in
lintutils
.
get_sources
(
arguments
.
source_dir
,
exclude_globs
):
linted_filenames
.
append
(
path
)
if
not
arguments
.
quiet
:
msg
=
'Tidying {}'
if
arguments
.
fix
else
'Checking {}'
print
(
"
\n
"
.
join
(
map
(
msg
.
format
,
linted_filenames
)))
cmd
=
[
arguments
.
clang_tidy_binary
,
'-p'
,
arguments
.
compile_commands
]
if
arguments
.
fix
:
cmd
.
append
(
'-fix'
)
results
=
lintutils
.
run_parallel
(
[
cmd
+
some
for
some
in
lintutils
.
chunk
(
linted_filenames
,
16
)])
for
returncode
,
stdout
,
stderr
in
results
:
if
returncode
!=
0
:
sys
.
exit
(
returncode
)
else
:
_check_all
(
cmd
,
linted_filenames
)
cpp/build.sh
浏览文件 @
4c944e1b
...
...
@@ -89,6 +89,7 @@ if [[ ${MAKE_CLEAN} == "ON" ]]; then
-DMILVUS_ENABLE_PROFILING=
${
PROFILING
}
\
-DBUILD_FAISS_WITH_MKL=
${
BUILD_FAISS_WITH_MKL
}
\
-DUSE_JFROG_CACHE=
${
USE_JFROG_CACHE
}
\
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
../"
echo
${
CMAKE_CMD
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录