summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2026-07-12 18:38:31 +0800
committersakumisu <[email protected]>2026-07-12 18:38:31 +0800
commit5e9d0e6dd393d9aff3ed7f8dc46824139448d0bb (patch)
tree2824441b3b3396b92459df1a3acc27055188e0a2
parent22b07a18fde0befcdb59d58de5ad62c6ab4ba88e (diff)
update(chore): add clang-tidy
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--.clang-tidy24
-rw-r--r--.github/workflows/clang-tidy.yml93
-rw-r--r--.github/workflows/cppcheck.yml9
3 files changed, 125 insertions, 1 deletions
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 00000000..9977886d
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,24 @@
+---
+Checks: >
+ -*,
+ clang-analyzer-core.*,
+ clang-analyzer-deadcode.*,
+ clang-analyzer-nullability.*,
+ clang-analyzer-security.*,
+ -clang-analyzer-security.insecureAPI.*,
+ clang-analyzer-unix.*,
+ bugprone-*,
+ -bugprone-easily-swappable-parameters,
+ -bugprone-macro-parentheses,
+ -bugprone-reserved-identifier
+
+WarningsAsErrors: ''
+HeaderFilterRegex: '.*(core|class|common|osal|port|platform)/.*'
+FormatStyle: none
+
+CheckOptions:
+ bugprone-argument-comment.StrictMode: false
+ bugprone-sizeof-expression.WarnOnSizeOfConstant: true
+ bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression: false
+ bugprone-suspicious-memset-usage.WarnOnImplicitCast: true
+...
diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml
new file mode 100644
index 00000000..1f6c2171
--- /dev/null
+++ b/.github/workflows/clang-tidy.yml
@@ -0,0 +1,93 @@
+name: Clang-Tidy action
+
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+ inputs:
+ scan_regex:
+ description: "Regex used to select files from compile_commands.json"
+ required: false
+ default: "/(core|class|common|osal|port|platform)/.*[.]c$"
+
+jobs:
+ clang-tidy:
+ name: clang-tidy
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Install dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y clang-tidy cmake ninja-build jq ripgrep wget
+
+ - name: Download hpm_sdk
+ run: |
+ cd ~
+ git clone --depth 1 https://github.com/hpmicro/hpm_sdk.git
+
+ - name: Download RISC-V toolchain
+ run: |
+ cd ~
+ wget -q https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2023.10.18/rv32imac_zicsr_zifencei_multilib_b_ext-linux.tar.gz
+ tar -xzf rv32imac_zicsr_zifencei_multilib_b_ext-linux.tar.gz
+
+ - name: Generate HPM compile database
+ run: |
+ cd tests/hpmicro
+ export HPM_SDK_BASE=~/hpm_sdk
+ export GNURISCV_TOOLCHAIN_PATH=~/rv32imac_zicsr_zifencei_multilib_b_ext-linux
+ export HPM_SDK_TOOLCHAIN_VARIANT=
+ cmake -S . -B build -GNinja \
+ -DBOARD=hpm6800evk \
+ -DHPM_BUILD_TYPE=flash_sdram_xip \
+ -DCMAKE_BUILD_TYPE=debug \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
+
+ - name: Run clang-tidy
+ shell: bash
+ env:
+ SCAN_REGEX: ${{ github.event.inputs.scan_regex || '/(core|class|common|osal|port|platform)/.*[.]c$' }}
+ run: |
+ TOOLCHAIN="$HOME/rv32imac_zicsr_zifencei_multilib_b_ext-linux"
+ GCC="$TOOLCHAIN/bin/riscv32-unknown-elf-gcc"
+ GCC_INCLUDE="$("$GCC" -print-file-name=include)"
+ GCC_INCLUDE_FIXED="$("$GCC" -print-file-name=include-fixed)"
+
+ set +e
+ jq -r '.[].file' tests/hpmicro/build/compile_commands.json \
+ | rg "^${GITHUB_WORKSPACE}${SCAN_REGEX}" \
+ | xargs -r -n1 clang-tidy \
+ -p tests/hpmicro/build \
+ --quiet \
+ --extra-arg-before=--target=riscv32-unknown-elf \
+ --extra-arg=-isystem"$GCC_INCLUDE" \
+ --extra-arg=-isystem"$GCC_INCLUDE_FIXED" \
+ > clang-tidy.log 2>&1
+ tidy_status=$?
+ set -e
+
+ grep -E "warning:|error:" clang-tidy.log | tee clang-tidy-summary.log || true
+
+ while IFS= read -r line; do
+ if [[ "$line" =~ ^([^:]+):([0-9]+):([0-9]+):[[:space:]]warning:[[:space:]](.*)$ ]]; then
+ echo "::warning file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]},col=${BASH_REMATCH[3]}::${BASH_REMATCH[4]}"
+ elif [[ "$line" =~ ^([^:]+):([0-9]+):([0-9]+):[[:space:]]error:[[:space:]](.*)$ ]]; then
+ echo "::error file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]},col=${BASH_REMATCH[3]}::${BASH_REMATCH[4]}"
+ fi
+ done < clang-tidy-summary.log
+
+ if [ "$tidy_status" -ne 0 ]; then
+ exit "$tidy_status"
+ fi
+
+ - name: Upload clang-tidy logs
+ if: always()
+ uses: actions/upload-artifact@v4
+ with:
+ name: clang-tidy-logs
+ path: |
+ clang-tidy.log
+ clang-tidy-summary.log
diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml
index 666afd27..9a6523cd 100644
--- a/.github/workflows/cppcheck.yml
+++ b/.github/workflows/cppcheck.yml
@@ -13,5 +13,12 @@ jobs:
- name: cppcheck
shell: bash
run: |
+ set -o pipefail
sudo apt install cppcheck
- cppcheck --enable=warning,portability,performance --language=c --platform=unix32 --std=c99 --force . -i third_party/ -i class/template -i port/template/
+ cppcheck --enable=warning,portability,performance --language=c --platform=unix32 --std=c99 --quiet --force . -i third_party/ -i class/template -i port/template/ -i tests/ --include=tests/hpmicro/inc/usb_config.h 2>&1 | tee cppcheck.log
+ - name: Upload cppcheck log
+ if: always()
+ uses: actions/upload-artifact@v4
+ with:
+ name: cppcheck-log
+ path: cppcheck.log