Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------

BasedOnStyle: Google
DerivePointerAlignment: false
ColumnLimit: 110
PointerAlignment: Left
37 changes: 37 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------

# Based on the .clang-tidy configuration in hw-native-sys/pypto,
# adapted to the directory layout of this repository.
# -clang-analyzer-unix.Malloc is disabled due to false positives.
Checks: >
bugprone-*,
clang-analyzer-*,
clang-diagnostic-*,
google-*,
modernize-*,
performance-*,
portability-*,
misc-include-cleaner,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The misc-include-cleaner check is very strict and often requires manual annotations (such as // IWYU pragma: keep) to handle false positives where it incorrectly identifies an include as unused or missing. If the codebase has not been prepared for this check, it may generate a large number of errors. Consider disabling it until the initial cleanup is complete.

-bugprone-easily-swappable-parameters,
-clang-analyzer-unix.Malloc,
-google-build-using-namespace,
-modernize-avoid-c-arrays,
-modernize-concat-nested-namespaces,
-modernize-return-braced-init-list,
-modernize-use-auto,
-modernize-use-trailing-return-type,
-performance-enum-size,
-performance-inefficient-string-concatenation,
-portability-template-virtual-member-function

WarningsAsErrors: "*"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Enabling WarningsAsErrors: "*" on a new configuration that has not been tested locally (as noted in the PR description) is highly likely to break the CI build. It is recommended to first introduce the configuration with warnings only, fix existing violations, and then enable this option to maintain a clean baseline.

WarningsAsErrors: ""

HeaderFilterRegex: '.*(include[/\\]|lib[/\\]).*\.(h|hpp)$'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current HeaderFilterRegex is too broad because the leading .* followed by include or lib will match system headers (e.g., /usr/include/stdio.h), causing clang-tidy to report diagnostics for external code. Combined with WarningsAsErrors: "*", this will likely break the build. It is better to use a regex that specifically targets the project's own header directories by including unique path components like PTO or CAPI.

HeaderFilterRegex: '.*(include|lib)[/\\].*(PTO|CAPI|Bindings)[/\\].*\.(h|hpp)$'

HeaderFileExtensions: ["h", "hpp"]
ImplementationFileExtensions: ["cpp", "cc", "c"]
54 changes: 54 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------

# Adapted from hw-native-sys/pypto for this repository.
# Project-specific hooks from pypto are intentionally omitted here when the
# supporting scripts or config files do not exist in PTOAS yet.

default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
exclude: ^docs/images/
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v21.1.0
hooks:
- id: clang-format
types_or: [c++, c]
files: ^(include/|lib/|tools/).*\.(h|hpp|c|cc|cpp)$
exclude: ^tools/ptobc/generated/

- repo: https://github.com/cpplint/cpplint
rev: 2.0.0
hooks:
- id: cpplint
files: ^(include/|lib/|tools/).*\.(h|hpp|c|cc|cpp)$
exclude: ^tools/ptobc/generated/
args:
- --root=.
- --linelength=110
- --filter=-whitespace/parens,-whitespace/indent_namespace,-runtime/references

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.8
hooks:
- id: ruff-check
files: ^(\.github/scripts/|python/).*\.(py|pyi)$
args: [--fix]
- id: ruff-format
files: ^(\.github/scripts/|python/).*\.(py|pyi)$
args: [--line-length=110]
Loading