summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/dist/s_clang-scan
blob: 5235a069c60d6e616eaf7b45a405596d9584ef2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /bin/sh

t_out=__wt.$$.out
t_err=__wt.$$.err
a=__wt.$$.a
b=__wt.$$.b
t_build=__s_clang_scan_tmp_build
trap 'rm -rf $a $b $t_out $t_err $t_build' 0 1 2 3 13 15

# Find the top-level WiredTiger directory and move to there.
top=`git rev-parse --show-toplevel` && cd $top || exit 1
echo "$0: running scan-build in $PWD"

# Clang isn't installed in any standard place, find a binary we can use.
# If the caller gives us $SCANBUILD, check for $SCANCOMPILER and default
# to "clang".
scan="$SCANBUILD"
test -z "$scan" || compiler="${SCANCOMPILER:-clang}"

if test -z "$scan" &&
    test -x /usr/bin/clang &&
    test -x /usr/bin/scan-build; then
	compiler="/usr/bin/clang"
	scan="/usr/bin/scan-build"
fi

if test -z "$scan"; then
	echo "$0: no clang compiler and scan-build programs found"
	echo "$0: set \$SCANCOMPILER=/path/clang and \$SCANBUILD=/path/scan-build to continue"
	exit 1
fi
echo "$0: compiler: $compiler"
echo "$0: scan-build: $scan"

# Remove old reports.
rm -rf clangScanBuildReports && mkdir clangScanBuildReports
rm -rf ${t_build} && mkdir ${t_build}

cd ${t_build}
args="-o clangScanBuildReports"
args="$args --use-cc=$compiler"
args="$args -disable-checker core.NullDereference"
$scan $args cmake CMAKE_C_FLAGS=-g \
    -DENABLE_STATIC=1 -DENABLE_SHARED=0 -DHAVE_DIAGNOSTIC=1 -DENABLE_STRICT=1 ../.> /dev/null
$scan $args make -j 8 wt 1>../$t_out 2>../$t_err
cd ..

grep 'No bugs found' $t_out > /dev/null && exit 0

# Compare the set of errors/warnings and exit success when they're expected.
# clang-scan outputs errors/warnings with a leading file path followed by a
# colon, followed by the string "error:" or "warning:".
cat dist/s_clang-scan.diff |
    egrep '^[a-z\./].*error: |^[a-z\./].*warning: ' | sed -e 's/:.*:.*://' | sort > $a
cat $t_err |
    egrep '^[a-z\./].*error: |^[a-z\./].*warning: ' | sed -e 's/:.*:.*://' | sort > $b
diff $a $b > /dev/null && exit 0

echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo 'scan-build output differs from expected:'
echo '<<<<<<<<<< Expected >>>>>>>>>> Current'
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
diff dist/s_clang-scan.diff $t_err
exit 1