coverity.sh 1.64 KB
Newer Older
Ben Straub committed
1 2
#!/bin/bash

3
set -e
4

5 6 7
# Environment check
[ -z "$COVERITY_TOKEN" ] && echo "Need to set a coverity token" && exit 1

8 9 10
SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
BUILD_DIR=$(pwd)

11
case $(uname -m) in
Ben Straub committed
12 13 14
	i?86)				BITS=32 ;;
	amd64|x86_64)	BITS=64 ;;
esac
15
SCAN_TOOL=https://scan.coverity.com/download/cxx/linux${BITS}
16
TOOL_BASE=$(pwd)/_coverity-scan
Ben Straub committed
17 18

# Install coverity tools
19
if [ ! -d "$TOOL_BASE" ]; then
Ben Straub committed
20
	echo "Downloading coverity..."
21 22
	mkdir -p "$TOOL_BASE"
	pushd "$TOOL_BASE"
Ben Straub committed
23 24 25
	wget -O coverity_tool.tgz $SCAN_TOOL \
		--post-data "project=libgit2&token=$COVERITY_TOKEN"
	tar xzf coverity_tool.tgz
26 27 28
	popd
	TOOL_DIR=$(find "$TOOL_BASE" -type d -name 'cov-analysis*')
	ln -s "$TOOL_DIR" "$TOOL_BASE"/cov-analysis
Ben Straub committed
29 30
fi

31
cp "${SOURCE_DIR}/script/user_nodefs.h" "$TOOL_BASE"/cov-analysis/config/user_nodefs.h
32

Ben Straub committed
33 34 35
COV_BUILD="$TOOL_BASE/cov-analysis/bin/cov-build"

# Configure and build
36 37
cmake ${SOURCE_DIR}

Ben Straub committed
38 39 40 41 42 43
COVERITY_UNSUPPORTED=1 \
	$COV_BUILD --dir cov-int \
	cmake --build .

# Upload results
tar czf libgit2.tgz cov-int
44
SHA=$(cd ${SOURCE_DIR} && git rev-parse --short HEAD)
45 46 47 48

HTML="$(curl \
	--silent \
	--write-out "\n%{http_code}" \
49
	--form token="$COVERITY_TOKEN" \
50
	--form email=libgit2@gmail.com \
Ben Straub committed
51
	--form file=@libgit2.tgz \
52
	--form version="$SHA" \
53
	--form description="libgit2 build" \
54 55 56 57 58 59 60 61
	https://scan.coverity.com/builds?project=libgit2)"
# Body is everything up to the last line
BODY="$(echo "$HTML" | head -n-1)"
# Status code is the last line
STATUS_CODE="$(echo "$HTML" | tail -n1)"

echo "${BODY}"

62
if [ "${STATUS_CODE}" != "200" -a "${STATUS_CODE}" != "201" ]; then
63 64 65
	echo "Received error code ${STATUS_CODE} from Coverity"
	exit 1
fi