Adds clang-tidy to the workflow (#128)

This commit is contained in:
John Demme 2020-10-08 13:52:58 -07:00 committed by GitHub
parent 2d82d657fe
commit 8d3d08fdf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 7 deletions

19
.clang-tidy Normal file
View File

@ -0,0 +1,19 @@
# Copy of llvm-project/mlir/.clang-tidy
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,readability-identifier-naming'
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.MemberCase
value: camelBack
- key: readability-identifier-naming.ParameterCase
value: camelBack
- key: readability-identifier-naming.UnionCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: camelBack
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 1

View File

@ -43,6 +43,10 @@ jobs:
with: with:
fetch-depth: 2 fetch-depth: 2
submodules: 'true' submodules: 'true'
- name: Install clang-tidy
run: |
sudo apt-get install -y clang-tidy-9
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-9 100
- name: Get LLVM Hash - name: Get LLVM Hash
id: get-llvm-hash id: get-llvm-hash
run: echo "::set-output name=hash::$(git rev-parse @:./llvm)" run: echo "::set-output name=hash::$(git rev-parse @:./llvm)"
@ -74,7 +78,8 @@ jobs:
cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF -DMLIR_DIR=../llvm/install/lib/cmake/mlir/ -DLLVM_DIR=../llvm/install/lib/cmake/llvm/ -DCMAKE_LINKER=lld -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build/bin/llvm-lit cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF -DMLIR_DIR=../llvm/install/lib/cmake/mlir/ -DLLVM_DIR=../llvm/install/lib/cmake/llvm/ -DCMAKE_LINKER=lld -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build/bin/llvm-lit
make check-circt -j$(nproc) make check-circt -j$(nproc)
- name: clang-format - name: choose-commit
if: ${{ always() }}
env: env:
PR_BASE: ${{ github.event.pull_request.base.sha }} PR_BASE: ${{ github.event.pull_request.base.sha }}
run: | run: |
@ -84,26 +89,56 @@ jobs:
else else
DIFF_COMMIT="$PR_BASE" DIFF_COMMIT="$PR_BASE"
fi fi
echo "DIFF_COMMIT=$DIFF_COMMIT" >> $GITHUB_ENV
- name: clang-format
if: ${{ always() }}
run: |
# Run clang-format
git clang-format-9 $DIFF_COMMIT git clang-format-9 $DIFF_COMMIT
git diff --ignore-submodules > clang-format.patch git diff --ignore-submodules > clang-format.patch
if [ -s clang-format.patch ]; then if [ -s clang-format.patch ]; then
echo "Clang-format found formatting problems in the following files. See diff in the clang-format.patch artifact." echo "Clang-format found formatting problems in the following files. See diff in the clang-format.patch artifact."
git diff --ignore-submodules --name-only git diff --ignore-submodules --name-only
git checkout .
exit 1 exit 1
fi fi
echo "Clang-format found no formatting problems" echo "Clang-format found no formatting problems"
exit 0 exit 0
- name: Upload clang-format patch - name: clang-tidy
if: ${{ always() }}
run: |
git diff -U0 $DIFF_COMMIT | clang-tidy-diff-9.py -path build -p1 -fix
git diff --ignore-submodules > clang-tidy.patch
if [ -s clang-tidy.patch ]; then
echo "Clang-tidy problems in the following files. See diff in the clang-tidy.patch artifact."
git diff --ignore-submodules --name-only
git checkout .
exit 1
fi
echo "Clang-tidy found no problems"
exit 0
- name: Upload format and tidy patches
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
continue-on-error: true continue-on-error: true
if: ${{ failure() }} if: ${{ failure() }}
with: with:
name: clang-format-patch name: clang-format-tidy-patches
path: clang-format.patch path: clang-*.patch
# Unfortunately, artifact uploads are always zips so display the diff as well # Unfortunately, artifact uploads are always zips so display the diff as well
- name: clang-format patch display - name: clang format and tidy patches display
if: ${{ failure() }} if: ${{ failure() }}
continue-on-error: true continue-on-error: true
run: | run: |
# Display patch # Display patches
cat clang-format.patch if [ ! -z clang-format.patch ]; then
echo "Clang-format patch"
echo "================"
cat clang-format.patch
echo "================"
end
if [ ! -z clang-tidy.patch ]; then
echo "Clang-tidy patch"
echo "================"
cat clang-tidy.patch
echo "================"
end