diff --git a/.github/workflows/review-actions.yml b/.github/workflows/review-actions.yml new file mode 100644 index 00000000000..ae19d919fea --- /dev/null +++ b/.github/workflows/review-actions.yml @@ -0,0 +1,59 @@ +name: Auto Review Analyzers + +on: + push: + branches: + - main + paths-ignore: + # Do not trigger action when docs are updated. + - 'docs/**' + pull_request: + branches: + - main + +jobs: + clang-tidy: + runs-on: + labels: ubuntu-22.04-64core + + permissions: + # Open PR comments + pull-requests: write + # OPTIONAL: auto-closing conversations requires the `contents` permission + contents: write + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: Fetch base branch to compare to + run: | + git remote add review-base "https://github.com/${{ github.event.pull_request.base.repo.full_name }}" + git fetch --no-tags --no-recurse-submodules review-base "${{ github.event.pull_request.base.ref }}" + + - name: Restore Nightly Bazel Cache + uses: actions/cache/restore@v4 + with: + path: "~/.cache/bazel" + key: bazel-cache-nightly-${{ runner.os }}-${{ github.sha }} + restore-keys: bazel-cache-nightly-${{ runner.os }}- + + - name: Create compilation DB + run: | + xls/dev_tools/make-compilation-db.sh + + - name: Run clang-tidy on diff + run: | + mkdir clang-tidy-result + git diff -U1000 "$(git merge-base HEAD review-base/${{ github.event.pull_request.base.ref }})" | xls/dev_tools/run-clang-tidy-diff.sh -p1 -path build -export-fixes clang-tidy-result/fixes.yml + + - name: Run clang-tidy-pr-comments action + uses: hzeller/clang-tidy-pr-comments@master + with: + # Token to allow commenting + github_token: ${{ secrets.GITHUB_TOKEN }} + clang_tidy_fixes: clang-tidy-result/fixes.yml + request_changes: true + suggestions_per_comment: 10 diff --git a/xls/dev_tools/make-compilation-db.sh b/xls/dev_tools/make-compilation-db.sh index d65522e5bdd..8244405e730 100755 --- a/xls/dev_tools/make-compilation-db.sh +++ b/xls/dev_tools/make-compilation-db.sh @@ -19,7 +19,7 @@ set -e readonly OUTPUT_BASE="$(bazel info output_base)" readonly COMPDB_SCRIPT="${OUTPUT_BASE}/external/com_grail_bazel_compdb/generate.py" -[ -r "${COMPDB_SCRIPT}" ] || bazel fetch @com_grail_bazel_compdb//... +[ -r "${COMPDB_SCRIPT}" ] || bazel fetch --noshow_progress @com_grail_bazel_compdb//... python3 "${COMPDB_SCRIPT}" @@ -33,4 +33,3 @@ s/ -f[^ ]*/ /g # remove all -fxyz options s/ --target[^ ]*/ /g # target platform not needed, might confuse s/ -stdlib=libc++/ / # otherwise, clang-tidy does not find c++ headers EOF - diff --git a/xls/dev_tools/run-clang-tidy-diff.sh b/xls/dev_tools/run-clang-tidy-diff.sh new file mode 100755 index 00000000000..24e78f6ef41 --- /dev/null +++ b/xls/dev_tools/run-clang-tidy-diff.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Copyright 2023 The XLS Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Prepare compilation DB and run clang-tidy-diff that we already have +# bundled in our toolchain. +# Reads a unified diff from stdin. If a header is removed, we want to get +# enough context to see that it is not used anywhere; so invoke like +# +# git diff -U1000 | xls/dev_tools/run-clang-tidy-cached.sh -p1 + +CLANG_TIDY_LLVM_BASE="$(bazel info output_base)/external/llvm_toolchain_llvm/" + +"${CLANG_TIDY_LLVM_BASE}/share/clang/clang-tidy-diff.py" \ + -clang-tidy-binary="${CLANG_TIDY_LLVM_BASE}/bin/clang-tidy" "$@" diff --git a/xls/dslx/errors.cc b/xls/dslx/errors.cc index 78a9e3065e1..5a0b2021c5f 100644 --- a/xls/dslx/errors.cc +++ b/xls/dslx/errors.cc @@ -14,8 +14,8 @@ #include "xls/dslx/errors.h" -#include -#include +//#include testing +//#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" diff --git a/xls/ir/function_builder.cc b/xls/ir/function_builder.cc index bd3829257bd..6f46d909286 100644 --- a/xls/ir/function_builder.cc +++ b/xls/ir/function_builder.cc @@ -19,7 +19,7 @@ #include #include #include -#include +// #include // testing clang tidy #include #include #include