From d8cff7d17ab847cec6eae5fba00823a797714535 Mon Sep 17 00:00:00 2001 From: xinbingnan Date: Wed, 14 Sep 2022 17:59:17 +0800 Subject: [PATCH] tools/ci/docker/linux/Dockerfile: Install CodeChecker and requirements(clang, clang-tidy) .github/workflows/build.yml: added CodeChecker support for GitHub Workflow tools/testbuild.sh: added support for CodeChecker checks - Added support for CodeChecker checks. - Generate inspection reports and summaries. - After the task is executed, the logs are compressed and the database is packaged. Signed-off-by: xinbingnan --- .github/workflows/build.yml | 9 ++++-- tools/ci/testlist/codechecker.dat | 4 +++ tools/testbuild.sh | 52 +++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 tools/ci/testlist/codechecker.dat diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aeb3afc867..7a21fe444d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -122,7 +122,7 @@ jobs: strategy: matrix: - boards: [arm-01, arm-02, arm-03, arm-04, arm-05, arm-06, arm-07, arm-08, arm-09, arm-10, arm-11, arm-12, arm-13, other, risc-v, sim-01, sim-02, xtensa] + boards: [arm-01, arm-02, arm-03, arm-04, arm-05, arm-06, arm-07, arm-08, arm-09, arm-10, arm-11, arm-12, arm-13, other, risc-v, sim-01, sim-02, xtensa, codechecker] steps: - name: Download Source Artifact @@ -160,10 +160,15 @@ jobs: git config --global --add safe.directory /github/workspace/sources/nuttx git config --global --add safe.directory /github/workspace/sources/apps cd sources/nuttx/tools/ci - ./cibuild.sh -A -R -c testlist/${{matrix.boards}}.dat + if [ "X${{matrix.boards}}" = "Xcodechecker" ]; then + ./cibuild.sh -A -R -c --codechecker testlist/${{matrix.boards}}.dat + else + ./cibuild.sh -A -R -c testlist/${{matrix.boards}}.dat + fi ccache -s - uses: actions/upload-artifact@v3 + if: ${{ always() }} with: name: linux-builds path: buildartifacts/ diff --git a/tools/ci/testlist/codechecker.dat b/tools/ci/testlist/codechecker.dat new file mode 100644 index 0000000000..c15a97dcc8 --- /dev/null +++ b/tools/ci/testlist/codechecker.dat @@ -0,0 +1,4 @@ +# Select a random set of targets to check. If you need to check a specific target, write the target list in this file. +# Make sure that the compilation check time does not exceed the average time. + +/arm/sama5/sama5d4-ek/configs/nxwm,CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI diff --git a/tools/testbuild.sh b/tools/testbuild.sh index abb42cd08f..0c18646217 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -36,6 +36,7 @@ PRINTLISTONLY=0 GITCLEAN=0 SAVEARTIFACTS=0 CHECKCLEAN=1 +CODECHECKER=0 RUN=0 case $(uname -s) in @@ -57,7 +58,7 @@ esac function showusage { echo "" - echo "USAGE: $progname [-l|m|c|g|n] [-d] [-e ] [-x] [-j ] [-a ] [-t ] [-p] [-G] " + echo "USAGE: $progname [-l|m|c|g|n] [-d] [-e ] [-x] [-j ] [-a ] [-t ] [-p] [-G] [--codechecker] " echo " $progname -h" echo "" echo "Where:" @@ -80,6 +81,7 @@ function showusage { echo " as well." echo " -R execute \"run\" script in the config directories if exists." echo " -h will show this help test and terminate" + echo " --codechecker enables CodeChecker statically analyze the code." echo " selects the list of configurations to test. No default" echo "" echo "Your PATH variable must include the path to both the build tools and the" @@ -133,6 +135,9 @@ while [ ! -z "$1" ]; do -R ) RUN=1 ;; + --codechecker ) + CODECHECKER=1 + ;; -h ) showusage ;; @@ -208,6 +213,18 @@ function exportandimport { return $fail } +function compressartifacts { + local target_path=$1 + local target_name=$2 + + pushd $target_path >/dev/null + + tar zcf ${target_name}.tar.gz ${target_name} + rm -rf ${target_name} + + popd >/dev/null +} + function makefunc { if ! ${MAKE} ${MAKE_FLAGS} "${EXTRA_FLAGS}" ${JOPTION} $@ 1>/dev/null; then fail=1 @@ -218,6 +235,32 @@ function makefunc { return $fail } +function checkfunc { + build_cmd="${MAKE} ${MAKE_FLAGS} \"${EXTRA_FLAGS}\" ${JOPTION} 1>/dev/null" + + local config_sub_path=$(echo "$config" | sed "s/:/\//") + local sub_target_name=${config_sub_path#$(dirname "${config_sub_path}")/} + local codechecker_dir=${ARTIFACTDIR}/codechecker_logs/${config_sub_path} + + mkdir -p "${codechecker_dir}" + + echo " Checking NuttX by Codechecker..." + CodeChecker check -b "${build_cmd}" -o "${codechecker_dir}/logs" -e sensitive --ctu + codecheck_ret=$? + echo " Storing analysis result to CodeChecker..." + echo " Generating HTML report..." + CodeChecker parse --export html --output "${codechecker_dir}/html" "${codechecker_dir}/logs" 1>/dev/null + echo " Compressing logs..." + compressartifacts "$(dirname "${codechecker_dir}")" "${sub_target_name}" + +# If you need to stop CI, uncomment the following line. +# if [ $codecheck_ret -ne 0 ]; then +# fail=1 +# fi + + return $fail +} + # Clean up after the last build function distclean { @@ -283,7 +326,12 @@ function configure { function build { echo " Building NuttX..." - makefunc + if [ "${CODECHECKER}" -eq 1 ]; then + checkfunc + else + makefunc + fi + if [ ${SAVEARTIFACTS} -eq 1 ]; then artifactconfigdir=$ARTIFACTDIR/$(echo $config | sed "s/:/\//")/ mkdir -p $artifactconfigdir