已合并
feat: pre-commit & update clang-fmt #1377
maohp_hw创建于 4月1日
feat: pre-commit & update clang-fmt #1377
已合并
maohp_hw创建于 4月1日
maohp_hw
maohp_hw成员
4月1日

描述

为项目添加pre-commit钩子配置,在代码提交前自动执行代码格式化和合规性检查,提升代码质量和合规性。

实现

  • 新增.pre-commit-config.yaml配置文件,集成clang-format和OAT检查
  • 更新.clang-format配置,基于Google风格优化代码格式规则
  • 新增scripts/oat_check.sh脚本,实现OAT合规性检查功能
    • 支持自动检测和安装Java/Maven环境
    • 支持增量扫描(仅检查待提交文件)
    • 自动克隆和构建tools_oat工具
    • 生成合规性检查报告

具体变更

  1. clang-format配置更新
    • 基于Google风格调整格式规则
    • 优化括号对齐、函数格式等配置
    • 添加注释标记与基线配置的冲突点
  2. pre-commit钩子配置
    • 配置clang-format自动格式化C/C++代码
    • 配置OAT合规性检查(文件类型和许可证头)
    • 在commit阶段自动触发检查
  3. OAT检查脚本
    • 自动环境检测和依赖安装(Java/Maven)
    • 支持Linux/macOS/Windows多平台
    • 增量扫描模式,仅检查待提交文件
    • 自动处理CRLF换行符问题
    • 生成简洁的检查报告

使用方式

  1. 安装pre-commit框架:
    pip install pre-commit
    
  2. 在项目根目录安装钩子:
    pre-commit install
    
  3. 正常提交代码,钩子会自动执行:
    git add .
    git commit -m "your message"
    
  4. 手动运行检查:
    pre-commit run --all-files
    

关联的Issue

关联的Issue #387

测试

  • 在Linux/macOS/Windows环境下测试pre-commit钩子
  • 验证Java/Maven自动安装功能
  • 验证OAT扫描功能正常工作
  • 测试增量扫描和全量扫描模式

文档更新

NA

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 maohp_hw 的贡献)
maohp_hwmaohp_hw成员
4月1日 创建了 pull request,commit 0a8a3581
CANN-robot
CANN-robot成员
4月1日 评论:

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
impl/c_api bianque, xun_zhuge, pangfd (3/2) pangfd (1/1)
impl/experimental/tensor_api pangfd, bianque, xun_zhuge (3/2) pangfd (1/1)
include/c_api wuzhaolin, bianque, xun_zhuge (3/2) wuzhaolin (1/1)
repo-cann/asc-devkit bianque, ookkkkoo1122, xun_zhuge (3/2) ookkkkoo1122, xun_zhuge (2/1)
scripts xun_zhuge, bianque (2/2) xun_zhuge (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

haipingmao, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
4月1日 将zengjuan,zhanghao_0689,yanqingshang,wulinyu,zhuliangying,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,wqtshg_wt,yangbinhua,gao_dafa,chenyiyuan,xun_zhuge,ookkkkoo1122,bianque,houyuyang,shi_nanxiang,wuyang_hw,ascendhjh,DragonBornHD84,jiangZD设为评审人
CANN-robotCANN-robot成员
4月1日 添加了label:cann-cla/yes
CANN-robotCANN-robot成员
4月1日 将zengjuan,zhanghao_0689,yanqingshang,wulinyu,zhuliangying,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,wqtshg_wt,yangbinhua,gao_dafa,chenyiyuan,xun_zhuge,ookkkkoo1122,bianque,houyuyang,shi_nanxiang,wuyang_hw,ascendhjh,DragonBornHD84,jiangZD设为审查人
此处折叠了109条消息 查看更多
CANN-robotCANN-robot成员
4月2日 添加了label:lgtm
wuzhaolin成员
4月2日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
4月2日 添加了label:approved
CANN-robot
CANN-robot成员
4月2日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: pangfd, wuzhaolin, xun_zhuge, ookkkkoo1122.
Reviewers who wrote a comment of /lgtm are: xun_zhuge, pangfd, bianque, wuzhaolin, ookkkkoo1122.

likedislike
CANN-robotCANN-robot成员
4月2日 合入了pull request