|
| 1 | +# #-- clang-analysis.test --# |
| 2 | +# source the master var file when it's there |
| 3 | +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master |
| 4 | +# use .tpkg.var.test for in test variable passing |
| 5 | +[ -f .tpkg.var.test ] && source .tpkg.var.test |
| 6 | +# common functions |
| 7 | +. ../common.sh |
| 8 | + |
| 9 | +if test ! -x "`which clang 2>&1`"; then |
| 10 | + echo "No clang in path" |
| 11 | + exit 0 |
| 12 | +fi |
| 13 | +#echo "have clang" |
| 14 | + |
| 15 | +# read value from Makefile |
| 16 | +# $1: result variable name |
| 17 | +# $2: string on Makefile |
| 18 | +# $3: Makefile location |
| 19 | +read_value () { |
| 20 | + x=`grep "$2" $3 | sed -e "s/$2//"` |
| 21 | + echo eval $1="'""$x""'" |
| 22 | + eval $1="'""$x""'" |
| 23 | + # print what we just read |
| 24 | + #echo $1"="'"'"`eval echo '$'$1`"'"' |
| 25 | +} |
| 26 | + |
| 27 | +PRE="../.." |
| 28 | +# read some values from the Makefile |
| 29 | +read_value srcdir '^srcdir[ ]*= *' $PRE/Makefile |
| 30 | +read_value CPPFLAGS '^CPPFLAGS = *' $PRE/Makefile |
| 31 | +read_value LIBOBJS '^LIBOBJS = *' $PRE/Makefile |
| 32 | + |
| 33 | +#echo dir is $dir |
| 34 | +# turn libobjs into C files |
| 35 | +compatfiles=`echo "$LIBOBJS" | sed -e 's?..LIBOBJDIR.?compat/?g' -e 's/.U.o/.c/g'` |
| 36 | +echo compatfiles are $compatfiles |
| 37 | +#echo |
| 38 | + |
| 39 | +echo "cd $PRE -- cd $srcdir" |
| 40 | +cd $PRE; cd $srcdir |
| 41 | +# check the files in the srcdir |
| 42 | +fail="no" |
| 43 | +for x in *.c $compatfiles; do |
| 44 | + echo clang --analyze $CPPFLAGS $x |
| 45 | + plist=`basename $x .c`.plist |
| 46 | + rm -rf $plist |
| 47 | + clang --analyze $CPPFLAGS $x 2>&1 | tee tmp.$$ |
| 48 | + if grep -e warning -e error tmp.$$ >/dev/null; then |
| 49 | + fail="yes" |
| 50 | + fails="$fails $x" |
| 51 | + fi |
| 52 | + rm -rf $plist tmp.$$ |
| 53 | +done |
| 54 | + |
| 55 | +echo |
| 56 | +if test "$fail" = "yes"; then |
| 57 | + echo "Failures" |
| 58 | + echo "create reports in file.plist dir with clang --analyze --analyzer-output html $CPPFLAGS""$fails" |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | +echo "OK" |
| 62 | +exit 0 |
0 commit comments