我还没有一个很好的答案,而我仍然感到惊讶的是这么手动,但我至少已经让 cpplint.py
和 clang-tidy
像这样工作:
cpplint
我向我的 src/BUILD
文件添加了这个目标(您需要根据需要配置 --filter
):
py_test(
name = "cpplint",
srcs = ["@google_styleguide//:cpplint/cpplint.py"],
data = [":all_cpp_files"],
args = ["--root=src", "--linelength=100", "--counting=detailed",
"--filter=..."] +
["src/%s" % f for f in glob(["**/*.cc", "**/*.h"])],
main = "cpplint.py",
python_version = "PY2",
)
@google_styleguide
工作区的定义如下:
new_git_repository(
name = "google_styleguide",
remote = "https://github.com/google/styleguide",
commit = "26470f9ccb354ff2f6d098f831271a1833701b28",
build_file = "@//:google_styleguide.BUILD",
)
clang-tidy
我创建了一个自定义的shell脚本,大致如下(您需要调整要启用/禁用的checks
):
execution_root=$(bazel info execution_root) || exit
clang-tidy \
-warnings-as-errors=* \
-header-filter=src/.* \
-checks="${checks}" \
"src/"*.cc \
-- \
-I "${execution_root}/external/googletest/googletest/include/" \
-I "${execution_root}/external/absl/" \
-I "${execution_root}/external/gsl/include/" \
-I .
读取时出错:无法为//:google_styleguide.BUILD加载软件包:在以下目录中找不到BUILD文件。将BUILD文件添加到目录中以将其标记为软件包。
- edc