From: Willem Toorop Date: Tue, 18 Nov 2025 13:04:26 +0000 (+0100) Subject: Clang static code analysis tpkg X-Git-Tag: 1.9.0-rc.1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=256cf6d4efed4c8bb2ebb58dd2aeb5a8216664cd;p=thirdparty%2Fldns.git Clang static code analysis tpkg --- diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index 624b58c9..add49d0c 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -56,7 +56,7 @@ jobs: - name: Set up Cygwin uses: cygwin/cygwin-install-action@master with: - packages: make gcc-g++ bash libtool automake autoconf libssl-devel bind-utils + packages: make gcc-g++ bash libtool automake autoconf libssl-devel bind-utils clang - uses: actions/checkout@main with: submodules: recursive @@ -87,7 +87,7 @@ jobs: - name: Get the qemu container run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - name: "${{ matrix.platform }}: Build and test" - run: docker run --rm --interactive --mount type=bind,source=$(pwd),target=/host ${{ matrix.platform }}/alpine sh -c "apk add make gcc libc-dev libtool automake autoconf openssl-dev m4 indent bash bind-tools && cd /host && libtoolize -vci && autoreconf -vfi && ./configure && make test" + run: docker run --rm --interactive --mount type=bind,source=$(pwd),target=/host ${{ matrix.platform }}/alpine sh -c "apk add make gcc libc-dev libtool automake autoconf openssl-dev m4 indent bash bind-tools clang && cd /host && libtoolize -vci && autoreconf -vfi && ./configure && make test" # BSDs: diff --git a/test/33-clang-analysis.tpkg/33-clang-analysis.dsc b/test/33-clang-analysis.tpkg/33-clang-analysis.dsc new file mode 100644 index 00000000..2d95f35a --- /dev/null +++ b/test/33-clang-analysis.tpkg/33-clang-analysis.dsc @@ -0,0 +1,15 @@ +BaseName: 33-clang-analysis +Version: 1.0 +Description: clang analysis +CreationDate: Wed 12 Sep 16:00:26 CEST 2018 +Maintainer: Wouter Wijngaards +Category: +Component: +Depends: +Help: +Pre: +Post: +Test: 33-clang-analysis.test +AuxFiles: +Passed: +Failure: diff --git a/test/33-clang-analysis.tpkg/33-clang-analysis.test b/test/33-clang-analysis.tpkg/33-clang-analysis.test new file mode 100644 index 00000000..dfb75958 --- /dev/null +++ b/test/33-clang-analysis.tpkg/33-clang-analysis.test @@ -0,0 +1,62 @@ +# #-- clang-analysis.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test +# common functions +. ../common.sh + +if test ! -x "`which clang 2>&1`"; then + echo "No clang in path" + exit 0 +fi +#echo "have clang" + +# read value from Makefile +# $1: result variable name +# $2: string on Makefile +# $3: Makefile location +read_value () { + x=`grep "$2" $3 | sed -e "s/$2//"` + echo eval $1="'""$x""'" + eval $1="'""$x""'" + # print what we just read + #echo $1"="'"'"`eval echo '$'$1`"'"' +} + +PRE="../.." +# read some values from the Makefile +read_value srcdir '^srcdir[ ]*= *' $PRE/Makefile +read_value CPPFLAGS '^CPPFLAGS = *' $PRE/Makefile +read_value LIBOBJS '^LIBOBJS = *' $PRE/Makefile + +#echo dir is $dir +# turn libobjs into C files +compatfiles=`echo "$LIBOBJS" | sed -e 's?..LIBOBJDIR.?compat/?g' -e 's/.U.o/.c/g'` +echo compatfiles are $compatfiles +#echo + +echo "cd $PRE -- cd $srcdir" +cd $PRE; cd $srcdir +# check the files in the srcdir +fail="no" +for x in *.c $compatfiles; do + echo clang --analyze $CPPFLAGS $x + plist=`basename $x .c`.plist + rm -rf $plist + clang --analyze $CPPFLAGS $x 2>&1 | tee tmp.$$ + if grep -e warning -e error tmp.$$ >/dev/null; then + fail="yes" + fails="$fails $x" + fi + rm -rf $plist tmp.$$ +done + +echo +if test "$fail" = "yes"; then + echo "Failures" + echo "create reports in file.plist dir with clang --analyze --analyzer-output html $CPPFLAGS""$fails" + exit 1 +fi +echo "OK" +exit 0