From ab52a74539bfe51a639e988bd7494de749c0e9d1 Mon Sep 17 00:00:00 2001 From: Lingjie Li Date: Thu, 1 Feb 2024 12:37:57 +0800 Subject: [PATCH] [build] add static check workflow --- .clang-format | 2 +- .clang-tidy | 12 ------ .clangd | 5 +++ .github/workflows/static.yml | 74 ++++++++++++++++++++++++++++++++++++ csrc/diopi_helper.h | 14 ++++--- csrc/extensions.cpp | 10 ++--- csrc/pybind_type_cast.h | 22 +++++------ 7 files changed, 104 insertions(+), 35 deletions(-) create mode 100644 .clangd create mode 100644 .github/workflows/static.yml diff --git a/.clang-format b/.clang-format index ed68e746..0b9508ff 100644 --- a/.clang-format +++ b/.clang-format @@ -18,7 +18,7 @@ IncludeCategories: - Regex: '^("|<)Python\.h' Priority: 50 CaseSensitive: false - - Regex: '^("|<)(frameobject|structmember)\.h' + - Regex: '^("|<)(frameobject|structmember|listobject)\.h' Priority: 50 SortPriority: 51 CaseSensitive: false diff --git a/.clang-tidy b/.clang-tidy index b0dfbca6..5a1cd5c7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,30 +2,19 @@ Checks: ' bugprone-*, -bugprone-easily-swappable-parameters, --bugprone-reserved-identifier, clang-analyzer-*, clang-diagnostic-*, cppcoreguidelines-*, --cppcoreguidelines-macro-usage, --cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, --cppcoreguidelines-pro-type-reinterpret-cast, --cppcoreguidelines-pro-type-static-cast-downcast, --cppcoreguidelines-pro-type-union-access, --cppcoreguidelines-pro-type-vararg, --cppcoreguidelines-special-member-functions, --cppcoreguidelines-non-private-member-variables-in-classes, hicpp-exception-baseclass, hicpp-avoid-goto, google-* misc-unused-alias-decls, misc-unused-using-decls, modernize-*, --modernize-concat-nested-namespaces, -modernize-use-trailing-return-type, --modernize-use-nodiscard, performance-*, readability-*, -readability-identifier-length, @@ -34,7 +23,6 @@ readability-*, ' HeaderFilterRegex: '.*' AnalyzeTemporaryDtors: false -#WarningsAsErrors: '*' FormatStyle: file CheckOptions: - key: cppcoreguidelines-avoid-do-while.IgnoreMacros diff --git a/.clangd b/.clangd new file mode 100644 index 00000000..654de907 --- /dev/null +++ b/.clangd @@ -0,0 +1,5 @@ +CompileFlags: + Remove: -fabi* +Diagnostics: + UnusedIncludes: Strict + MissingIncludes: Strict diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 00000000..9560ced3 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,74 @@ +name: static checks on sco + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +env: + ENV_SOURCE: /mnt/cache/share/platform/env/dipu_latest + PROXY_SOURCE: /mnt/cache/share/platform/env/proxy + WORKSPACE: /mnt/cache/share/deeplinkci/github/${{ github.repository }}/${{ github.run_number }} + CODE_SOURCE: source + CLANGD_TIDY_SOURCE: clangd-tidy + CLANGD_EXEC: /mnt/cache/share/platform/dep/clang-17/bin/clangd + +concurrency: + group: ${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + checkout-code: + name: checkout code + runs-on: tps-sco-ci + steps: + - name: prepare workspace + run: | + set -euxo pipefail + mkdir -p ${WORKSPACE} && cd ${WORKSPACE} && pwd + - name: checkout code + run: | + set -euo pipefail + source ${PROXY_SOURCE} + set -x + cd ${WORKSPACE} && pwd + if [[ -d ${CODE_SOURCE} ]]; then + rm -rf ${CODE_SOURCE} + fi + if [ -n "${{ github.event.pull_request.head.repo.full_name }}" ] && [[ ! "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then + git clone ${{ github.event.pull_request.head.repo.clone_url }} ${CODE_SOURCE} + cd ${CODE_SOURCE} && git checkout ${{ github.event.pull_request.head.sha }} + git remote add mainrepo https://github.com/${{ github.repository }}.git + git fetch mainrepo && git merge --no-edit mainrepo/${{ github.base_ref }} + else + git clone ${{ github.event.repository.clone_url }} ${CODE_SOURCE} && cd ${CODE_SOURCE} + if [ "${{ github.event_name }}" == "pull_request" ]; then + git checkout ${{ github.event.pull_request.head.sha }} && git merge --no-edit ${{ github.base_ref }} + else + git checkout ${{ github.sha }} + fi + fi + git submodule update --init --recursive + - name: checkout clangd-tidy + run: | + set -euo pipefail + source ${PROXY_SOURCE} + set -x + cd ${WORKSPACE}/${CODE_SOURCE} && pwd + git -c advice.detachedHead=false clone --depth 1 -b v0.1.2 https://github.com/lljbash/clangd-tidy.git ${CLANGD_TIDY_SOURCE} + + build-and-tidy: + name: build + runs-on: tps-sco-ci + needs: [checkout-code] + steps: + - name: build + run: | + set -euxo pipefail + srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && cd ${WORKSPACE}/${CODE_SOURCE} && pwd && pip install -e . -v -t install" + - name: clang-tidy + run: | + set -euxo pipefail + srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && cd ${WORKSPACE}/${CODE_SOURCE} && pwd && git ls-files csrc | xargs ${CLANGD_TIDY_SOURCE}/clangd-tidy --clangd-executable=${CLANGD_EXEC} -j4" diff --git a/csrc/diopi_helper.h b/csrc/diopi_helper.h index eb45398e..9756a0b3 100644 --- a/csrc/diopi_helper.h +++ b/csrc/diopi_helper.h @@ -4,20 +4,25 @@ #define DIOPI_HELPER_H_WTUAZNIC #include +#include #include #include +#include #include #include +#include #include -#include + +#include +#include #include #include +#include #include -namespace dipu { -namespace dipu_ext { +namespace dipu::dipu_ext { namespace type_traits { @@ -121,7 +126,6 @@ void callDiopi(const DiopiFunc& diopi_func, Args&&... args) { callDiopiKeepContext(diopi_func, std::forward(args)...); } -} // namespace dipu_ext -} // namespace dipu +} // namespace dipu::dipu_ext #endif /* end of include guard: DIOPI_HELPER_H_WTUAZNIC */ diff --git a/csrc/extensions.cpp b/csrc/extensions.cpp index 7661c01e..8b4c6389 100644 --- a/csrc/extensions.cpp +++ b/csrc/extensions.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -14,7 +15,8 @@ #include #include // IWYU pragma: keep -#include +#include +#include #include @@ -23,8 +25,7 @@ #include "diopi_helper.h" #include "pybind_type_cast.h" -namespace dipu { -namespace dipu_ext { +namespace dipu::dipu_ext { namespace { @@ -297,5 +298,4 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { } } -} // namespace dipu_ext -} // namespace dipu +} // namespace dipu::dipu_ext diff --git a/csrc/pybind_type_cast.h b/csrc/pybind_type_cast.h index 94701d14..6d128981 100644 --- a/csrc/pybind_type_cast.h +++ b/csrc/pybind_type_cast.h @@ -5,24 +5,23 @@ #include -#include +#include #include -#include -#include -#include +#include +#include +#include +#include +#include -namespace dipu { -namespace dipu_ext { +namespace dipu::dipu_ext { using IntArray = std::vector; using OptionalIntArray = c10::optional; -} // namespace dipu_ext -} // namespace dipu +} // namespace dipu::dipu_ext -namespace pybind11 { -namespace detail { +namespace pybind11::detail { namespace py = pybind11; @@ -44,7 +43,6 @@ struct type_caster { } }; -} // namespace detail -} // namespace pybind11 +} // namespace pybind11::detail #endif /* end of include guard: PYBIND_TYPE_CAST_H_PXMGELYW */