fix clang-tidy #3168
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [assigned, opened, synchronize, reopened] | |
workflow_dispatch: | |
defaults: | |
run: | |
# This is already the default, except when running inside another Docker | |
# image, which is the case here. So set it up globally to avoid | |
# repeating elsewhere. | |
shell: bash | |
env: | |
# Run apt package manager in the CI in non-interactive mode. | |
# Otherwise, on Ubuntu 20.04 the installation of tzdata asking question | |
DEBIAN_FRONTEND: noninteractive | |
jobs: | |
build-repo: | |
name: Build and Test | |
# By latest GitHub means actually latest LTS only | |
runs-on: ubuntu-latest | |
strategy: | |
# Run all the test even if there are some which fail | |
fail-fast: false | |
# Run the tests on the Cartesian product of the following | |
matrix: | |
build_type: [ Assert, Release ] | |
ubuntu_version: [ 20.04, 22.04 ] | |
steps: | |
# Clone the repo and its submodules. Do shallow clone to save clone | |
# time. | |
- name: Get the project repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
submodules: "true" | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install Python packages | |
run: | | |
pip install cmake numpy psutil pybind11 rich pkginfo lit PyYAML | |
- name: Install Ninja | |
run: sudo apt-get install -y ninja-build | |
- name: Install lld and clang (for aiecc) | |
run: sudo apt-get install -y clang lld | |
- name: Get MLIR | |
id: mlir-wheels | |
run: | | |
pip -q download mlir -f https://github.com/Xilinx/mlir-aie/releases/expanded_assets/mlir-distro && unzip -q mlir-*.whl | |
WHL=$(ls mlir-*.whl) | |
echo "MLIR_WHEEL_VERSION=$(python -c "import pkginfo; w = pkginfo.Wheel('$WHL'); print(w.version.split('+')[0] + '+' + w.version.split('+')[1].rsplit('.', 1)[-1])")" | tee -a $GITHUB_OUTPUT | |
echo "MLIR_DIR=$PWD/mlir" | tee -a $GITHUB_OUTPUT | |
- name: Ccache for C++ compilation | |
# https://github.com/hendrikmuhs/ccache-action/releases/tag/v1.2.9 | |
uses: hendrikmuhs/ccache-action@ca3acd2731eef11f1572ccb126356c2f9298d35e | |
with: | |
# Since there are now several compilation jobs running in parallel, | |
# use a different key per job to avoid a ccache writing race condition | |
key: ${{ matrix.build_type }}-${{ runner.os }}-${{ matrix.ubuntu_version }}-${{ steps.mlir-wheels.outputs.MLIR_WHEEL_VERSION }} | |
max-size: 1G | |
# Build the repo test target in debug mode to build and test. | |
- name: Build and test (Assert) | |
if: matrix.build_type == 'Assert' | |
run: | | |
mkdir build_assert | |
cd build_assert | |
cmake .. \ | |
-GNinja \ | |
-DCMAKE_BUILD_TYPE=Debug \ | |
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \ | |
-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON \ | |
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \ | |
-DCMAKE_C_VISIBILITY_PRESET=hidden \ | |
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \ | |
-DAIE_COMPILER=NONE \ | |
-DAIE_LINKER=NONE \ | |
-DHOST_COMPILER=NONE \ | |
-DLLVM_ENABLE_ASSERTIONS=ON \ | |
-DLLVM_ENABLE_RTTI=ON \ | |
-DCMAKE_MODULE_PATH=`pwd`/../cmake/modulesXilinx \ | |
-DMLIR_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/mlir \ | |
-DLLVM_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/llvm \ | |
-DLLVM_USE_LINKER=lld \ | |
-DLLVM_EXTERNAL_LIT=$(which lit) \ | |
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON | |
ninja | |
ninja check-aie | |
ninja check-tutorials | |
ninja check-reference-designs | |
# Build the repo test target in release mode to build and test. | |
- name: Build and test (Release) | |
if: matrix.build_type == 'Release' | |
run: | | |
mkdir build_release | |
cd build_release | |
cmake .. \ | |
-GNinja \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \ | |
-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON \ | |
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \ | |
-DCMAKE_C_VISIBILITY_PRESET=hidden \ | |
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \ | |
-DAIE_COMPILER=NONE \ | |
-DAIE_LINKER=NONE \ | |
-DHOST_COMPILER=NONE \ | |
-DLLVM_ENABLE_ASSERTIONS=OFF \ | |
-DLLVM_ENABLE_RTTI=ON \ | |
-DCMAKE_MODULE_PATH=`pwd`/../cmake/modulesXilinx \ | |
-DMLIR_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/mlir \ | |
-DLLVM_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/llvm \ | |
-DLLVM_USE_LINKER=lld \ | |
-DLLVM_EXTERNAL_LIT=$(which lit) | |
ninja | |
ninja check-aie | |
ninja check-tutorials | |
ninja check-reference-designs | |
# lint-repo: | |
# | |
# name: Check formatting and lint | |
# | |
# runs-on: ubuntu-latest | |
# | |
# permissions: | |
# contents: write | |
# pull-requests: write | |
# | |
# steps: | |
# - name: Get repo | |
# uses: actions/checkout@v3 | |
# with: | |
# fetch-depth: 2 | |
# submodules: "true" | |
# | |
# - uses: actions/setup-python@v4 | |
# with: | |
# python-version: '3.9' | |
# | |
# - name: Install Python packages | |
# run: | | |
# pip install cmake numpy psutil pybind11 rich pkginfo lit PyYAML | |
# | |
# - name: Install Ninja | |
# run: sudo apt-get install -y ninja-build | |
# | |
# - name: Get MLIR | |
# id: mlir-wheels | |
# run: | | |
# pip -q download mlir -f https://github.com/Xilinx/mlir-aie/releases/expanded_assets/mlir-distro && unzip -q mlir-*.whl | |
# echo "MLIR_DIR=$PWD/mlir" | tee -a $GITHUB_OUTPUT | |
# | |
# - name: Build for compilation db | |
# run: | | |
# mkdir build_assert | |
# pushd build_assert | |
# cmake .. \ | |
# -GNinja \ | |
# -DCMAKE_BUILD_TYPE=Release \ | |
# -DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON \ | |
# -DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \ | |
# -DCMAKE_C_VISIBILITY_PRESET=hidden \ | |
# -DCMAKE_CXX_VISIBILITY_PRESET=hidden \ | |
# -DAIE_COMPILER=NONE \ | |
# -DAIE_LINKER=NONE \ | |
# -DHOST_COMPILER=NONE \ | |
# -DLLVM_ENABLE_ASSERTIONS=ON \ | |
# -DLLVM_ENABLE_RTTI=ON \ | |
# -DCMAKE_MODULE_PATH=`pwd`/../cmake/modulesXilinx \ | |
# -DMLIR_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/mlir \ | |
# -DLLVM_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/llvm \ | |
# -DLLVM_EXTERNAL_LIT=$(which lit) \ | |
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | |
# | |
# ninja aie-headers mlir-headers | |
# popd | |
# | |
# - uses: cpp-linter/cpp-linter-action@v2 | |
# id: linter | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# with: | |
# style: file | |
# database: build_assert | |
# files-changed-only: true | |
# # this is a combined list from LLVM and MLIR | |
# tidy-checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-const-correctness,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion,-misc-use-anonymous-namespace,readability-identifier-naming,-misc-const-correctness,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-macro-parentheses,bugprone-macro-repeated-side-effects,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-suspicious-semicolon,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-unused-raii,bugprone-unused-return-value,misc-redundant-expression,misc-static-assert,misc-unused-using-decls,modernize-use-bool-literals,modernize-loop-convert,modernize-make-unique,modernize-raw-string-literal,modernize-use-equals-default,modernize-use-default-member-init,modernize-use-emplace,modernize-use-nullptr,modernize-use-override,modernize-use-using,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-vector-operation,performance-move-const-arg,performance-no-automatic-move,performance-trivially-destructible,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-inconsistent-declaration-parameter-name,readability-misleading-indentation,readability-redundant-control-flow,readability-redundant-smartptr-get,readability-simplify-boolean-expr,readability-simplify-subscript-expr,readability-use-anyofallof' | |
# thread-comments: ${{ github.event_name == 'pull_request' && 'update' }} | |
# | |
# - name: Pass/Fail | |
# if: steps.linter.outputs.checks-failed > 0 | |
# run: exit 1 | |
clang-tidy: | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
fetch-depth: 2 | |
submodules: "true" | |
- name: Install clang-tidy | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y clang-tidy ninja-build clang | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install Python packages | |
run: | | |
pip install cmake numpy psutil pybind11 rich pkginfo lit PyYAML requests | |
- name: Get MLIR | |
id: mlir-wheels | |
run: | | |
pip -q download mlir -f https://github.com/Xilinx/mlir-aie/releases/expanded_assets/mlir-distro && unzip -q mlir-*.whl | |
echo "MLIR_DIR=$PWD/mlir" | tee -a $GITHUB_OUTPUT | |
- name: Prepare compile_commands.json | |
run: | | |
mkdir build | |
pushd build | |
cmake .. \ | |
-GNinja \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_C_COMPILER=clang \ | |
-DCMAKE_CXX_COMPILER=clang++ \ | |
-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON \ | |
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \ | |
-DCMAKE_C_VISIBILITY_PRESET=hidden \ | |
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \ | |
-DAIE_COMPILER=NONE \ | |
-DAIE_LINKER=NONE \ | |
-DHOST_COMPILER=NONE \ | |
-DLLVM_ENABLE_ASSERTIONS=ON \ | |
-DLLVM_ENABLE_RTTI=ON \ | |
-DCMAKE_MODULE_PATH=`pwd`/../cmake/modulesXilinx \ | |
-DMLIR_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/mlir \ | |
-DLLVM_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/llvm \ | |
-DLLVM_EXTERNAL_LIT=$(which lit) \ | |
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON | |
ninja aie-headers mlir-headers | |
popd | |
- name: Analyze | |
run: | | |
git fetch origin main | |
git diff -U0 origin/main | clang-tidy-diff -p1 -path build -export-fixes fixes.yml | |
cat fixes.yml | |
- name: Run code formatter | |
env: | |
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} | |
run: | | |
PULL_REQUEST_ID="$(jq "if (.issue.number != null) then .issue.number else .number end" < "$GITHUB_EVENT_PATH")" | |
echo $PULL_REQUEST_ID | |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} python utils/git/clang-tidy-pr.py \ | |
--clang-tidy-fixes fixes.yml \ | |
--pull-request-id "$PULL_REQUEST_ID" \ | |
--repository "$GITHUB_REPOSITORY" \ | |
--repository-root "$PWD" \ | |
--request-changes "true" \ | |
--suggestions-per-comment 10 | |
code-coverage: | |
name: Code Coverage | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Get the project repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
submodules: "true" | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install Python and other packages | |
run: | | |
pip install cmake numpy psutil pybind11 rich lit | |
- name: Install Ninja | |
run: sudo apt-get install -y ninja-build | |
- name: Install llvm-cov | |
run: sudo apt-get install -y clang lld llvm | |
- name: Get changed files | |
id: changed-files | |
run: | | |
git fetch origin main | |
# Because for the life of me I cannot figure out how to read the output of git diff into a bash array. | |
CHANGED_FILES=$(python utils/get_git_changed_files.py) | |
echo "changed-files=${CHANGED_FILES}" | tee $GITHUB_OUTPUT | |
- name: Get MLIR | |
id: mlir-wheels | |
run: | | |
pip -q download mlir -f https://github.com/Xilinx/mlir-aie/releases/expanded_assets/mlir-distro && unzip -q mlir-*.whl | |
echo "MLIR_DIR=$PWD/mlir" | tee -a $GITHUB_OUTPUT | |
- name: Ccache for C++ compilation | |
if: steps.changed-files.outputs.changed-files != '' | |
# https://github.com/hendrikmuhs/ccache-action/releases/tag/v1.2.9 | |
uses: hendrikmuhs/ccache-action@ca3acd2731eef11f1572ccb126356c2f9298d35e | |
with: | |
key: ${{ runner.os }}-${{ matrix.ubuntu_version }}-${{ steps.get-llvm-commit-hash.outputs.hash }}-code-cov | |
max-size: 1G | |
- name: Install our python reqs | |
if: steps.changed-files.outputs.changed-files != '' | |
run: pip install -r python/requirements.txt | |
- name: Build and generate coverage (Release) | |
if: steps.changed-files.outputs.changed-files != '' | |
run: | | |
mkdir build_release | |
cd build_release | |
cmake .. \ | |
-GNinja \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON \ | |
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \ | |
-DCMAKE_C_VISIBILITY_PRESET=hidden \ | |
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \ | |
-DAIE_COMPILER=NONE \ | |
-DAIE_LINKER=NONE \ | |
-DHOST_COMPILER=NONE \ | |
-DLLVM_ENABLE_ASSERTIONS=OFF \ | |
-DLLVM_ENABLE_RTTI=ON \ | |
-DCMAKE_MODULE_PATH=`pwd`/../cmake/modulesXilinx \ | |
-DMLIR_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/mlir \ | |
-DLLVM_DIR=${{ steps.mlir-wheels.outputs.MLIR_DIR }}/lib/cmake/llvm \ | |
-DLLVM_USE_LINKER=lld \ | |
-DLLVM_EXTERNAL_LIT=$(which lit) \ | |
\ | |
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ | |
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \ | |
-DBUILD_INSTRUMENTED_COVERAGE=ON \ | |
-DINSTRUMENTED_COVERAGE_FILES="${{ steps.changed-files.outputs.changed-files }}" | |
ninja && ninja generate-aie-coverage-report | |
cat /home/runner/work/mlir-aie/mlir-aie/build_release/report/summary.txt | |
- name: Format coverage report | |
if: steps.changed-files.outputs.changed-files != '' | |
id: format-report | |
run: | | |
sed -i.bak 's/<!doctype html>/<!--<!doctype codecov html>-->/g' /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html | |
sed -i.bak 's/<pre>//g' /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html | |
sed -i.bak 's/<\/pre>//g' /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html | |
sed -i.bak 's/([0-9]*\/[0-9]*)//g' /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html | |
sed -i.bak "s/href=/href=''/g" /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html | |
WORKSPACE=$(echo "/home/runner/work/mlir-aie/mlir-aie/" | sed 's/\//\\\//g') | |
sed -i.bak "s/$WORKSPACE//g" /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html | |
- name: Update PR with coverage results | |
if: steps.changed-files.outputs.changed-files != '' && github.event.pull_request.head.repo.full_name == github.repository | |
uses: edumserrano/find-create-or-update-comment@v2 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body-includes: '<!--<!doctype codecov html>-->' | |
comment-author: 'github-actions[bot]' | |
body-path: /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html | |
edit-mode: replace | |
code_formatter: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Get the project repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
submodules: "true" | |
- name: Get changed files | |
id: changed-files | |
run: | | |
git fetch origin main | |
# Because for the life of me I cannot figure out how to read the output of git diff into a bash array. | |
CHANGED_FILES=$(python utils/get_git_changed_files.py) | |
echo "changed-files=${CHANGED_FILES}" | tee $GITHUB_OUTPUT | |
- name: Install clang-format | |
uses: aminya/setup-cpp@v1 | |
with: | |
clangformat: 17.0.1 | |
- name: Setup Python env | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
cache: 'pip' | |
cache-dependency-path: 'code-format-tools/utils/git/requirements_formatting.txt' | |
- name: Install python dependencies | |
run: pip install -r utils/git/requirements_formatting.txt | |
- name: Run code formatter | |
env: | |
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} | |
START_REV: ${{ github.event.pull_request.base.sha }} | |
END_REV: ${{ github.event.pull_request.head.sha }} | |
CHANGED_FILES: ${{ steps.changed-files.outputs.changed-files }} | |
run: | | |
python utils/git/code-format-helper.py \ | |
--token ${{ secrets.GITHUB_TOKEN }} \ | |
--issue-number $GITHUB_PR_NUMBER \ | |
--start-rev $START_REV \ | |
--end-rev $END_REV \ | |
--changed-files "$CHANGED_FILES" |