From b01f13b9b1e93371f1d059d4596a9c23a585ad1b Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Fri, 21 Jul 2023 21:44:06 +0800 Subject: [PATCH 01/15] add clang-tidy check in the end of PR-CI-Build --- paddle/scripts/paddle_build.sh | 50 +++++++++++++++++++++++++++- tools/dockerfile/Dockerfile.ubuntu | 2 +- tools/dockerfile/Dockerfile.ubuntu18 | 2 +- tools/dockerfile/Dockerfile.ubuntu20 | 2 +- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index ef2cff21c4436..69aed76d6450a 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3238,6 +3238,53 @@ function trt_convert_test() { fi } +function clang-tidy_check() { + set +x + + diff_files=$(git diff --name-only --diff-filter=ACMR ${BRANCH}) + num_diff_files=$(echo "$diff_files" | wc -l) + echo -e "diff files between pr and ${BRANCH}:\n${diff_files}" + + echo "Checking code style by pre-commit ..." + startTime_s=`date +%s` + pre-commit run clang-tidy --files ${diff_files};check_error=$? + endTime_s=`date +%s` + [ -n "$startTime_firstBuild" ] && startTime_s=$startTime_firstBuild + echo "Files Num: $[ $num_diff_files ]" + echo "Check Time: $[ $endTime_s - $startTime_s ]s" + + if test ! -z "$(git diff)"; then + echo -e '\n************************************************************************************' + echo -e "These files have been formatted by code format hook. You should use pre-commit to \ + format them before git push." + echo -e '************************************************************************************\n' + git diff 2>&1 + fi + + echo -e '\n************************************************************************************' + if [ ${check_error} != 0 ];then + echo "Your PR code style check failed." + echo "Please install pre-commit locally and set up git hook scripts:" + echo "" + echo " pip install pre-commit==2.17.0" + echo " pre-commit install" + echo "" + if [[ $num_diff_files -le 100 ]];then + echo "Then, run pre-commit to check codestyle issues in your PR:" + echo "" + echo " pre-commit run --files" $(echo ${diff_files} | tr "\n" " ") + echo "" + fi + echo "For more information, please refer to our codestyle check guide:" + echo "https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/codestyle_check_guide_cn.html" + else + echo "Your PR code style check passed." + fi + echo -e '************************************************************************************\n' + + exit ${check_error} +} + function build_pr_and_develop() { run_setup ${PYTHON_ABI:-""} bdist_wheel ${parallel_number} if [ ! -d "${PADDLE_ROOT}/build/python/dist/" ]; then @@ -3273,7 +3320,8 @@ function build_pr_and_develop() { mkdir ${PADDLE_ROOT}/build/dev_whl && cp ${PADDLE_ROOT}/build/python/dist/*.whl ${PADDLE_ROOT}/build/dev_whl fi generate_api_spec "$1" "DEV" - + + clang-tidy_check } function build_develop() { diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index fd7e476f710ab..74ab4b6bac7bb 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -28,7 +28,7 @@ RUN apt-get update && \ wget unzip unrar tar xz-utils bzip2 gzip coreutils ntp \ curl sed grep graphviz libjpeg-dev zlib1g-dev \ python-matplotlib \ - automake locales swig \ + automake locales swig clang-tidy-10 \ liblapack-dev liblapacke-dev \ net-tools libtool module-init-tools && \ apt-get clean -y diff --git a/tools/dockerfile/Dockerfile.ubuntu18 b/tools/dockerfile/Dockerfile.ubuntu18 index 41f8f97db0018..d0d5e6713b594 100644 --- a/tools/dockerfile/Dockerfile.ubuntu18 +++ b/tools/dockerfile/Dockerfile.ubuntu18 @@ -28,7 +28,7 @@ RUN apt-get update --allow-unauthenticated && \ apt-get update && \ apt-get install -y curl wget vim git unzip unrar tar xz-utils libssl-dev bzip2 gzip \ coreutils ntp language-pack-zh-hans python-qt4 libsm6 libxext6 libxrender-dev libgl1-mesa-glx \ - bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool module-init-tools + bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool module-init-tools clang-tidy-10 # Downgrade gcc&&g++ diff --git a/tools/dockerfile/Dockerfile.ubuntu20 b/tools/dockerfile/Dockerfile.ubuntu20 index 98bc6ec80731a..3bab5d0e121fe 100644 --- a/tools/dockerfile/Dockerfile.ubuntu20 +++ b/tools/dockerfile/Dockerfile.ubuntu20 @@ -28,7 +28,7 @@ RUN apt-get update --allow-unauthenticated && \ apt-get update && \ apt-get install -y curl wget vim git unzip unrar tar xz-utils libssl-dev bzip2 gzip \ coreutils ntp language-pack-zh-hans libsm6 libxext6 libxrender-dev libgl1-mesa-glx \ - bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod + bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod clang-tidy-10 # Downgrade gcc&&g++ From 01ecc486e1c2081370ab343f0fc67ede6ba69633 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Sun, 23 Jul 2023 22:17:46 +0800 Subject: [PATCH 02/15] remove clang-tidy in ci --- tools/dockerfile/Dockerfile.ubuntu | 2 +- tools/dockerfile/Dockerfile.ubuntu18 | 2 +- tools/dockerfile/Dockerfile.ubuntu20 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index 74ab4b6bac7bb..7a3e6e6870252 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -28,7 +28,7 @@ RUN apt-get update && \ wget unzip unrar tar xz-utils bzip2 gzip coreutils ntp \ curl sed grep graphviz libjpeg-dev zlib1g-dev \ python-matplotlib \ - automake locales swig clang-tidy-10 \ + automake locales swig \ liblapack-dev liblapacke-dev \ net-tools libtool module-init-tools && \ apt-get clean -y diff --git a/tools/dockerfile/Dockerfile.ubuntu18 b/tools/dockerfile/Dockerfile.ubuntu18 index d0d5e6713b594..41f8f97db0018 100644 --- a/tools/dockerfile/Dockerfile.ubuntu18 +++ b/tools/dockerfile/Dockerfile.ubuntu18 @@ -28,7 +28,7 @@ RUN apt-get update --allow-unauthenticated && \ apt-get update && \ apt-get install -y curl wget vim git unzip unrar tar xz-utils libssl-dev bzip2 gzip \ coreutils ntp language-pack-zh-hans python-qt4 libsm6 libxext6 libxrender-dev libgl1-mesa-glx \ - bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool module-init-tools clang-tidy-10 + bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool module-init-tools # Downgrade gcc&&g++ diff --git a/tools/dockerfile/Dockerfile.ubuntu20 b/tools/dockerfile/Dockerfile.ubuntu20 index 3bab5d0e121fe..98bc6ec80731a 100644 --- a/tools/dockerfile/Dockerfile.ubuntu20 +++ b/tools/dockerfile/Dockerfile.ubuntu20 @@ -28,7 +28,7 @@ RUN apt-get update --allow-unauthenticated && \ apt-get update && \ apt-get install -y curl wget vim git unzip unrar tar xz-utils libssl-dev bzip2 gzip \ coreutils ntp language-pack-zh-hans libsm6 libxext6 libxrender-dev libgl1-mesa-glx \ - bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod clang-tidy-10 + bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod # Downgrade gcc&&g++ From 8240f3e3895a33aa20a49188d07adba28c31844f Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Tue, 25 Jul 2023 22:20:07 +0800 Subject: [PATCH 03/15] add clang-tidy in ci image --- tools/dockerfile/Dockerfile.ubuntu | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index 7a3e6e6870252..e02711a885531 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -28,7 +28,7 @@ RUN apt-get update && \ wget unzip unrar tar xz-utils bzip2 gzip coreutils ntp \ curl sed grep graphviz libjpeg-dev zlib1g-dev \ python-matplotlib \ - automake locales swig \ + automake locales swig \ liblapack-dev liblapacke-dev \ net-tools libtool module-init-tools && \ apt-get clean -y @@ -198,6 +198,9 @@ RUN wget -q https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/binutils/ RUN apt-get install libprotobuf-dev -y +# Install clang-tidy +RUN apt-get install clang-tidy-10 -y + # Configure OpenSSH server. c.f. https://docs.docker.com/engine/examples/running_ssh_service RUN mkdir /var/run/sshd && echo 'root:root' | chpasswd && sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config && sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config CMD source ~/.bashrc From eb1491117eae1c79153d13028fc167dfbb95c61b Mon Sep 17 00:00:00 2001 From: Zhenghai Zhang <1719571694@qq.com> Date: Wed, 26 Jul 2023 15:11:02 +0800 Subject: [PATCH 04/15] fix bug --- .pre-commit-config.yaml | 1 + tools/dockerfile/Dockerfile.ubuntu | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c3162f1839b98..ab3c485fec149 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -114,6 +114,7 @@ repos: files: \.(c|cc|cxx|cpp|h|hpp|hxx)$ args: - -p=build/ + - -clang-tidy-binary=clang-tidy - -extra-arg=-Wno-unknown-warning-option - -extra-arg=-Wno-pessimizing-move - -extra-arg=-Wno-braced-scalar-init diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index e02711a885531..943f2ab548c95 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -168,9 +168,9 @@ RUN pip3.7 --no-cache-dir install pytest astroid isort && \ RUN pip3.7 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ pip3.8 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ pip3.9 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ - pip3.7 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \ - pip3.8 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \ - pip3.9 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 + pip3.7 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 && \ + pip3.8 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 && \ + pip3.9 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 RUN pip3.7 --no-cache-dir install coverage && \ pip3.8 --no-cache-dir install coverage && \ @@ -198,9 +198,6 @@ RUN wget -q https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/binutils/ RUN apt-get install libprotobuf-dev -y -# Install clang-tidy -RUN apt-get install clang-tidy-10 -y - # Configure OpenSSH server. c.f. https://docs.docker.com/engine/examples/running_ssh_service RUN mkdir /var/run/sshd && echo 'root:root' | chpasswd && sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config && sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config CMD source ~/.bashrc From 1dd88fc497d7e7eb118289c0ce8a969df82dd9b5 Mon Sep 17 00:00:00 2001 From: Zhenghai Zhang <1719571694@qq.com> Date: Thu, 27 Jul 2023 10:27:37 +0800 Subject: [PATCH 05/15] fix bug --- paddle/scripts/paddle_build.sh | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 69aed76d6450a..fa989d79c142d 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3245,7 +3245,7 @@ function clang-tidy_check() { num_diff_files=$(echo "$diff_files" | wc -l) echo -e "diff files between pr and ${BRANCH}:\n${diff_files}" - echo "Checking code style by pre-commit ..." + echo "Checking code style by clang-tidy ..." startTime_s=`date +%s` pre-commit run clang-tidy --files ${diff_files};check_error=$? endTime_s=`date +%s` @@ -3253,32 +3253,24 @@ function clang-tidy_check() { echo "Files Num: $[ $num_diff_files ]" echo "Check Time: $[ $endTime_s - $startTime_s ]s" - if test ! -z "$(git diff)"; then - echo -e '\n************************************************************************************' - echo -e "These files have been formatted by code format hook. You should use pre-commit to \ - format them before git push." - echo -e '************************************************************************************\n' - git diff 2>&1 - fi - echo -e '\n************************************************************************************' if [ ${check_error} != 0 ];then - echo "Your PR code style check failed." - echo "Please install pre-commit locally and set up git hook scripts:" + echo "Your PR code style clang-tidy check failed." + echo "Please install clang-tidy locally:" + echo "" + echo " pip install clang-tidy==15.0.2.1" echo "" - echo " pip install pre-commit==2.17.0" - echo " pre-commit install" echo "" if [[ $num_diff_files -le 100 ]];then - echo "Then, run pre-commit to check codestyle issues in your PR:" + echo "After the build is completed, run clang-tidy to check codestyle issues in your PR:" echo "" - echo " pre-commit run --files" $(echo ${diff_files} | tr "\n" " ") + echo " pre-commit run clang-tidy --files" $(echo ${diff_files} | tr "\n" " ") echo "" fi echo "For more information, please refer to our codestyle check guide:" echo "https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/codestyle_check_guide_cn.html" else - echo "Your PR code style check passed." + echo "Your PR code style clang-tidy check passed." fi echo -e '************************************************************************************\n' From e660c3ff3aece0550b6b6f96e598b7ec3819d338 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Tue, 1 Aug 2023 23:06:07 +0800 Subject: [PATCH 06/15] update dockerfile --- tools/dockerfile/Dockerfile.ubuntu18 | 6 +++--- tools/dockerfile/Dockerfile.ubuntu20 | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/dockerfile/Dockerfile.ubuntu18 b/tools/dockerfile/Dockerfile.ubuntu18 index 41f8f97db0018..059d94eb940ec 100644 --- a/tools/dockerfile/Dockerfile.ubuntu18 +++ b/tools/dockerfile/Dockerfile.ubuntu18 @@ -129,9 +129,9 @@ RUN pip3.7 --no-cache-dir install --upgrade pip && \ RUN pip3.7 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ pip3.8 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ pip3.9 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ - pip3.7 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \ - pip3.8 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \ - pip3.9 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 + pip3.7 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 && \ + pip3.8 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 && \ + pip3.9 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 COPY ./python/requirements.txt /root/ RUN pip3.7 --no-cache-dir install -r /root/requirements.txt && \ diff --git a/tools/dockerfile/Dockerfile.ubuntu20 b/tools/dockerfile/Dockerfile.ubuntu20 index 3a11f530c1416..3c9eb1719fd2a 100644 --- a/tools/dockerfile/Dockerfile.ubuntu20 +++ b/tools/dockerfile/Dockerfile.ubuntu20 @@ -141,10 +141,10 @@ RUN pip3.7 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ pip3.8 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ pip3.9 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ pip3.10 --no-cache-dir install pre-commit==2.17.0 pylint==2.12.0 && \ - pip3.7 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \ - pip3.8 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \ - pip3.9 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \ - pip3.10 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 + pip3.7 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 && \ + pip3.8 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 && \ + pip3.9 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 && \ + pip3.10 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 clang-tidy==15.0.2.1 COPY ./python/requirements.txt /root/ RUN pip3.7 --no-cache-dir install -r /root/requirements.txt && \ From 822b9f5871c0e5ca98ce9ea4b7e8c353b06af036 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Fri, 4 Aug 2023 12:08:06 +0800 Subject: [PATCH 07/15] fix bug --- paddle/scripts/paddle_build.sh | 44 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index fa989d79c142d..fb91035aad22d 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3240,41 +3240,35 @@ function trt_convert_test() { function clang-tidy_check() { set +x + trap 'abort' 0 + set -e - diff_files=$(git diff --name-only --diff-filter=ACMR ${BRANCH}) - num_diff_files=$(echo "$diff_files" | wc -l) - echo -e "diff files between pr and ${BRANCH}:\n${diff_files}" + clang-tidy --version - echo "Checking code style by clang-tidy ..." + num_diff_files=$(git diff --numstat ${BRANCH} | wc -l) + commit_files=on startTime_s=`date +%s` - pre-commit run clang-tidy --files ${diff_files};check_error=$? + for file_name in `git diff --numstat ${BRANCH} |awk '{print $NF}'`;do + if ! pre-commit run clang-tidy --files $file_name ; then + commit_files=off + fi + done endTime_s=`date +%s` [ -n "$startTime_firstBuild" ] && startTime_s=$startTime_firstBuild - echo "Files Num: $[ $num_diff_files ]" - echo "Check Time: $[ $endTime_s - $startTime_s ]s" - - echo -e '\n************************************************************************************' - if [ ${check_error} != 0 ];then + if [ $commit_files == 'off' ];then echo "Your PR code style clang-tidy check failed." - echo "Please install clang-tidy locally:" - echo "" - echo " pip install clang-tidy==15.0.2.1" - echo "" - echo "" - if [[ $num_diff_files -le 100 ]];then - echo "After the build is completed, run clang-tidy to check codestyle issues in your PR:" - echo "" - echo " pre-commit run clang-tidy --files" $(echo ${diff_files} | tr "\n" " ") - echo "" - fi - echo "For more information, please refer to our codestyle check guide:" - echo "https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/codestyle_check_guide_cn.html" + echo "File Count: $[ $num_diff_files ]" + echo "Check Time: $[ $endTime_s - $startTime_s ]s" + git diff 2>&1 + exit 4 else + echo "File Count: $[ $num_diff_files ]" + echo "Check Time: $[ $endTime_s - $startTime_s ]s" echo "Your PR code style clang-tidy check passed." fi - echo -e '************************************************************************************\n' - exit ${check_error} + trap : 0 + set -x } function build_pr_and_develop() { From 21cc5df60e72f3ee1b75e07d9aece34e25bc8429 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Mon, 27 Nov 2023 23:43:18 +0800 Subject: [PATCH 08/15] =?UTF-8?q?Revert=20"[Fix]=20=E4=BF=AE=E6=94=B9logge?= =?UTF-8?q?r=E5=90=8D=E7=A7=B0=E9=81=BF=E5=85=8D=E5=86=B2=E7=AA=81=20(#566?= =?UTF-8?q?87)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b17bcb7f2fd36c59488ab028e6a57783dbec232f. --- tools/sampcd_processor_utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/sampcd_processor_utils.py b/tools/sampcd_processor_utils.py index d7b0a660f1639..e339499213b40 100644 --- a/tools/sampcd_processor_utils.py +++ b/tools/sampcd_processor_utils.py @@ -23,9 +23,7 @@ import time import typing -logger = logging.getLogger(__name__) -logger.propagate = False - +logger = logging.getLogger() if logger.handlers: console = logger.handlers[ 0 From 57764815ebf9275138967df5cb8c46abd4d1645e Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Tue, 12 Dec 2023 21:48:14 +0800 Subject: [PATCH 09/15] test 10 files clang-tidy ci time --- .clang-tidy | 294 +++++++++--------- .../ir/mkldnn/cpu_quantize_pass_tester.cc | 2 +- paddle/fluid/framework/ir/quantize_helper.cc | 2 +- .../new_executor/interpreter/plan.cc | 2 +- paddle/fluid/pir/transforms/inplace_pass.cc | 2 +- .../profiler/dump/serialization_logger.cc | 2 +- paddle/phi/kernels/funcs/jit/test.cc | 2 +- paddle/scripts/paddle_build.sh | 22 +- paddle/utils/string/split_test.cc | 2 +- test/cpp/fluid/framework/prune_test.cc | 4 +- .../reader/reader_blocking_queue_test.cc | 4 +- test/cpp/inference/api/api_tester.cc | 2 +- 12 files changed, 166 insertions(+), 174 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index cbe5b04fda95e..479dafb29981c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,206 +1,206 @@ --- Checks: ' bugprone-argument-comment, --bugprone-assert-side-effect, --bugprone-bad-signal-to-kill-thread, --bugprone-bool-pointer-implicit-conversion, +bugprone-assert-side-effect, +bugprone-bad-signal-to-kill-thread, +bugprone-bool-pointer-implicit-conversion, bugprone-branch-clone, bugprone-copy-constructor-init, --bugprone-dangling-handle, --bugprone-dynamic-static-initializers, +bugprone-dangling-handle, +bugprone-dynamic-static-initializers, bugprone-exception-escape, --bugprone-fold-init-type, --bugprone-forwarding-reference-overload, --bugprone-inaccurate-erase, +bugprone-fold-init-type, +bugprone-forwarding-reference-overload, +bugprone-inaccurate-erase, bugprone-incorrect-roundings, --bugprone-infinite-loop, +bugprone-infinite-loop, bugprone-integer-division, --bugprone-macro-repeated-side-effects, --bugprone-misplaced-operator-in-strlen-in-alloc, +bugprone-macro-repeated-side-effects, +bugprone-misplaced-operator-in-strlen-in-alloc, bugprone-misplaced-widening-cast, --bugprone-move-forwarding-reference, --bugprone-multiple-statement-macro, +bugprone-move-forwarding-reference, +bugprone-multiple-statement-macro, bugprone-narrowing-conversions, --bugprone-not-null-terminated-result, --bugprone-parent-virtual-call, --bugprone-posix-return, +bugprone-not-null-terminated-result, +bugprone-parent-virtual-call, +bugprone-posix-return, bugprone-signed-char-misuse, --bugprone-sizeof-container, --bugprone-sizeof-expression, --bugprone-string-constructor, --bugprone-string-integer-assignment, --bugprone-string-literal-with-embedded-nul, --bugprone-suspicious-enum-usage, --bugprone-suspicious-memset-usage, +bugprone-sizeof-container, +bugprone-sizeof-expression, +bugprone-string-constructor, +bugprone-string-integer-assignment, +bugprone-string-literal-with-embedded-nul, +bugprone-suspicious-enum-usage, +bugprone-suspicious-memset-usage, bugprone-suspicious-missing-comma, --bugprone-suspicious-semicolon, --bugprone-suspicious-string-compare, --bugprone-terminating-continue, --bugprone-throw-keyword-missing, --bugprone-too-small-loop-variable, --bugprone-undefined-memory-manipulation, --bugprone-undelegated-constructor, +bugprone-suspicious-semicolon, +bugprone-suspicious-string-compare, +bugprone-terminating-continue, +bugprone-throw-keyword-missing, +bugprone-too-small-loop-variable, +bugprone-undefined-memory-manipulation, +bugprone-undelegated-constructor, bugprone-unhandled-self-assignment, bugprone-unused-raii, bugprone-unused-return-value, bugprone-use-after-move, --bugprone-virtual-near-miss, --clang-analyzer-apiModeling.StdCLibraryFunctions, --clang-analyzer-apiModeling.TrustNonnull, --clang-analyzer-apiModeling.google.GTest, --clang-analyzer-apiModeling.llvm.CastValue, --clang-analyzer-apiModeling.llvm.ReturnValue, +bugprone-virtual-near-miss, +clang-analyzer-apiModeling.StdCLibraryFunctions, +clang-analyzer-apiModeling.TrustNonnull, +clang-analyzer-apiModeling.google.GTest, +clang-analyzer-apiModeling.llvm.CastValue, +clang-analyzer-apiModeling.llvm.ReturnValue, clang-analyzer-core.CallAndMessage, --clang-analyzer-core.DivideZero, --clang-analyzer-core.DynamicTypePropagation, +clang-analyzer-core.DivideZero, +clang-analyzer-core.DynamicTypePropagation, clang-analyzer-core.NonNullParamChecker, --clang-analyzer-core.NonnilStringConstants, --clang-analyzer-core.NullDereference, --clang-analyzer-core.StackAddrEscapeBase, --clang-analyzer-core.StackAddressEscape, +clang-analyzer-core.NonnilStringConstants, +clang-analyzer-core.NullDereference, +clang-analyzer-core.StackAddrEscapeBase, +clang-analyzer-core.StackAddressEscape, clang-analyzer-core.UndefinedBinaryOperatorResult, --clang-analyzer-core.VLASize, --clang-analyzer-core.builtin.BuiltinFunctions, --clang-analyzer-core.builtin.NoReturnFunctions, --clang-analyzer-core.uninitialized.ArraySubscript, +clang-analyzer-core.VLASize, +clang-analyzer-core.builtin.BuiltinFunctions, +clang-analyzer-core.builtin.NoReturnFunctions, +clang-analyzer-core.uninitialized.ArraySubscript, clang-analyzer-core.uninitialized.Assign, --clang-analyzer-core.uninitialized.Branch, --clang-analyzer-core.uninitialized.CapturedBlockVariable, --clang-analyzer-core.uninitialized.UndefReturn, +clang-analyzer-core.uninitialized.Branch, +clang-analyzer-core.uninitialized.CapturedBlockVariable, +clang-analyzer-core.uninitialized.UndefReturn, clang-analyzer-cplusplus.InnerPointer, --clang-analyzer-cplusplus.Move, --clang-analyzer-cplusplus.NewDelete, --clang-analyzer-cplusplus.NewDeleteLeaks, --clang-analyzer-cplusplus.PureVirtualCall, --clang-analyzer-cplusplus.SelfAssignment, --clang-analyzer-cplusplus.SmartPtr, --clang-analyzer-cplusplus.VirtualCallModeling, +clang-analyzer-cplusplus.Move, +clang-analyzer-cplusplus.NewDelete, +clang-analyzer-cplusplus.NewDeleteLeaks, +clang-analyzer-cplusplus.PureVirtualCall, +clang-analyzer-cplusplus.SelfAssignment, +clang-analyzer-cplusplus.SmartPtr, +clang-analyzer-cplusplus.VirtualCallModeling, clang-analyzer-deadcode.DeadStores, --clang-analyzer-fuchsia.HandleChecker, --clang-analyzer-nullability.NullPassedToNonnull, --clang-analyzer-nullability.NullReturnedFromNonnull, --clang-analyzer-nullability.NullabilityBase, --clang-analyzer-nullability.NullableDereferenced, --clang-analyzer-nullability.NullablePassedToNonnull, --clang-analyzer-nullability.NullableReturnedFromNonnull, +clang-analyzer-fuchsia.HandleChecker, +clang-analyzer-nullability.NullPassedToNonnull, +clang-analyzer-nullability.NullReturnedFromNonnull, +clang-analyzer-nullability.NullabilityBase, +clang-analyzer-nullability.NullableDereferenced, +clang-analyzer-nullability.NullablePassedToNonnull, +clang-analyzer-nullability.NullableReturnedFromNonnull, clang-analyzer-optin.cplusplus.UninitializedObject, --clang-analyzer-optin.cplusplus.VirtualCall, --clang-analyzer-optin.mpi.MPI-Checker, --clang-analyzer-optin.osx.OSObjectCStyleCast, --clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker, --clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker, --clang-analyzer-optin.performance.GCDAntipattern, --clang-analyzer-optin.performance.Padding, +clang-analyzer-optin.cplusplus.VirtualCall, +clang-analyzer-optin.mpi.MPI-Checker, +clang-analyzer-optin.osx.OSObjectCStyleCast, +clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker, +clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker, +clang-analyzer-optin.performance.GCDAntipattern, +clang-analyzer-optin.performance.Padding, clang-analyzer-optin.portability.UnixAPI, --clang-analyzer-osx.API, --clang-analyzer-osx.MIG, --clang-analyzer-osx.NSOrCFErrorDerefChecker, --clang-analyzer-osx.NumberObjectConversion, --clang-analyzer-osx.OSObjectRetainCount, --clang-analyzer-osx.ObjCProperty, --clang-analyzer-osx.SecKeychainAPI, --clang-analyzer-osx.cocoa.AtSync, --clang-analyzer-osx.cocoa.AutoreleaseWrite, --clang-analyzer-osx.cocoa.ClassRelease, --clang-analyzer-osx.cocoa.Dealloc, --clang-analyzer-osx.cocoa.IncompatibleMethodTypes, --clang-analyzer-osx.cocoa.Loops, --clang-analyzer-osx.cocoa.MissingSuperCall, --clang-analyzer-osx.cocoa.NSAutoreleasePool, --clang-analyzer-osx.cocoa.NSError, --clang-analyzer-osx.cocoa.NilArg, --clang-analyzer-osx.cocoa.NonNilReturnValue, --clang-analyzer-osx.cocoa.ObjCGenerics, --clang-analyzer-osx.cocoa.RetainCount, --clang-analyzer-osx.cocoa.RetainCountBase, --clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak, --clang-analyzer-osx.cocoa.SelfInit, --clang-analyzer-osx.cocoa.SuperDealloc, --clang-analyzer-osx.cocoa.UnusedIvars, --clang-analyzer-osx.cocoa.VariadicMethodTypes, --clang-analyzer-osx.coreFoundation.CFError, --clang-analyzer-osx.coreFoundation.CFNumber, --clang-analyzer-osx.coreFoundation.CFRetainRelease, --clang-analyzer-osx.coreFoundation.containers.OutOfBounds, --clang-analyzer-osx.coreFoundation.containers.PointerSizedValues, --clang-analyzer-security.FloatLoopCounter, --clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, --clang-analyzer-security.insecureAPI.SecuritySyntaxChecker, --clang-analyzer-security.insecureAPI.UncheckedReturn, --clang-analyzer-security.insecureAPI.bcmp, --clang-analyzer-security.insecureAPI.bcopy, --clang-analyzer-security.insecureAPI.bzero, --clang-analyzer-security.insecureAPI.decodeValueOfObjCType, --clang-analyzer-security.insecureAPI.getpw, --clang-analyzer-security.insecureAPI.gets, --clang-analyzer-security.insecureAPI.mkstemp, --clang-analyzer-security.insecureAPI.mktemp, --clang-analyzer-security.insecureAPI.rand, --clang-analyzer-security.insecureAPI.strcpy, +clang-analyzer-osx.API, +clang-analyzer-osx.MIG, +clang-analyzer-osx.NSOrCFErrorDerefChecker, +clang-analyzer-osx.NumberObjectConversion, +clang-analyzer-osx.OSObjectRetainCount, +clang-analyzer-osx.ObjCProperty, +clang-analyzer-osx.SecKeychainAPI, +clang-analyzer-osx.cocoa.AtSync, +clang-analyzer-osx.cocoa.AutoreleaseWrite, +clang-analyzer-osx.cocoa.ClassRelease, +clang-analyzer-osx.cocoa.Dealloc, +clang-analyzer-osx.cocoa.IncompatibleMethodTypes, +clang-analyzer-osx.cocoa.Loops, +clang-analyzer-osx.cocoa.MissingSuperCall, +clang-analyzer-osx.cocoa.NSAutoreleasePool, +clang-analyzer-osx.cocoa.NSError, +clang-analyzer-osx.cocoa.NilArg, +clang-analyzer-osx.cocoa.NonNilReturnValue, +clang-analyzer-osx.cocoa.ObjCGenerics, +clang-analyzer-osx.cocoa.RetainCount, +clang-analyzer-osx.cocoa.RetainCountBase, +clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak, +clang-analyzer-osx.cocoa.SelfInit, +clang-analyzer-osx.cocoa.SuperDealloc, +clang-analyzer-osx.cocoa.UnusedIvars, +clang-analyzer-osx.cocoa.VariadicMethodTypes, +clang-analyzer-osx.coreFoundation.CFError, +clang-analyzer-osx.coreFoundation.CFNumber, +clang-analyzer-osx.coreFoundation.CFRetainRelease, +clang-analyzer-osx.coreFoundation.containers.OutOfBounds, +clang-analyzer-osx.coreFoundation.containers.PointerSizedValues, +clang-analyzer-security.FloatLoopCounter, +clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, +clang-analyzer-security.insecureAPI.SecuritySyntaxChecker, +clang-analyzer-security.insecureAPI.UncheckedReturn, +clang-analyzer-security.insecureAPI.bcmp, +clang-analyzer-security.insecureAPI.bcopy, +clang-analyzer-security.insecureAPI.bzero, +clang-analyzer-security.insecureAPI.decodeValueOfObjCType, +clang-analyzer-security.insecureAPI.getpw, +clang-analyzer-security.insecureAPI.gets, +clang-analyzer-security.insecureAPI.mkstemp, +clang-analyzer-security.insecureAPI.mktemp, +clang-analyzer-security.insecureAPI.rand, +clang-analyzer-security.insecureAPI.strcpy, clang-analyzer-security.insecureAPI.vfork, --clang-analyzer-unix.API, --clang-analyzer-unix.DynamicMemoryModeling, +clang-analyzer-unix.API, +clang-analyzer-unix.DynamicMemoryModeling, clang-analyzer-unix.Malloc, --clang-analyzer-unix.MallocSizeof, --clang-analyzer-unix.MismatchedDeallocator, +clang-analyzer-unix.MallocSizeof, +clang-analyzer-unix.MismatchedDeallocator, clang-analyzer-unix.Vfork, --clang-analyzer-unix.cstring.BadSizeArg, --clang-analyzer-unix.cstring.CStringModeling, --clang-analyzer-unix.cstring.NullArg, --clang-analyzer-valist.CopyToSelf, --clang-analyzer-valist.Uninitialized, --clang-analyzer-valist.Unterminated, --clang-analyzer-valist.ValistBase, +clang-analyzer-unix.cstring.BadSizeArg, +clang-analyzer-unix.cstring.CStringModeling, +clang-analyzer-unix.cstring.NullArg, +clang-analyzer-valist.CopyToSelf, +clang-analyzer-valist.Uninitialized, +clang-analyzer-valist.Unterminated, +clang-analyzer-valist.ValistBase, cppcoreguidelines-avoid-c-arrays, --cppcoreguidelines-avoid-goto, +cppcoreguidelines-avoid-goto, cppcoreguidelines-c-copy-assignment-signature, cppcoreguidelines-explicit-virtual-functions, cppcoreguidelines-init-variables, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, cppcoreguidelines-pro-type-const-cast, --cppcoreguidelines-pro-type-member-init, --cppcoreguidelines-slicing, --hicpp-avoid-goto, +cppcoreguidelines-pro-type-member-init, +cppcoreguidelines-slicing, +hicpp-avoid-goto, hicpp-exception-baseclass, misc-unused-alias-decls, misc-unused-using-decls, modernize-avoid-bind, modernize-avoid-c-arrays, modernize-deprecated-headers, --modernize-deprecated-ios-base-aliases, +modernize-deprecated-ios-base-aliases, modernize-loop-convert, modernize-make-shared, modernize-make-unique, --modernize-pass-by-value, +modernize-pass-by-value, modernize-raw-string-literal, modernize-redundant-void-arg, --modernize-replace-auto-ptr, --modernize-replace-random-shuffle, --modernize-shrink-to-fit, --modernize-unary-static-assert, +modernize-replace-auto-ptr, +modernize-replace-random-shuffle, +modernize-shrink-to-fit, +modernize-unary-static-assert, modernize-use-bool-literals, modernize-use-emplace, modernize-use-equals-default, --modernize-use-equals-delete, --modernize-use-noexcept, +modernize-use-equals-delete, +modernize-use-noexcept, modernize-use-nullptr, modernize-use-override, modernize-use-transparent-functors, --modernize-use-uncaught-exceptions, +modernize-use-uncaught-exceptions, performance-faster-string-find, performance-for-range-copy, --performance-implicit-conversion-in-loop, --performance-inefficient-algorithm, +performance-implicit-conversion-in-loop, +performance-inefficient-algorithm, performance-inefficient-string-concatenation, --performance-inefficient-vector-operation, +performance-inefficient-vector-operation, performance-move-const-arg, --performance-move-constructor-init, --performance-no-automatic-move, +performance-move-constructor-init, +performance-no-automatic-move, performance-noexcept-move-constructor, --performance-trivially-destructible, --performance-type-promotion-in-math-fn, --performance-unnecessary-copy-initialization, +performance-trivially-destructible, +performance-type-promotion-in-math-fn, +performance-unnecessary-copy-initialization, readability-container-size-empty, ' HeaderFilterRegex: '^(paddle/(?!cinn)).*$' diff --git a/paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc b/paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc index 5ffc2db337ada..bad886ae40cdf 100644 --- a/paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc +++ b/paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc @@ -754,7 +754,7 @@ const std::vector churn_out_vars(ProgramDesc* prog, void create_vars(ProgramDesc* prog, const std::initializer_list& names) { - for (auto name : names) prog->MutableBlock(0)->Var(name); + for (auto const& name : names) prog->MutableBlock(0)->Var(name); } void SetMultiGruOp(ProgramDesc* prog, diff --git a/paddle/fluid/framework/ir/quantize_helper.cc b/paddle/fluid/framework/ir/quantize_helper.cc index 08f2cc457ef2c..fa72f4caf4433 100644 --- a/paddle/fluid/framework/ir/quantize_helper.cc +++ b/paddle/fluid/framework/ir/quantize_helper.cc @@ -38,7 +38,7 @@ std::unordered_map> GetQuantInfoFromTheGraph( const std::string suffix = "_" + key_suffix + "_" + flag; if (graph->Has(flag)) { std::vector attr_names = graph->AttrNames(); - for (auto fake_name : attr_names) { + for (auto const& fake_name : attr_names) { size_t pos = fake_name.find(suffix); if (pos != std::string::npos) { std::string name = fake_name.substr(0, pos); diff --git a/paddle/fluid/framework/new_executor/interpreter/plan.cc b/paddle/fluid/framework/new_executor/interpreter/plan.cc index ee2f5dc57acc6..349e1f0ffa0b5 100644 --- a/paddle/fluid/framework/new_executor/interpreter/plan.cc +++ b/paddle/fluid/framework/new_executor/interpreter/plan.cc @@ -68,7 +68,7 @@ const std::vector>& Plan::JobList() const { const std::vector Plan::JobTypes() const { std::vector res; - for (auto kv : type_to_ir_program_) { + for (auto const& kv : type_to_ir_program_) { res.emplace_back(kv.first); } return res; diff --git a/paddle/fluid/pir/transforms/inplace_pass.cc b/paddle/fluid/pir/transforms/inplace_pass.cc index 57813d54a53f7..c77e7ecbbbecf 100644 --- a/paddle/fluid/pir/transforms/inplace_pass.cc +++ b/paddle/fluid/pir/transforms/inplace_pass.cc @@ -424,7 +424,7 @@ static std::unordered_map GetInplaceOps( } } if (!FLAGS_ir_inplace_kernel_blacklist.empty()) { - for (auto i : inplace_ops) { + for (auto const& i : inplace_ops) { std::cout << i.second << std::endl; } } diff --git a/paddle/fluid/platform/profiler/dump/serialization_logger.cc b/paddle/fluid/platform/profiler/dump/serialization_logger.cc index 6f4ed06de9e8e..17c3d42ec5e86 100644 --- a/paddle/fluid/platform/profiler/dump/serialization_logger.cc +++ b/paddle/fluid/platform/profiler/dump/serialization_logger.cc @@ -198,7 +198,7 @@ void SerializationLogger::LogHostTraceEventNode( OperatorSupplementEventProto::input_shape_proto::shape_vector* shape_vectors_proto = input_shape_proto->add_shape_vecs(); auto shape_vectors = item.second; - for (auto shape_vector : shape_vectors) { + for (auto const& shape_vector : shape_vectors) { OperatorSupplementEventProto::input_shape_proto::shape_vector::shape* shape_proto = shape_vectors_proto->add_shapes(); for (auto& shape_item : shape_vector) { diff --git a/paddle/phi/kernels/funcs/jit/test.cc b/paddle/phi/kernels/funcs/jit/test.cc index d388d95975cff..4cc58d6a3b0c5 100644 --- a/paddle/phi/kernels/funcs/jit/test.cc +++ b/paddle/phi/kernels/funcs/jit/test.cc @@ -75,7 +75,7 @@ void TestAllImpls(const typename KernelTuple::attr_type& attr, const Tester& verifier, const Args&... args) { auto funcs = jit::GetAllCandidateFuncsWithTypes(attr); - for (auto f : funcs) { + for (auto const& f : funcs) { VLOG(10) << "Test Kernel " << f.first; verifier(f.second, args...); } diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 217281b5e66b1..ab98f75a77214 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3453,27 +3453,19 @@ function clang-tidy_check() { set -e clang-tidy --version - - num_diff_files=$(git diff --numstat ${BRANCH} | wc -l) + num_diff_files=$(git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)' | wc -l) commit_files=on startTime_s=`date +%s` - for file_name in `git diff --numstat ${BRANCH} |awk '{print $NF}'`;do - if ! pre-commit run clang-tidy --files $file_name ; then - commit_files=off - fi - done + if ! pre-commit run clang-tidy ; then + commit_files=off + fi endTime_s=`date +%s` [ -n "$startTime_firstBuild" ] && startTime_s=$startTime_firstBuild + echo "File Count: $[ $num_diff_files ]" + echo "Check Time: $[ $endTime_s - $startTime_s ]s" if [ $commit_files == 'off' ];then echo "Your PR code style clang-tidy check failed." - echo "File Count: $[ $num_diff_files ]" - echo "Check Time: $[ $endTime_s - $startTime_s ]s" - git diff 2>&1 - exit 4 - else - echo "File Count: $[ $num_diff_files ]" - echo "Check Time: $[ $endTime_s - $startTime_s ]s" - echo "Your PR code style clang-tidy check passed." + exit 1 fi trap : 0 diff --git a/paddle/utils/string/split_test.cc b/paddle/utils/string/split_test.cc index dcb69955c8658..f0a2f02530369 100644 --- a/paddle/utils/string/split_test.cc +++ b/paddle/utils/string/split_test.cc @@ -21,7 +21,7 @@ TEST(StringSplit, StringSplit) { std::string to_split = "0,1,2,3,4,5"; int i = 0; - for (auto s : paddle::string::Split(to_split, ',')) { + for (auto const& s : paddle::string::Split(to_split, ',')) { EXPECT_EQ(atoi(s.c_str()), i); i++; } diff --git a/test/cpp/fluid/framework/prune_test.cc b/test/cpp/fluid/framework/prune_test.cc index 8da75413e9d6d..9725dfed751ac 100644 --- a/test/cpp/fluid/framework/prune_test.cc +++ b/test/cpp/fluid/framework/prune_test.cc @@ -30,8 +30,8 @@ void AddOp(const std::string &type, f::AttributeMap attrs, paddle::framework::BlockDesc *block) { // insert output - for (auto kv : outputs) { - for (auto v : kv.second) { + for (auto const &kv : outputs) { + for (auto const &v : kv.second) { auto var = block->Var(v); var->SetDataType(paddle::framework::proto::VarType::FP32); } diff --git a/test/cpp/fluid/reader/reader_blocking_queue_test.cc b/test/cpp/fluid/reader/reader_blocking_queue_test.cc index b02f21eb2eb49..b1cd884f789bc 100644 --- a/test/cpp/fluid/reader/reader_blocking_queue_test.cc +++ b/test/cpp/fluid/reader/reader_blocking_queue_test.cc @@ -117,12 +117,12 @@ void CheckIsUnorderedSame(const std::vector>& v1, const std::vector>& v2) { std::set s1; std::set s2; - for (auto vec : v1) { + for (auto const& vec : v1) { for (size_t elem : vec) { s1.insert(elem); } } - for (auto vec : v2) { + for (auto const& vec : v2) { for (size_t elem : vec) { s2.insert(elem); } diff --git a/test/cpp/inference/api/api_tester.cc b/test/cpp/inference/api/api_tester.cc index 43128f07e3308..8fb2fb14685ef 100644 --- a/test/cpp/inference/api/api_tester.cc +++ b/test/cpp/inference/api/api_tester.cc @@ -95,7 +95,7 @@ TEST(paddle_inference_api, AnalysisConfigCopyCtor) { AnalysisConfig cfg2(cfg1); auto passes = cfg2.pass_builder()->AllPasses(); - for (auto ps : passes) { + for (auto const &ps : passes) { CHECK_NE(ps, delete_pass); } } From 23c97834b063ca80b503e00abd1a7c72a97dd3c7 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Wed, 13 Dec 2023 23:41:44 +0800 Subject: [PATCH 10/15] fix bug --- paddle/scripts/paddle_build.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index ab98f75a77214..35ec1842d15e5 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3453,12 +3453,16 @@ function clang-tidy_check() { set -e clang-tidy --version + current_branch=`git branch | grep \* | cut -d ' ' -f2` + echo $current_branch num_diff_files=$(git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)' | wc -l) commit_files=on startTime_s=`date +%s` - if ! pre-commit run clang-tidy ; then - commit_files=off - fi + for file_name in `git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)' |awk '{print $NF}'`;do + if ! pre-commit run clang-tidy --files ${PADDLE_ROOT}/$file_name ; then + commit_files=off + fi + done endTime_s=`date +%s` [ -n "$startTime_firstBuild" ] && startTime_s=$startTime_firstBuild echo "File Count: $[ $num_diff_files ]" @@ -3474,6 +3478,7 @@ function clang-tidy_check() { function build_pr_and_develop() { run_setup ${PYTHON_ABI:-""} bdist_wheel ${parallel_number} + clang-tidy_check if [ ! -d "${PADDLE_ROOT}/build/python/dist/" ]; then mkdir ${PADDLE_ROOT}/build/python/dist/ fi @@ -3509,9 +3514,7 @@ function build_pr_and_develop() { mkdir ${PADDLE_ROOT}/build/dev_whl && cp ${PADDLE_ROOT}/build/python/dist/*.whl ${PADDLE_ROOT}/build/dev_whl fi - generate_api_spec "$1" "DEV" - - clang-tidy_check + generate_api_spec "$1" "DEV" } function build_develop() { From 40d36e83ce921c1218548bcdec271a56203387fd Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Thu, 14 Dec 2023 21:30:31 +0800 Subject: [PATCH 11/15] fix bug --- paddle/scripts/paddle_build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 35ec1842d15e5..cdd18cdfe4f39 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3454,11 +3454,11 @@ function clang-tidy_check() { clang-tidy --version current_branch=`git branch | grep \* | cut -d ' ' -f2` - echo $current_branch - num_diff_files=$(git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)' | wc -l) + echo "current_branch : $current_branch" + num_diff_files=$(git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)$' | wc -l) commit_files=on startTime_s=`date +%s` - for file_name in `git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)' |awk '{print $NF}'`;do + for file_name in `git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)$' |awk '{print $NF}'`;do if ! pre-commit run clang-tidy --files ${PADDLE_ROOT}/$file_name ; then commit_files=off fi From c54620a39b698d9d84dac1fbbd4214ce9a1e7fa4 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Fri, 15 Dec 2023 21:36:06 +0800 Subject: [PATCH 12/15] fix bug --- paddle/scripts/paddle_build.sh | 1 - tools/codestyle/clang-tidy.py | 20 +++++++++++++------- tools/dockerfile/Dockerfile.ubuntu | 2 ++ tools/dockerfile/Dockerfile.ubuntu20 | 3 +++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index cdd18cdfe4f39..4dfe8cec28d15 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3452,7 +3452,6 @@ function clang-tidy_check() { trap 'abort' 0 set -e - clang-tidy --version current_branch=`git branch | grep \* | cut -d ' ' -f2` echo "current_branch : $current_branch" num_diff_files=$(git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)$' | wc -l) diff --git a/tools/codestyle/clang-tidy.py b/tools/codestyle/clang-tidy.py index 404413b9b9945..4c21d81c5819c 100644 --- a/tools/codestyle/clang-tidy.py +++ b/tools/codestyle/clang-tidy.py @@ -469,23 +469,29 @@ def main(): if __name__ == '__main__': - target_version = "15.0.2" + target_version = "15.0.2.1" + target_llvm_version = "15.0.2" try: - out = subprocess.check_output(['clang-tidy', '--version'], shell=True) + out = subprocess.check_output(['clang-tidy', '--version']) version = out.decode('utf-8') - if version.find(target_version) == -1: + if target_llvm_version not in version: print( - f"clang-tidy version == {target_version} not found, attempting auto-install...", + f"clang-tidy version {target_version} not found, attempting auto-install...", file=sys.stderr, ) subprocess.check_output( - 'pip install --no-cache clang-tidy=="15.0.2.1"', shell=True + [ + 'pip', + 'install', + '--no-cache', + f'clang-tidy=={target_version}', + ] ) - except: + except subprocess.CalledProcessError: print( "clang-tidy not found, attempting auto-install...", file=sys.stderr ) subprocess.check_output( - 'pip install --no-cache clang-tidy=="15.0.2.1"', shell=True + ['pip', 'install', '--no-cache', f'clang-tidy=={target_version}'] ) main() diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index a592fc013908d..a304bc21361e7 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -210,5 +210,7 @@ RUN wget https://paddle-ci.gz.bcebos.com/ccache-3.7.9.tar.gz && \ ln -s /usr/local/ccache-3.7.9/bin/ccache /usr/local/bin/ccache && \ cd ../ && rm -rf ccache-3.7.9 ccache-3.7.9.tar.gz +# To fix 'omp.h' file not found [clang-diagnostic-error] bug in clang-tidy_check +RUN apt-get install -y libomp5 libomp-dev && apt-get clean -y EXPOSE 22 diff --git a/tools/dockerfile/Dockerfile.ubuntu20 b/tools/dockerfile/Dockerfile.ubuntu20 index fb241400da27d..3bb9c9d8844c0 100644 --- a/tools/dockerfile/Dockerfile.ubuntu20 +++ b/tools/dockerfile/Dockerfile.ubuntu20 @@ -178,4 +178,7 @@ RUN wget https://paddle-ci.cdn.bcebos.com/clang+llvm-3.8.0-x86_64-linux-gnu-ubun tar xf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz && cd clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04 && \ cp -rn * /usr/local && cd .. && rm -rf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04 && rm -rf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz +# To fix 'omp.h' file not found [clang-diagnostic-error] bug in clang-tidy_check +RUN apt-get install -y libomp5 libomp-dev && apt-get clean -y + EXPOSE 22 From 9bdcc7908fbe924c1eb5ee14bb0b777bf468fd92 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Sat, 16 Dec 2023 22:22:41 +0800 Subject: [PATCH 13/15] fix bug --- tools/dockerfile/Dockerfile.ubuntu | 3 +-- tools/dockerfile/Dockerfile.ubuntu20 | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index a304bc21361e7..c0eb36aae5105 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -30,6 +30,7 @@ RUN apt-get update && \ python-matplotlib \ automake locales swig \ liblapack-dev liblapacke-dev \ + libomp5 libomp-dev \ net-tools libtool module-init-tools && \ apt-get clean -y @@ -210,7 +211,5 @@ RUN wget https://paddle-ci.gz.bcebos.com/ccache-3.7.9.tar.gz && \ ln -s /usr/local/ccache-3.7.9/bin/ccache /usr/local/bin/ccache && \ cd ../ && rm -rf ccache-3.7.9 ccache-3.7.9.tar.gz -# To fix 'omp.h' file not found [clang-diagnostic-error] bug in clang-tidy_check -RUN apt-get install -y libomp5 libomp-dev && apt-get clean -y EXPOSE 22 diff --git a/tools/dockerfile/Dockerfile.ubuntu20 b/tools/dockerfile/Dockerfile.ubuntu20 index 3bb9c9d8844c0..6ef16d080ed49 100644 --- a/tools/dockerfile/Dockerfile.ubuntu20 +++ b/tools/dockerfile/Dockerfile.ubuntu20 @@ -29,7 +29,7 @@ RUN apt-get update --allow-unauthenticated && \ apt-get update && \ apt-get install -y curl wget vim git unzip unrar tar xz-utils libssl-dev bzip2 gzip \ coreutils ntp language-pack-zh-hans libsm6 libxext6 libxrender-dev libgl1-mesa-glx \ - bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod + bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod libomp5 libomp-dev # Downgrade gcc&&g++ @@ -178,7 +178,5 @@ RUN wget https://paddle-ci.cdn.bcebos.com/clang+llvm-3.8.0-x86_64-linux-gnu-ubun tar xf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz && cd clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04 && \ cp -rn * /usr/local && cd .. && rm -rf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04 && rm -rf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz -# To fix 'omp.h' file not found [clang-diagnostic-error] bug in clang-tidy_check -RUN apt-get install -y libomp5 libomp-dev && apt-get clean -y EXPOSE 22 From d77cac7c723dacb4dff332d395dff5a1a03b8006 Mon Sep 17 00:00:00 2001 From: ccsuzzh <1719571694@qq.com> Date: Mon, 18 Dec 2023 20:42:02 +0800 Subject: [PATCH 14/15] fix bug --- paddle/scripts/paddle_build.sh | 2 +- tools/dockerfile/Dockerfile.ubuntu | 1 - tools/dockerfile/Dockerfile.ubuntu20 | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 4dfe8cec28d15..fa20d163af68b 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3451,7 +3451,7 @@ function clang-tidy_check() { set +x trap 'abort' 0 set -e - + apt-get install -y libomp5 libomp-dev current_branch=`git branch | grep \* | cut -d ' ' -f2` echo "current_branch : $current_branch" num_diff_files=$(git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)$' | wc -l) diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index c0eb36aae5105..a592fc013908d 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -30,7 +30,6 @@ RUN apt-get update && \ python-matplotlib \ automake locales swig \ liblapack-dev liblapacke-dev \ - libomp5 libomp-dev \ net-tools libtool module-init-tools && \ apt-get clean -y diff --git a/tools/dockerfile/Dockerfile.ubuntu20 b/tools/dockerfile/Dockerfile.ubuntu20 index 6ef16d080ed49..fb241400da27d 100644 --- a/tools/dockerfile/Dockerfile.ubuntu20 +++ b/tools/dockerfile/Dockerfile.ubuntu20 @@ -29,7 +29,7 @@ RUN apt-get update --allow-unauthenticated && \ apt-get update && \ apt-get install -y curl wget vim git unzip unrar tar xz-utils libssl-dev bzip2 gzip \ coreutils ntp language-pack-zh-hans libsm6 libxext6 libxrender-dev libgl1-mesa-glx \ - bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod libomp5 libomp-dev + bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod # Downgrade gcc&&g++ @@ -178,5 +178,4 @@ RUN wget https://paddle-ci.cdn.bcebos.com/clang+llvm-3.8.0-x86_64-linux-gnu-ubun tar xf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz && cd clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04 && \ cp -rn * /usr/local && cd .. && rm -rf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04 && rm -rf clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz - EXPOSE 22 From bde648e5a58ecab2da7d5d96f355c5c12cb61c09 Mon Sep 17 00:00:00 2001 From: Zhenghai Zhang <65210872+ccsuzzh@users.noreply.github.com> Date: Tue, 19 Dec 2023 09:31:10 +0800 Subject: [PATCH 15/15] Update paddle_build.sh --- paddle/scripts/paddle_build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index fa20d163af68b..5475d6ae994cb 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -3452,6 +3452,7 @@ function clang-tidy_check() { trap 'abort' 0 set -e apt-get install -y libomp5 libomp-dev + dpkg -s libomp5 libomp-dev current_branch=`git branch | grep \* | cut -d ' ' -f2` echo "current_branch : $current_branch" num_diff_files=$(git diff --numstat ${BRANCH} | grep -E '\.(c|cc|cxx|cpp|h|hpp|hxx)$' | wc -l)