华为CANN/hcomm pre-commit工具指南 pre-commit Tool Guide【免费下载链接】hcommHCOMMHuawei Communication是HCCL的通信基础库提供通信域以及通信资源的管理能力。项目地址: https://gitcode.com/cann/hcommOverviewpre-commit is a Git Hooks framework that automatically runs code checking and formatting tools duringgit commit. This project is configured with the following checks:HookFunctionDescriptionclang-formatC and C code formattingAutomatically formats code to maintain consistent styleOAT CheckOpen source compliance checkDetects license headers and prevents binary file submissionRequirementsGit: 2.0Python: 3.8clang-format: 14.0 (code formatting tool)Java: 17 (required for OAT tool, can be installed automatically)Maven: 3.6 (required for OAT tool, can be installed automatically)Installation Steps1. Install pre-commit# Option 1: Using pip pip install pre-commit # Option 2: Using system package manager (Ubuntu or Debian) sudo apt install pre-commit2. Install Dependency Tools# Ubuntu or Debian sudo apt install clang-format openjdk-17-jre maven # macOS brew install clang-format openjdk17 maven3. Install Git Hooks in the Project Path# Navigate to the repository root directory cd /path/to/hcomm pre-commit installA successful installation displays:pre-commit installed at .git/hooks/pre-commitUsageAutomatic Checking (Recommended)Each time you executegit commit, pre-commit automatically runs checks:git add . git commit -m your commit messageExample output:clang-format.............................................................Passed OAT Compliance Check.....................................................PassedRunning Checks Manually# Run all checks pre-commit run # Run a specific type of check pre-commit run clang-format pre-commit run oat-check # Check all files (not limited to the staging area) pre-commit run --all-filesSkipping Checks (Emergency)git commit --no-verify -m emergency fixNote: Use this only in emergencies. During normal development, ensure all checks pass.Check Descriptions1. clang-formatAutomatically formats C and C code according to the .clang-format configuration in the project root directory.2. OAT Compliance CheckOAT (Open Source Audit Tool) checks open source compliance:Check ItemDescriptionLicense header checkEnsures source files contain the CANN License headerBinary file checkPrevents submission of binary filesArchive file checkPrevents submission of archive files such as zip and tarThe first time the OAT check script runs, it automatically:Detects or installs Java 17Detects or installs MavenClones and compiles the tools_oat tool (approximately 1 to 2 minutes)Frequently Asked QuestionsQ1: The OAT check is slow during the first commitCause: The first run needs to clone and compile the OAT tool.Solution: This is normal. Subsequent commits use the cached JAR and are much faster.Related Documentspre-commit Official Documentationclang-format ConfigurationOAT Toolpre-commit Integration Guide for Code Repositories (Chinese)【免费下载链接】hcommHCOMMHuawei Communication是HCCL的通信基础库提供通信域以及通信资源的管理能力。项目地址: https://gitcode.com/cann/hcomm创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考