Skip to content

Commit 2fbf917

Browse files
committed
clang-tidy in .bazelrc and a github workflow
References: - https://github.com/erenon/bazel_clang_tidy - https://clang.llvm.org/extra/clang-tidy/ Run locally with ``` bazel build //cuttlefish/... --config clang-tidy ``` The `clang-diagnostic-pragma-once-outside-header` check is disabled as bazel's `parse_headers` feature tries to compile every header as a source file. We could re-enable that check if we switch to an include guard system, which would also better satisfy the style guide: https://google.github.io/styleguide/cppguide.html#The__define_Guard All default checks have warnings converted to errors, as bazel seemed to be consuming all warning output. Checks that we are currently failing have been explicitly allow-listed.
1 parent 3bbc9fc commit 2fbf917

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

.github/workflows/presubmit.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- name: Setup apt
5858
run: apt update -y && apt upgrade -y
5959
- name: Install dependencies
60-
run: apt install -y git clang libcurl4-openssl-dev
60+
run: apt install -y git clang libcurl4-openssl-dev clang-tidy
6161
- name: Install bazel
6262
run: bash tools/buildutils/installbazel.sh
6363
- name: Build cvd
@@ -69,6 +69,8 @@ jobs:
6969
with:
7070
name: testlogs
7171
path: bazel-testlogs
72+
- name: Run clang-tidy
73+
run: cd base/cvd && bazel build //cuttlefish/... --config clang-tidy
7274
e2e-tests-orchestration:
7375
runs-on: ubuntu-22.04
7476
steps:

base/cvd/.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
build --copt=-fdiagnostics-color=always
22
build --repo_env=CC=clang
3+
4+
build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
5+
build:clang-tidy --output_groups=report
6+
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config

base/cvd/.clang-tidy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Bad interaction with the `parse_headers` bazel feature
2+
Checks: '-clang-diagnostic-pragma-once-outside-header'
3+
4+
# Using the bazel clang-tidy helper, warnings seem to be ignored entirely.
5+
# Default warnings are converted to errors here for visibility.
6+
WarningsAsErrors: >
7+
clang-analyzer-*,
8+
-clang-analyzer-core.uninitialized.Assign,
9+
-clang-analyzer-core.UndefinedBinaryOperatorResult,
10+
-clang-analyzer-deadcode.DeadStores,
11+
clang-diagnostic-*,
12+
-clang-diagnostic-inconsistent-missing-override,
13+
-clang-diagnostic-pragma-once-outside-header,
14+
-clang-diagnostic-unneeded-internal-declaration,
15+
-clang-diagnostic-unused-const-variable,
16+
-clang-diagnostic-unused-private-field,
17+
-clang-diagnostic-unused-variable,

base/cvd/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ genrule(
88
outs = ["build/version.h"],
99
cmd = "sed -e \"s|@VCS_TAG@|`git describe`|\" $< > $@",
1010
)
11+
12+
filegroup(
13+
name = "clang_tidy_config",
14+
srcs = [".clang-tidy"],
15+
visibility = ["//visibility:public"],
16+
)

base/cvd/MODULE.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ git_override(
2424
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
2525
# Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main).
2626
)
27+
28+
# clang-tidy
29+
# https://github.com/erenon/bazel_clang_tidy
30+
bazel_dep(name = "bazel_clang_tidy", dev_dependency = True)
31+
git_override(
32+
module_name = "bazel_clang_tidy",
33+
commit = "f23d924918c581c68cd5cda5f12b4f8198ac0c35",
34+
remote = "https://github.com/erenon/bazel_clang_tidy.git",
35+
)

0 commit comments

Comments
 (0)