已合并
refactor: 统一头文件 include guard 为 #pragma once 并添加 CI lint 规则 #173
zhanghua创建于 6月16日
refactor: 统一头文件 include guard 为 #pragma once 并添加 CI lint 规则 #173
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhanghua 的贡献)6月16日 关联了issue:[Requirement|需求建议]: 统一头文件 include guard 风格
6月16日 添加了label:cann-cla/yes
CANN-robot
6月16日 评论:
6月16日 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/ops-blas | ✅ 王子韬, 宋凯 (2/2) | ✅ 宋凯, 王子韬 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zhanghua145, thanks for your pull request. All authors of the commits have signed the CLA. 👍


6月16日 修改了pull request 的描述
zhanghua
6月16日 评论:
6月16日 评论:
compile


此处折叠了43条消息 查看更多
6月16日 添加了label:approved
songkai111
6月16日 评论:
6月16日 评论:
/lgtm
/approve


6月16日 添加了label:lgtm
6月16日 关闭了关联的issue
6月16日 合入了pull request
描述
统一仓库中所有头文件的 include guard 风格为
#pragma once,解决当前#ifndef/#define/#endif与#pragma once混用导致的风格不一致问题。关联 Issue
关联 Issue #162
变更内容
1. 统一现有头文件(125 个文件,+456/-698)
#ifndef→#pragma once#pragma once#pragma oncecgerc_kernel_impl.h原先缺少 include guard2. 添加 CI lint 检查脚本
新增
scripts/ci/check_pragma_once.sh,用于检查 PR 中新增/修改的.h/.hpp文件是否使用#pragma once。调用方式(与现有
scripts/ci/run_example.sh一致,接收 PR 文件列表):pr_filelist.txt格式为每行一个文件路径(相对仓库根目录),仅检查.h/.hpp文件,其他文件类型自动跳过。检查规则:
#pragma once,拒绝#ifndefinclude guard 和无 guard 的文件.opencode/、asc-devkit/等)⚠️ 需要维护者操作:接入 CI 流水线
本 PR 提供了
scripts/ci/check_pragma_once.sh检查脚本,但尚未接入 CI 流水线。需要维护者在 GitCode 平台侧的流水线配置中新增一个步骤,在编译前调用该脚本。建议的接入方式(参考现有
run_example.sh的调用模式):# CI 流水线中新增 lint 步骤(在编译步骤之前) - name: check-pragma-once script: | # pr_filelist.txt 由平台自动生成,包含 PR 变更文件列表 bash scripts/ci/check_pragma_once.sh pr_filelist.txt在维护者接入流水线之前,该脚本也可通过以下方式手动使用:
bash scripts/ci/check_pragma_once.sh <文件列表>.pre-commit-config.yaml(需开发者自行安装pre-commit)关于 Issue 中提到的 3 个缺少 guard 的头文件
Issue #162 提到有 3 个头文件缺少标准 include guard。经逐 commit 追溯历史,原始 3 个文件为:
blas/gerc/cgerc/arch22/cgerc_kernel_impl.hblas/cgerc/cgerc_kernel_impl.hblas/gerc/cgerc/arch22/)blas/common/kernel_launch/aclblas_kernel_do.hcc4d43c"del common kernel launch header")第 2、3 个文件已在其他 PR 的重构过程中被删除,因此本次只需修复第 1 个文件。
未修改的
#ifndef仓库中剩余约 114 处
#ifndef均为条件编译(非 include guard),保持不变:#ifndef __CCE_AICORE__— 区分 Host/Device 编译目标#ifndef TEST_DEVICE_ID— 测试设备 ID 默认值#ifndef __force_inline__— 编译器特性检测#ifndef ACLBLAS_OPERATION_DECLARED— 枚举声明保护这些是功能性的编译条件判断,不属于 include guard,不在本次修改范围内。
验证
bash build.sh --run --soc=ascend950,ops_blas + ops_blasLt 均成功)#pragma once#ifndefguard,放行#pragma once,仅检查 PR 变更文件)类型标签