Skip to content

Commit

Permalink
Add a clang-tidy check for analyzer tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Apr 7, 2024
1 parent cda40c6 commit 6eb23dc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run clang-tidy
on:
push:
paths:
- '**.c'
- '**.h'
pull_request:

jobs:
analyze:
runs-on: ubuntu-latest

name: Install clang-tidy
steps:
- uses: actions/checkout@v3
- name: Install clang-tidy
run: |
sudo apt install clang-tidy
- name: Build
run: |
mkdir build && cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=1
sudo cmake --build . --config Release
cd ..
- name: Check for warnings
run: |
./run-clang-tidy.sh build
30 changes: 30 additions & 0 deletions run-clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

if [ $# -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 <build-path>"
exit 1
fi

BUILD_PATH="$1"

clang-tidy $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks=clang-analyzer-*,-clang-analyzer-cplusplus* | tee ct-warnings.txt

tmp=$(mktemp)
grep ": warning" ct-warnings.txt | grep -oE "^[/a-zA-Z0-9]*\.[ch]" | sort | uniq > $tmp
top_level=$(git rev-parse --show-toplevel)

echo "\n\n###### REPORT\n\n"

for modified in $(git diff --name-only origin/next); do
full_path="$top_level/$modified"
if grep -q "$full_path" $tmp; then
echo "$full_path as warnings. Please fix them."
needs_fixes=1
fi
done

if [ -z $needs_fixes ]; then
echo "All good"
exit 0
fi
exit 1

0 comments on commit 6eb23dc

Please sign in to comment.