I don't have a great answer yet, and I'm still surprised it's this manual, but I have at least got cpplint.py
and clang-tidy
working, like so:
cpplint
I added this target to my src/BUILD
file (you'll want to configure --filter
as needed):
py_test(
name = "cpplint",
srcs = ["@google_styleguide//:cpplint/cpplint.py"],
data = [":all_cpp_files"],
# Not sure if there's a better way to express the paths to the src/ dir
# Drake uses the location oparator, but needs to jump through hoops to get the list of targets
args = ["--root=src", "--linelength=100", "--counting=detailed",
"--filter=..."] +
["src/%s" % f for f in glob(["**/*.cc", "**/*.h"])],
main = "cpplint.py",
python_version = "PY2",
)
The @google_styleguide
workspace is defined like so:
new_git_repository(
name = "google_styleguide",
remote = "https://github.com/google/styleguide",
commit = "26470f9ccb354ff2f6d098f831271a1833701b28",
build_file = "@//:google_styleguide.BUILD",
)
clang-tidy
I created a custom shell script that roughly looks like this (you'll need to tune which checks
you want to enable/disable):
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 .