Skip to content

checkpatch: remove and use clang-format instead#10619

Open
lgirdwood wants to merge 1 commit intothesofproject:mainfrom
lgirdwood:checkpatch
Open

checkpatch: remove and use clang-format instead#10619
lgirdwood wants to merge 1 commit intothesofproject:mainfrom
lgirdwood:checkpatch

Conversation

@lgirdwood
Copy link
Member

checkpatch flags too many false positives in the SOF codebase to be considered useful. Notwithstanding it does not cope with assembler, matlab and topology very well.

Remove and use clang-format instead which is understood by modern editors and agents for both SOF and rimage.

clang-format is based on Linux clang-format with adaptations for SOF and Zephyr.

checkpatch flags too many false positives in the SOF codebase to be
considered useful. Notwithstanding it does not cope with assembler,
matlab and topology very well.

Remove and use clang-format instead which is understood by modern editors
and agents for both SOF and rimage.

clang-format is based on Linux clang-format with adaptations for SOF and
Zephyr.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Copilot AI review requested due to automatic review settings March 12, 2026 16:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the existing checkpatch-based style tooling (including CI and git hooks) and introduces clang-format configuration intended to become the new code-style mechanism for SOF/rimage.

Changes:

  • Deleted the rimage-local checkpatch implementation and associated configuration/data files.
  • Removed checkpatch-based git hooks and the GitHub Actions checkpatch job.
  • Added clang-format configuration files at repo root and under tools/rimage/.

Reviewed changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tools/rimage/scripts/checkpatch.pl Removes the rimage checkpatch script entirely.
tools/rimage/.clang-format Adds clang-format rules for the rimage tree.
tools/rimage/.checkpatch.conf Removes rimage checkpatch configuration.
scripts/sof-pre-commit-hook.sh Removes pre-commit hook invoking checkpatch.
scripts/sof-post-commit-hook.sh Removes post-commit hook invoking checkpatch.
scripts/const_structs.checkpatch Removes checkpatch data file used by constant-struct checks.
.gitignore Drops ignore pattern for checkpatch-generated camelcase cache.
.github/workflows/codestyle.yml Removes the checkpatch CI job (leaves yamllint).
.github/workflows/checkpatch_list.sh Removes helper script used by the checkpatch CI job.
.github/workflows/SPDX-README.md Rewords guidance text to be less checkpatch-centric.
.clang-format Adds repo-root clang-format rules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 14 to 22
# yamllint disable-line rule:truthy
on: [pull_request, workflow_call, workflow_dispatch]

jobs:
checkpatch:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
strictness: [null, --subjective]

env:
PR_NUM: ${{github.event.number}}
# TODO: reduce duplication with scripts/sof-*-commit-hook.sh
# thanks to either some .conf file or some wrapper script
CHK_CMD_OPTS: --ignore UNKNOWN_COMMIT_ID --codespell

steps:
# depth 2 so:
# ^1. we can show the Subject of the current target branch tip
# ^2. we reconnect/graft to the later fetch pull/1234/head,
- uses: actions/checkout@v4
with: {fetch-depth: 2}

- name: install codespell
run: sudo apt-get -y install codespell && dpkg -L codespell | grep dict

# See shallowness issue https://github.com/thesofproject/linux/issues/2556
- name: fetch PR commits
run: |
.github/workflows/shallowfetchPRcommits.sh \
${GITHUB_REPOSITORY} "$PR_NUM"
# show what we got
git --no-pager log --oneline --graph --decorate --max-count=50

- name: checkpatch
env:
STRICTNESS: ${{ matrix.strictness }}
run: .github/workflows/checkpatch_list.sh ${CHK_CMD_OPTS}
${STRICTNESS} < PR_SHAs.txt

jobs:
yamllint:
runs-on: ubuntu-latest
steps:
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says checkpatch is removed and clang-format is used instead, but the workflow change removes the checkpatch job without adding any clang-format enforcement. This means CI no longer checks C/C++ formatting at all (only yamllint remains). Add a new GitHub Actions job that runs clang-format in verify mode (e.g., formatting check / diff check) using the committed .clang-format so the intended replacement is actually applied in CI.

Copilot uses AI. Check for mistakes.
# SPDX-License-Identifier: GPL-2.0
#
# clang-format configuration file. Intended for clang-format >= 11.
#
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clang-format configuration appears to be duplicated verbatim in two places (.clang-format and tools/rimage/.clang-format). Keeping identical configs in multiple locations is likely to diverge over time and create inconsistent formatting depending on where clang-format is invoked from. Consider consolidating to a single source of truth (preferably the repo root), or add an explicit comment/guardrail explaining why tools/rimage/ needs its own copy and how it should be kept in sync.

Suggested change
#
#
# NOTE: This file is intentionally duplicated in tools/rimage/.clang-format.
# Both copies must remain identical. If you change formatting options here,
# make the same change in tools/rimage/.clang-format to keep them in sync.
#

Copilot uses AI. Check for mistakes.
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clang-format configuration appears to be duplicated verbatim in two places (.clang-format and tools/rimage/.clang-format). Keeping identical configs in multiple locations is likely to diverge over time and create inconsistent formatting depending on where clang-format is invoked from. Consider consolidating to a single source of truth (preferably the repo root), or add an explicit comment/guardrail explaining why tools/rimage/ needs its own copy and how it should be kept in sync.

Copilot uses AI. Check for mistakes.
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 120
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clang-format configuration appears to be duplicated verbatim in two places (.clang-format and tools/rimage/.clang-format). Keeping identical configs in multiple locations is likely to diverge over time and create inconsistent formatting depending on where clang-format is invoked from. Consider consolidating to a single source of truth (preferably the repo root), or add an explicit comment/guardrail explaining why tools/rimage/ needs its own copy and how it should be kept in sync.

Copilot uses AI. Check for mistakes.
Comment on lines +180 to +181
UseTab: Never
...
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clang-format configuration appears to be duplicated verbatim in two places (.clang-format and tools/rimage/.clang-format). Keeping identical configs in multiple locations is likely to diverge over time and create inconsistent formatting depending on where clang-format is invoked from. Consider consolidating to a single source of truth (preferably the repo root), or add an explicit comment/guardrail explaining why tools/rimage/ needs its own copy and how it should be kept in sync.

Copilot uses AI. Check for mistakes.
Comment on lines 15 to 21
on: [pull_request, workflow_call, workflow_dispatch]

jobs:
checkpatch:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
strictness: [null, --subjective]

env:
PR_NUM: ${{github.event.number}}
# TODO: reduce duplication with scripts/sof-*-commit-hook.sh
# thanks to either some .conf file or some wrapper script
CHK_CMD_OPTS: --ignore UNKNOWN_COMMIT_ID --codespell

steps:
# depth 2 so:
# ^1. we can show the Subject of the current target branch tip
# ^2. we reconnect/graft to the later fetch pull/1234/head,
- uses: actions/checkout@v4
with: {fetch-depth: 2}

- name: install codespell
run: sudo apt-get -y install codespell && dpkg -L codespell | grep dict

# See shallowness issue https://github.com/thesofproject/linux/issues/2556
- name: fetch PR commits
run: |
.github/workflows/shallowfetchPRcommits.sh \
${GITHUB_REPOSITORY} "$PR_NUM"
# show what we got
git --no-pager log --oneline --graph --decorate --max-count=50

- name: checkpatch
env:
STRICTNESS: ${{ matrix.strictness }}
run: .github/workflows/checkpatch_list.sh ${CHK_CMD_OPTS}
${STRICTNESS} < PR_SHAs.txt

jobs:
yamllint:
runs-on: ubuntu-latest
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the checkpatch CI job removed (and the checkpatch-based git hooks removed elsewhere in this PR), contributors lose the previously documented/implicit way to validate style locally and in CI. Add or update developer documentation to describe the new expected workflow (how to run clang-format, which paths it applies to, and any recommended editor/hook integration), ideally linking to the new .clang-format setup.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants