From 8d3d08fdf76b06ebd7da820ee26484e20653bff3 Mon Sep 17 00:00:00 2001 From: John Demme Date: Thu, 8 Oct 2020 13:52:58 -0700 Subject: [PATCH] Adds clang-tidy to the workflow (#128) --- .clang-tidy | 19 ++++++++++++ .github/workflows/buildAndTest.yml | 49 +++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000000..38939668adb8 --- /dev/null +++ b/.clang-tidy @@ -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 diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index e4efb648348c..a1a9598fdc71 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -43,6 +43,10 @@ jobs: with: fetch-depth: 2 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 id: get-llvm-hash 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 make check-circt -j$(nproc) - - name: clang-format + - name: choose-commit + if: ${{ always() }} env: PR_BASE: ${{ github.event.pull_request.base.sha }} run: | @@ -84,26 +89,56 @@ jobs: else DIFF_COMMIT="$PR_BASE" fi + echo "DIFF_COMMIT=$DIFF_COMMIT" >> $GITHUB_ENV + - name: clang-format + if: ${{ always() }} + run: | + # Run clang-format git clang-format-9 $DIFF_COMMIT git diff --ignore-submodules > clang-format.patch if [ -s clang-format.patch ]; then 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 checkout . exit 1 fi echo "Clang-format found no formatting problems" 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 continue-on-error: true if: ${{ failure() }} with: - name: clang-format-patch - path: clang-format.patch + name: clang-format-tidy-patches + path: clang-*.patch # 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() }} continue-on-error: true run: | - # Display patch - cat clang-format.patch + # Display patches + 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