From e819dbb0ff4dfbea27021f0474af7252ac7d21b0 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Mon, 15 Dec 2025 12:41:53 +0800 Subject: [PATCH 1/6] [CI] Update pre-commit hooks --- .pre-commit-config.yaml | 4 ++-- requirements-lint.txt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1bb4ceeb..bdaffff1f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,12 +32,12 @@ repos: args: [--ignore-case] files: ^docs/spelling_wordlist\.txt$ - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v21.1.6 # sync with requirements-lint.txt + rev: v21.1.7 # sync with requirements-lint.txt hooks: - id: clang-format types_or: [c++, c] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.14.7 # sync with requirements-lint.txt + rev: v0.14.9 # sync with requirements-lint.txt hooks: - id: ruff-format - id: ruff-check diff --git a/requirements-lint.txt b/requirements-lint.txt index 54f03638b..b68f81a2d 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -1,6 +1,6 @@ # Format and lint requirements pre-commit -clang-format==21.1.2 -clang-tidy==21.1.1 +clang-format==21.1.7 +clang-tidy==21.1.6 codespell[toml]==2.4.1 -ruff==0.14.3 +ruff==0.14.9 From 6db2b0427c4001c34865b84311533c47c4b42883 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Mon, 15 Dec 2025 13:02:06 +0800 Subject: [PATCH 2/6] [Lint] Pass correct `exclude-header-filter` to `clang-tidy` --- .clang-tidy | 2 ++ .github/workflows/ci.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 1681ed66e..f9b77bce8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,7 +4,9 @@ ExtraArgs: [] FormatStyle: file UseColor: true WarningsAsErrors: '*' +# FIXME: Use `ExcludeHeaderFilterRegex` instead when all maintainers upgraded their `clang-tidy` HeaderFilterRegex: '^(?!.*(?:/|^)(3rdparty|tvm)/).*' +# ExcludeHeaderFilterRegex: '^(3rdparty|tvm)/.*$' # NOTE: there must be no spaces before the '-', so put the comma last. Checks: >- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c33a25b65..7195cdee7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -316,6 +316,7 @@ jobs: CXX_FILES=$(find src -type f -iname "*.[ch]pp" -o -iname "*.cc" -o -iname "*.c" -o -iname "*.h") rc=0 "${CLANG_TIDY[@]}" -clang-tidy-binary="$(command -v clang-tidy)" \ + -exclude-header-filter='^(3rdparty|tvm)/.*$' \ -p="cmake-build" ${CXX_FILES} || rc="$?" rm -rf cmake-build run-clang-tidy.py if (( rc != 0 )); then From 53e84b46ac19a7ca18ab7e23202ca8a706c342a0 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Mon, 15 Dec 2025 13:07:55 +0800 Subject: [PATCH 3/6] [Lint] Download latest `run-clang-tidy` script --- .github/workflows/ci.yml | 19 ++++++++----------- .gitignore | 5 ++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7195cdee7..b75f85e1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -294,18 +294,15 @@ jobs: run: | echo "\$ $(command -v clang-tidy) --version" && clang-tidy --version - if [[ -x "$(command -v run-clang-tidy)" ]]; then - echo "Using run-clang-tidy from $(command -v run-clang-tidy)" - CLANG_TIDY=(run-clang-tidy) - else - RCT_URL=https://raw.githubusercontent.com/llvm/llvm-project/refs/heads/release/21.x/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py - echo "Downloading run-clang-tidy script from ${RCT_URL}" - echo "import urllib.request; url = '${RCT_URL}'.rstrip('/'); urllib.request.urlretrieve(url, url.split('/')[-1])" | uv run --no-project --script - - CLANG_TIDY=(uv run --no-project --script -- run-clang-tidy.py) - fi + # Download run-clang-tidy script + RCT_URL=https://raw.githubusercontent.com/llvm/llvm-project/refs/heads/release/21.x/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py + echo "Downloading run-clang-tidy script from ${RCT_URL}" + echo "import urllib.request; url = '${RCT_URL}'.rstrip('/'); urllib.request.urlretrieve(url, url.split('/')[-1])" | uv run --no-project --script - + RUN_CLANG_TIDY=(uv run --no-project --script -- run-clang-tidy.py) + if [[ -x "$(command -v clang-apply-replacements)" ]]; then echo "Using clang-apply-replacements from $(command -v clang-apply-replacements)" - CLANG_TIDY+=(-fix -clang-apply-replacements-binary="$(command -v clang-apply-replacements)") + RUN_CLANG_TIDY+=(-fix -clang-apply-replacements-binary="$(command -v clang-apply-replacements)") else echo "::warning::clang-apply-replacements not found in PATH, automatic fixing disabled." fi @@ -315,7 +312,7 @@ jobs: CXX_FILES=$(find src -type f -iname "*.[ch]pp" -o -iname "*.cc" -o -iname "*.c" -o -iname "*.h") rc=0 - "${CLANG_TIDY[@]}" -clang-tidy-binary="$(command -v clang-tidy)" \ + "${RUN_CLANG_TIDY[@]}" -clang-tidy-binary="$(command -v clang-tidy)" \ -exclude-header-filter='^(3rdparty|tvm)/.*$' \ -p="cmake-build" ${CXX_FILES} || rc="$?" rm -rf cmake-build run-clang-tidy.py diff --git a/.gitignore b/.gitignore index d94abf9e3..8dc9fd880 100644 --- a/.gitignore +++ b/.gitignore @@ -116,4 +116,7 @@ maint/host_checks/logs/* *.ncu-rep # csv -*.csv \ No newline at end of file +*.csv + +# clang-tidy +/run-clang-tidy.py From 8db8308b6b86212f2ed810d4e97857130270f912 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Mon, 15 Dec 2025 13:43:48 +0800 Subject: [PATCH 4/6] [CI] Show compile commands --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b75f85e1c..44a8e0f2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -309,6 +309,10 @@ jobs: # Run cmake to create the build directory with compile_commands.json cmake -S . -B cmake-build --fresh ${CLANG_TIDY_CMAKE_OPTIONS} # no quotes here + echo "::group::compile_commands.json" + ls -alh cmake-build/compile_commands.json + uv run --no-project -m -- json.tool --no-ensure-ascii cmake-build/compile_commands.json + echo "::endgroup::" CXX_FILES=$(find src -type f -iname "*.[ch]pp" -o -iname "*.cc" -o -iname "*.c" -o -iname "*.h") rc=0 From 4271e5d13ec88db52d54e9b2d8c3cb990513cd51 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Mon, 15 Dec 2025 14:11:12 +0800 Subject: [PATCH 5/6] [CI] Add output grouping to GHA --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44a8e0f2a..0bf2e2ec9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -316,9 +316,11 @@ jobs: CXX_FILES=$(find src -type f -iname "*.[ch]pp" -o -iname "*.cc" -o -iname "*.c" -o -iname "*.h") rc=0 + echo "::group::run-clang-tidy" "${RUN_CLANG_TIDY[@]}" -clang-tidy-binary="$(command -v clang-tidy)" \ -exclude-header-filter='^(3rdparty|tvm)/.*$' \ -p="cmake-build" ${CXX_FILES} || rc="$?" + echo "::endgroup::" rm -rf cmake-build run-clang-tidy.py if (( rc != 0 )); then echo "::error::clang-tidy found issues (exit code: ${rc}). Please run 'clang-tidy --fix' locally to fix them." From 5bd471fd47bdd671ebdd3fc208accb2694d4634e Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Mon, 15 Dec 2025 16:14:32 +0800 Subject: [PATCH 6/6] [Lint] Re-order pre-commit hooks --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bdaffff1f..3504adb6d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,9 +39,10 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.14.9 # sync with requirements-lint.txt hooks: - - id: ruff-format - id: ruff-check args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + args: [--exit-non-zero-on-format] - repo: https://github.com/codespell-project/codespell rev: v2.4.1 # sync with requirements-lint.txt hooks: