Skip to content

Commit

Permalink
Run clang tidy on diff with CI
Browse files Browse the repository at this point in the history
Added a script for CI execution. This script is not intended for local
user execution due to the following reasons:

1. `clang-tidy-diff.py` supports exit with a failure code when there are
   errors from version 17 onward. (The exact version is uncertain. For
   more details, please refer to
   llvm/llvm-project#65000.)
2. `bear` has different command line interfaces between version <= 2.4.x
    and onward. (For more details, please refer to
    https://github.com/rizsotto/Bear?tab=readme-ov-file#how-to-use.)

The script may not work if any of these issues occur.
In the CI environment, we ensure that the versions of these dependencies
are new enough.
  • Loading branch information
Lai-YT committed Feb 22, 2024
1 parent 1d94f7c commit bf8ca05
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
run: |
sudo apt-get install -q -y clang-format
scripts/check-format.sh
- name: static checks
run: |
sudo apt-get install -q -y bear clang-tidy-17
scripts/check-tidy.sh
test:
runs-on: ubuntu-22.04
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ venv.bak/

# VS Code configs
.vscode

# Compilation database
compile_commands.json
30 changes: 30 additions & 0 deletions scripts/check-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env sh

#
# Runs clang-tidy-diff.py on the diff between main and HEAD.
#

set -eu

command -v bear >/dev/null 2>&1 || (
echo "error: bear is required to generate compile_commands.json; see https://github.com/rizsotto/Bear"
exit 1
)

# number of jobs to run
NPROCS=1
# Find available processor numbers based on different OS.
OS="$(uname -s)"
case $OS in
'Linux')
NPROCS="$(grep -c ^processor /proc/cpuinfo)"
;;
'Darwin')
NPROCS="$(sysctl -n hw.ncpu)"
;;
esac

# Run a clean build to generate compile_commands.json.
make clean
bear make -j"${NPROCS}"
git diff -U0 main..HEAD | clang-tidy-diff -p1 -j"${NPROCS}"

0 comments on commit bf8ca05

Please sign in to comment.