| refactor: 统一头文件 include guard 为 #pragma once 并添加 CI lint 规则 Co-authored-by: Zhang Hua<1302896824@qq.com> # message auto-generated for no-merge-commit merge: !173 merge unify-include-guards into master refactor: 统一头文件 include guard 为 #pragma once 并添加 CI lint 规则 Created-by: zhanghua145 Commit-by: Zhang Hua Merged-by: cann-robot Description: ## 描述 统一仓库中所有头文件的 include guard 风格为 #pragma once,解决当前 #ifndef/#define/#endif 与 #pragma once 混用导致的风格不一致问题。 ## 关联 Issue 关联 Issue #162 ## 变更内容 ### 1. 统一现有头文件(125 个文件,+456/-698) | 类别 | 数量 | 说明 | |------|------|------| | #ifndef → #pragma once | 215 个 | 传统宏保护替换为 #pragma once | | 补充 #pragma once | 1 个 | cgerc_kernel_impl.h 原先缺少 include guard | | agent 模板同步 | 2 个 | 模板文件同步转换 | | **净减少行数** | **242 行** | 456 行增加,698 行删除 | ### 2. 添加 CI lint 检查脚本 新增 scripts/ci/check_pragma_once.sh,用于检查 PR 中新增/修改的 .h/.hpp 文件是否使用 #pragma once。 **调用方式**(与现有 scripts/ci/run_example.sh 一致,接收 PR 文件列表): bash bash scripts/ci/check_pragma_once.sh <pr_filelist.txt> pr_filelist.txt 格式为每行一个文件路径(相对仓库根目录),仅检查 .h/.hpp 文件,其他文件类型自动跳过。 **检查规则**: - 必须使用 #pragma once,拒绝 #ifndef include guard 和无 guard 的文件 - 自动跳过第三方目录(.opencode/、asc-devkit/ 等) ## ⚠️ 需要维护者操作:接入 CI 流水线 本 PR 提供了 scripts/ci/check_pragma_once.sh 检查脚本,但**尚未接入 CI 流水线**。需要维护者在 GitCode 平台侧的流水线配置中新增一个步骤,在编译前调用该脚本。 建议的接入方式(参考现有 run_example.sh 的调用模式): yaml # 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 hook**:已集成到 .pre-commit-config.yaml(需开发者自行安装 pre-commit) ## 关于 Issue 中提到的 3 个缺少 guard 的头文件 Issue #162 提到有 3 个头文件缺少标准 include guard。经逐 commit 追溯历史,原始 3 个文件为: | # | 文件 | 当前状态 | |---|------|----------| | 1 | blas/gerc/cgerc/arch22/cgerc_kernel_impl.h | 仍存在,**本次已修复** | | 2 | blas/cgerc/cgerc_kernel_impl.h | 已被删除(cgerc 目录重构,迁移至 blas/gerc/cgerc/arch22/) | | 3 | blas/common/kernel_launch/aclblas_kernel_do.h | 已被删除(commit cc4d43c "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,不在本次修改范围内。 ## 验证 - [x] 测试通过(bash build.sh --run --soc=ascend950,ops_blas + ops_blasLt 均成功)  - [x] 所有项目头文件(358 个)均已使用 #pragma once - [x] 无遗漏的 include guard 宏 - [x] CI lint 脚本测试通过(正确拒绝 #ifndef guard,放行 #pragma once,仅检查 PR 变更文件) ## 类型标签 - [ ] Bug 修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x] 其他:代码风格统一重构 See merge request: cann/ops-blas!173 | 6 天前 |