Skip to content

[clang-format] Pin version 22.1.8 and format kernel sources - #11936

Open
CYFS3 wants to merge 3 commits into
RT-Thread:masterfrom
CYFS3:style/src-clang-format-22.1.8
Open

CYFS3 wants to merge 3 commits into
RT-Thread:masterfrom
CYFS3:style/src-clang-format-22.1.8

Conversation

@CYFS3

@CYFS3 CYFS3 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

关联 #11653 和已合并的 #11859。

格式检查 CI 通过 pip 安装 clang-format,手动格式化工作流通过 apt 安装,均未固定版本,可能产生不同的格式化结果。需要将格式化工具固定到 22.x 的具体补丁版本,并统一 src/ 中与根目录配置不一致的历史排版。同时调整空循环和 do-while 的排版,避免将空循环的分号及 do-while 末尾的 while 单独拆行。

你的解决方案是什么 (what is your solution)

基于上游 master 的 9e6dec3b14f5bf5514b0da829736c2485c38b0a7,拆分为三个独立提交:

  1. 固定工具版本:将 clang-format 固定为 22.1.8,新增 tools/ci/requirements-format.txt,格式检查和手动格式化工作流都从该文件安装;手动工作流通过 actions/setup-python 提供 Python 环境。同步更新中英文编码规范中的安装、版本确认和编辑器配置说明。
  2. 调整格式参数:根目录 .clang-format 中将 AllowShortLoopsOnASingleLine 设为 true,空循环保留单行写法;将 BraceWrapping.BeforeWhile 设为 false,使普通代码及宏中的 do-while 使用 } while (...)。其余规则保持现状。
  3. 格式化源码:使用 clang-format 22.1.8 和上述配置递归格式化 src/ 下全部 73 个 C/头文件,包括 klibc、utest、perf、smp 子目录。69 个文件产生改动,其余 4 个已符合格式。Kconfig、SConscript 及其他目录的源码不在格式化范围内。

配合现有 InsertBraces: true,普通单语句循环仍补大括号并保持多行;AllowShortLoopsOnASingleLine 也可能影响宏定义中的无大括号短循环,作用范围不限于空循环。BeforeWhile 控制 do-while 结尾的换行,独立的 while、for 不受该选项影响。

现有 InsertBraces: true 为单语句分支和循环补充了 266 对大括号,因此整体源码差异包含空白、换行、注释排版及这些大括号,不能简单视为仅空白变更。

验证:

  • 73 个文件均通过 clang-format 22.1.8 的 --dry-run --Werror 及仓库现有 tools/ci/clang_format_check.py 检查。
  • 从基线重新格式化可复现全部结果,再次格式化不产生变化。
  • 对比原始与格式化后的 C token,除新增大括号外,原有 token 及顺序保持一致;预处理指令 token 和逻辑行边界保持一致。
  • 两项参数分别对比验证:16 个文件的 25 处空循环合并分号;13 个文件的 28 处 do-while 合并 } 与 while,包括宏,均没有其他源码变动。
  • 两个工作流 YAML 解析通过,均读取同一固定版本依赖文件;git diff --check 通过。
  • 未编译整个工程,未进行板级运行测试。

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 style/src-clang-format-22.1.8
    Enter PR branch style/src-clang-format-22.1.8 in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 style/src-clang-format-22.1.8 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the style/src-clang-format-22.1.8 branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions Bot added Doc This PR/issue related with documents Kernel PR has src relate code action github action yml imporve tools labels Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: documentation

Reviewers: @CXSforHPU @GorrayLi @lianux-mm

Changed Files (Click to expand)
  • documentation/7.contribution/coding_style_cn.md
  • documentation/7.contribution/coding_style_en.md

🏷️ Tag: kernel

Reviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837

Changed Files (Click to expand)
  • src/clock.c
  • src/components.c
  • src/cpu_mp.c
  • src/defunct.c
  • src/idle.c
  • src/ipc.c
  • src/irq.c
  • src/klibc/kerrno.c
  • src/klibc/kstdio.c
  • src/klibc/kstring.c
  • src/klibc/rt_vsnprintf_std.c
  • src/klibc/rt_vsnprintf_tiny.c
  • src/klibc/rt_vsscanf.c
  • src/klibc/utest/TC_rt_memcmp.c
  • src/klibc/utest/TC_rt_memcpy.c
  • src/klibc/utest/TC_rt_memmove.c
  • src/klibc/utest/TC_rt_memset.c
  • src/klibc/utest/TC_rt_sprintf.c
  • src/klibc/utest/TC_rt_sscanf.c
  • src/kservice.c
  • src/mem.c
  • src/memheap.c
  • src/mempool.c
  • src/object.c
  • src/scheduler_comm.c

🏷️ Tag: workflow

Reviewers: @Rbb666 @kurisaW @supperthomas

Changed Files (Click to expand)
  • .github/workflows/format_check.yml
  • .github/workflows/pr_clang_format.yml

📊 Current Review Status (Last Updated: 2026-10-29 10:47 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

nordic-nrf51822

  • FLASH: .text -8 B (-0.0%, 52,028 B / 262,144 B, total: 20% used)

raspberry-pico-rp2040

  • FLASH: .text -8 B (-0.0%, 114,160 B / 2,097,152 B, total: 5% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Comment thread src/utest/mutex_tc.c Outdated
tick = rt_tick_get();
while (rt_tick_get() - tick < (RT_TICK_PER_SECOND / 2));
while (rt_tick_get() - tick < (RT_TICK_PER_SECOND / 2))
;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这块的格式化是不是有些怪?怎么还换行了

Comment thread src/utest/thread_tc.c Outdated

while (tid6_finish_flag != 1);
while (tid6_finish_flag != 1)
;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

@CYFS3
CYFS3 force-pushed the style/src-clang-format-22.1.8 branch from 476815c to 804e8d0 Compare October 29, 2026 01:37
@CYFS3
CYFS3 force-pushed the style/src-clang-format-22.1.8 branch from 804e8d0 to a9de94f Compare October 29, 2026 01:52
@Rbb666 Rbb666 added the +1 Agree +1 label Oct 29, 2026
@CYFS3 CYFS3 closed this Oct 29, 2026
@CYFS3 CYFS3 reopened this Oct 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action github action yml imporve Doc This PR/issue related with documents Kernel PR has src relate code tools +1 Agree +1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants