

Pull Request已成功合入, 合并人@CANN-robot
(感谢 liu-wei 的贡献)变更摘要
此 PR 修复了 scripts/util/merge_proto.py 中 proto 文件解析的正则表达式问题。原有的 REG_OP(...)...OP_END_FACTORY_REG(...) 模式在遇到操作定义前带有注释块(/** ... */)或预处理守卫(#ifndef/#define/#endif)时,会错误地将匹配边界扩展到文件中最先出现的 REG_OP,从而"误吞"额外的无关内容。修复方案是将正则提取为模块级 OP_DEF_PATTERN,在其中将注释和预处理守卫作为可选前缀/后缀,并使用命名捕获组(opname、opdef)精确提取操作名和操作定义本身,使 match_op_proto 与 match_op_proto_extend 两个函数均受益。
主要改动
- 新增模块级正则
OP_DEF_PATTERN:在文件顶部定义了一个完整的正则表达式,支持可选的/** ... */注释块、可选的#ifndef/#define预处理守卫、以及REG_OP(name)...OP_END_FACTORY_REG(name)操作定义与可选的#endif收尾,使用命名捕获组区分守卫与操作定义。 match_op_proto改用新正则:将原先内联构造的op_def_pattern替换为模块级OP_DEF_PATTERN,并通过match.group("opname")和match.group("opdef")获取结果,避免回退引用\1可能匹配到错误内容。match_op_proto_extend同步更新:同样替换为OP_DEF_PATTERN.finditer并使用命名捕获组获取每次匹配的操作名和操作定义,使多个操作定义场景下的解析保持一致且准确。


代码审查
审查总结
对变更文件 scripts/util/merge_proto.py 进行了全面审查,分析结果:
- P0: 0 个
- P1: 0 个
- P2: 0 个
- P3: 1 个
已审查的文件:
scripts/util/merge_proto.py— 发现 1 个 P3 问题(条件#endif匹配过于严格,守卫特性为死代码)
整体风险评估:低风险。此变更将行内编译的正则表达式提升为模块级预编译常量,并用命名捕获组替代数字索引,提升了代码可读性和可维护性。新增的 doc comment 和预处理守卫匹配逻辑对于当前仓库中的所有实际 proto 文件均能正确回退到核心 REG_OP 块匹配,不会产生错误输出。唯一的低优先级问题是守卫+endif 条件匹配过于严格导致该子特性在当前仓库中从未生效,但回退行为保证了功能正确性。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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-cv | ✅ 王林木, 张磊 (2/2) | ✅ 王林木, 张磊 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


compile


流水线任务触发成功
任务链接 [5cf0e33450cf4422b4598b6b6576098b][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_harmony-infer-chs-cv | ✅ SUCCESS | >>>>> | |
| Compile_harmony-infer-chs-cv-1 | ✅ SUCCESS | >>>>> | |
| UT_Test | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_report_lcov | ✅ SUCCESS |
[2026-07-07 17:26:25] CI执行结束


流水线任务触发成功
任务链接 [57faf48597fe40e9862434baedc8364f][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-07-07 17:22:48] CI执行结束

