summaryrefslogtreecommitdiff
path: root/20-coverity-scan.sh
blob: 935d3555899061e0c388f260bfbdfd2841e894d8 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash

# SPDX-License-Identifier: GPL-2.0-or-later
#
# Coverity Scan Static analysis checker
#
# More CI reference at : 
# https://www.synopsys.com/blogs/software-security/integrating-coverity-scan-with-gitlab-ci/

# Stop on error (don't publish bad results)
set -e

source ./common.sh

LIBCAMERA=${1:-$(srcdir libcamera)}
ID=coverity

BRANCH=$(libcamera_branch "$LIBCAMERA")

check_version "$LIBCAMERA" "$ID"

logfile=$(log_filename $ID)

echo "Commencing coverity scan..." > $logfile

## Parse coverity

TOKEN=`git config --get coverity.token`
EMAIL=`git config --get coverity.email`

function get_coverity() {
	echo "Downloading Coverity Scan..."
	curl -o /tmp/cov-analysis-linux64.tgz \
		--form project=libcamera \
	       	--form token=$TOKEN \
		https://scan.coverity.com/download/linux64
	tar xfz /tmp/cov-analysis-linux64.tgz
	rm /tmp/cov-analysis-linux64.tgz
}

COVERITY_PATH=./cov-analysis-linux*

if [ ! -d $COVERITY_PATH ];
then
	get_coverity >> $logfile
fi

COVERITY_PATH=$(realpath ./cov-analysis-linux*)

if [ ! -d $COVERITY_PATH ];
then
	echo "Failed to install or obtain Coverity Scan"
	exit 1
fi


export PATH=$PATH:$COVERITY_PATH/bin

echo $PATH

BUILDDIR="$(builddir $ID)"

# We must guarantee that coverity builds are not retrieved from any cache
export CCACHE_DISABLE=true

function build_coverity() {

	rm -rf $BUILDDIR
	meson "$BUILDDIR" "$LIBCAMERA" \
		--prefix=/usr \
		-Dv4l2=true \
		-Dandroid=enabled \
		-Ddocumentation=disabled \
		-Dgstreamer=enabled

	cd $BUILDDIR
	cov-build --dir cov-int ninja

	echo "Compressing results for submission..."
	tar czf libcamera.tgz cov-int
	cd -
}


build_coverity >> $logfile

echo "Submitting to scan.coverity.com..." >> $logfile

curl --form token=$TOKEN \
  --form email=$EMAIL \
  --form file=@$BUILDDIR/libcamera.tgz \
  --form version="$VERSION" \
  --form description="$BRANCH" \
  https://scan.coverity.com/builds?project=libcamera

echo "build $VERSION submitted for $BRANCH." | tee -a $logfile

completed $ID