Skip to content

Commit ab3bc7a

Browse files
author
tsl
committed
adds clang-tidy lint
1 parent c2af5f5 commit ab3bc7a

File tree

6 files changed

+69
-4
lines changed

6 files changed

+69
-4
lines changed

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
build --cxxopt='-std=c++17' --compilation_mode=opt
1+
build --cxxopt='-std=c++17' --compilation_mode=opt --repo_env=CC=clang-10 --repo_env=CXX=clang++-10

.github/workflows/bazel.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ jobs:
1717
runs-on: ubuntu-latest
1818

1919
steps:
20-
- uses: actions/checkout@v1
20+
- name: Install clang
21+
run: |
22+
sudo apt install clang-10
23+
24+
- name: Checkout
25+
uses: actions/checkout@v1
2126

2227
- name: Mount bazel cache
2328
uses: actions/cache@v1
@@ -39,3 +44,7 @@ jobs:
3944
- name: Test
4045
run: |
4146
"${GITHUB_WORKSPACE}/bin/bazel" test --test_output=errors //painty/...
47+
48+
# - name: Lint
49+
# run: |
50+
# ./tools/lint-clang-tidy.sh

WORKSPACE.bazel

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ http_archive(
4747
strip_prefix = "eigen-3.3.7-patched",
4848
# urls = ["https://gitlab.com/thomas.lindemeier/eigen/-/archive/3.3.7-patched/eigen-3.3.7-patched.tar.gz"],
4949
# usually the urls above should be used. However, bazel is not able to download from gitlab and I therefore use an url to a copy of the archive for now.
50-
urls =["https://gist.github.com/lindemeier/e1c3506ea6b0e20a6b08d1ac142c8380/raw/ca1779dbb9964a5df4f950bfebd5833ad7f79528/eigen-3.3.7-patched.tar.gz"]
50+
urls =["https://gist.github.com/lindemeier/e1c3506ea6b0e20a6b08d1ac142c8380/raw/ca1779dbb9964a5df4f950bfebd5833ad7f79528/eigen-3.3.7-patched.tar.gz"],
51+
sha256 = "0be9ab513cd911d55a15b80b67c8ffa7f8168b00bbd8c1cd9359b3081b2df8c1"
5152
)
5253

5354
# OpenCV source release
5455
http_archive(
5556
name = "opencv",
5657
build_file_content = all_content,
5758
strip_prefix = "opencv-4.4.0",
59+
sha256 = "7faa0991c74cda52313ee37ef73f3e451332a47e7aa36c2bb2240b69f5002d27",
5860
urls = ["https://github.com/opencv/opencv/archive/4.4.0.zip"],
5961
)
6062

@@ -64,3 +66,11 @@ git_repository(
6466
remote = "https://github.com/google/googletest",
6567
branch = "v1.10.x",
6668
)
69+
70+
# dependency for generating compilation database
71+
http_archive(
72+
name = "com_grail_bazel_compdb",
73+
strip_prefix = "bazel-compilation-database-0.4.5",
74+
urls = ["https://github.com/grailbio/bazel-compilation-database/archive/0.4.5.tar.gz"],
75+
sha256 = "bcecfd622c4ef272fd4ba42726a52e140b961c4eac23025f18b346c968a8cfb4"
76+
)

painty.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
painty_copts = ["-Wall", "-Werror"]
1+
# gcc
2+
# painty_copts = ["-Wall", "-Werror"]
3+
#
4+
painty_copts = ["-Wall", "-Werror", "-Weverything", "-Wno-c++98-compat", "-Wno-padded", "-Wno-documentation", "-Wno-global-constructors"]
25

36
def painty_cc_library(
47
name,

painty/BUILD.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("@com_grail_bazel_compdb//:aspects.bzl", "compilation_database")
2+
3+
compilation_database(
4+
name = "painty_comdb",
5+
targets = [
6+
"//painty/core:painty_core",
7+
"//painty/image:painty_image",
8+
"//painty/io:painty_io",
9+
"//painty/renderer:painty_renderer"
10+
],
11+
# [Optional]
12+
# If your exec root (value returned by `bazel info execution_root`)
13+
# is constant across your users, then you can supply the value here.
14+
# Otherwise, the default is `__EXEC_ROOT__` which you can replace in
15+
# the output file using `sed` or similar tool (see below).
16+
exec_root = "__EXEC_ROOT__",
17+
)

tools/lint-clang-tidy.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
workspace_dir=$(bazel info workspace)
4+
5+
cd $workspace_dir
6+
7+
# generate compile_commands.json
8+
bazel build //painty:painty_comdb
9+
10+
# get the compile_commands.json
11+
compile_commands_outfile="$(bazel info bazel-bin)/painty/compile_commands.json"
12+
echo "Compilation database in "$compile_commands_outfile" is ready."
13+
14+
# post process the compilation commands file.
15+
# __EXEC_ROOT__ needs to be replaced with the directory containing the sources.
16+
sed -i -- "s|__EXEC_ROOT__|$workspace_dir|g" $compile_commands_outfile
17+
18+
if [ -z "${CLANG_TIDY:=$(which clang-tidy)}" ]; then
19+
echo "Unable to find clang-tidy" 1>&2
20+
exit 1
21+
fi
22+
23+
# get all relevant files and let clang-tidy process those
24+
find $workspace_dir/painty -regex '.*\.\(cpp\|h\|hpp\|cc\|cxx\)' -exec $CLANG_TIDY -p $compile_commands_outfile -fix -fix-errors -extra-arg=-std=c++17 -extra-arg=-isystem -extra-arg=-I$workspace_dir {} \;
25+
26+
exit 0

0 commit comments

Comments
 (0)