From c712f97993bd0c4243d87557e3f7a8fd6243574e Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 18 Jul 2023 12:01:40 +0800 Subject: [PATCH] tools/ci/checkpatch: add cmake style check into ci-check Signed-off-by: chao an --- tools/checkpatch.sh | 19 +++++++++++++++++++ tools/ci/cibuild.sh | 1 + tools/ci/docker/linux/Dockerfile | 1 + 3 files changed, 21 insertions(+) diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index 65952d986f2ae..962584b86e637 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -58,6 +58,15 @@ is_rust_file() { fi } +is_cmake_file() { + file_name=$(basename $@) + if [ "$file_name" == "CMakeLists.txt" ] || [[ "$file_name" =~ "cmake" ]]; then + echo 1 + else + echo 0 + fi +} + check_file() { if [ -x $@ ]; then case $@ in @@ -76,6 +85,16 @@ check_file() { elif ! rustfmt --edition 2021 --check $@ 2>&1; then fail=1 fi + elif [ "$(is_cmake_file $@)" == "1" ]; then + if ! command -v cmake-format &> /dev/null; then + echo -e "\ncmake-format not found, run following command to install:" + echo " $ pip install cmake-format" + fail=1 + elif ! cmake-format --check $@ 2>&1; then + echo -e "\ncmake-format check failed, run following command to update the style:" + echo " $ cmake-format -o $@ $@" + fail=1 + fi elif ! $TOOLDIR/nxstyle $@ 2>&1; then fail=1 fi diff --git a/tools/ci/cibuild.sh b/tools/ci/cibuild.sh index 8f25410186dbf..4660904b63eb6 100755 --- a/tools/ci/cibuild.sh +++ b/tools/ci/cibuild.sh @@ -282,6 +282,7 @@ function python-tools { # Force the reinstall of python packages due to issues with GitHub # cache restoration. pip3 install --force-reinstall \ + cmake-format \ CodeChecker \ cvt2utf \ cxxfilt \ diff --git a/tools/ci/docker/linux/Dockerfile b/tools/ci/docker/linux/Dockerfile index c3fd54ac53ff0..d5e505e3bfb93 100644 --- a/tools/ci/docker/linux/Dockerfile +++ b/tools/ci/docker/linux/Dockerfile @@ -286,6 +286,7 @@ ENV PIP_NO_CACHE_DIR=0 # instead of requiring them to be compiled. RUN pip3 install setuptools RUN pip3 install wheel +RUN pip3 install cmake-format # Install CodeChecker and use it to statically analyze the code. RUN pip3 install CodeChecker # Install cvt2utf to check for non-UTF characters.