Skip to content

Commit fd9eb73

Browse files
ktsaoupaulkatsoulakis
authored andcommitted
make coverity-scan.sh usable by hand (netdata#6747)
* make coverity-scan.sh usable by hand * updated debug variable and docs * merge coverity-scan.sh and coverity-install.sh -- MERGING AND TAKING OVER FURTHER IMPROVEMENTS as agreed --
1 parent 59dd72b commit fd9eb73

File tree

3 files changed

+145
-75
lines changed

3 files changed

+145
-75
lines changed

Diff for: .gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ packaging/makeself/tmp/
7777
# coverity
7878
cov-int/
7979
netdata-coverity-analysis.tgz
80-
.coverity-token
81-
.coverity-build
80+
.coverity-scan.conf
8281

8382
.cproject/
8483
.idea/

Diff for: coverity-install.sh

+1-35
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,4 @@
55
#
66
# Author: Pavlos Emm. Katsoulakis ([email protected])
77

8-
token="${COVERITY_SCAN_TOKEN}"
9-
([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)"
10-
if [ -z "${token}" ]; then
11-
echo >&2 "Save the coverity token to .coverity-token or export it as COVERITY_SCAN_TOKEN."
12-
exit 1
13-
fi
14-
15-
covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
16-
([ -z "${covbuild}" ] && [ -f .coverity-build ]) && covbuild="$(<.coverity-build)"
17-
if [ ! -z "${covbuild}" ]; then
18-
echo >&2 "Coverity already installed, nothing to do!"
19-
exit 0
20-
fi
21-
22-
echo >&2 "Installing coverity..."
23-
WORKDIR="/opt/coverity-source"
24-
mkdir -p "${WORKDIR}"
25-
26-
curl -SL --data "token=${token}&project=${REPOSITORY}" https://scan.coverity.com/download/linux64 > "${WORKDIR}/coverity_tool.tar.gz"
27-
if [ -f "${WORKDIR}/coverity_tool.tar.gz" ]; then
28-
tar -x -C "${WORKDIR}" -f "${WORKDIR}/coverity_tool.tar.gz"
29-
sudo mv "${WORKDIR}/cov-analysis-linux64-2019.03" /opt/coverity
30-
export PATH=${PATH}:/opt/coverity/bin/
31-
else
32-
echo "Failed to download coverity tool tarball!"
33-
fi
34-
35-
# Validate the installation
36-
covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
37-
if [ -z "$covbuild" ]; then
38-
echo "Failed to install coverity!"
39-
exit 1
40-
else
41-
echo >&2 "Coverity scan installed!"
42-
fi
8+
exec ./coverity-scan.sh install "${@}"

Diff for: coverity-scan.sh

+143-38
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,167 @@
11
#!/usr/bin/env bash
22
# Coverity scan script
33
#
4-
# To run this script you need to provide API token. This can be done either by:
5-
# - Putting token in ".coverity-token" file
6-
# - Assigning token value to COVERITY_SCAN_TOKEN environment variable
7-
#
84
# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
95
#
106
# Author : Costa Tsaousis ([email protected])
117
# Author : Pawel Krupa (paulfantom)
128
# Author : Pavlos Emm. Katsoulakis ([email protected])
139

14-
cpus=$(grep -c ^processor </proc/cpuinfo)
10+
# To run manually, save configuration to .coverity-scan.conf like this:
11+
#
12+
# the repository to report to coverity - devs can set here their own fork
13+
# REPOSITORY="netdata/netdata"
14+
#
15+
# the email of the developer, as given to coverity
16+
# COVERITY_SCAN_SUBMIT_MAIL="[email protected]"
17+
#
18+
# the token given by coverity to the developer
19+
# COVERITY_SCAN_TOKEN="TOKEN taken from Coverity site"
20+
#
21+
# the absolute path of the cov-build - optional
22+
# COVERITY_BUILD_PATH="/opt/cov-analysis-linux64-2019.03/bin/cov-build"
23+
#
24+
# when set, the script will print on screen the curl command that submits the build to coverity
25+
# this includes the token, so the default is not to print it.
26+
# COVERITY_SUBMIT_DEBUG=1
27+
#
28+
# All these variables can also be exported before running this script.
29+
#
30+
# If the first parameter of this script is "install",
31+
# coverity build tools will be downloaded and installed in /opt/coverity
32+
33+
# the version of coverity to use
34+
COVERITY_BUILD_VERSION="cov-analysis-linux64-2019.03"
35+
36+
source packaging/installer/functions.sh || exit 1
37+
38+
cpus=$(find_processors)
1539
[ -z "${cpus}" ] && cpus=1
1640

41+
if [ -f ".coverity-scan.conf" ]
42+
then
43+
source ".coverity-scan.conf" || exit 1
44+
fi
45+
46+
repo="${REPOSITORY}"
47+
if [ -z "${repo}" ]; then
48+
fatal "export variable REPOSITORY or set it in .coverity-scan.conf"
49+
fi
50+
repo="${repo//\//%2F}"
51+
52+
email="${COVERITY_SCAN_SUBMIT_MAIL}"
53+
if [ -z "${email}" ]; then
54+
fatal "export variable COVERITY_SCAN_SUBMIT_MAIL or set it in .coverity-scan.conf"
55+
fi
56+
1757
token="${COVERITY_SCAN_TOKEN}"
18-
([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)"
1958
if [ -z "${token}" ]; then
20-
echo >&2 "Save the coverity token to .coverity-token or export it as COVERITY_SCAN_TOKEN."
21-
exit 1
59+
fatal "export variable COVERITY_SCAN_TOKEN or set it in .coverity-scan.conf"
2260
fi
2361

24-
export PATH=${PATH}:/opt/coverity/bin/
25-
covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
26-
([ -z "${covbuild}" ] && [ -f .coverity-build ]) && covbuild="$(<.coverity-build)"
27-
if [ -z "${covbuild}" ]; then
28-
echo >&2 "Cannot find 'cov-build' binary in \$PATH."
29-
exit 1
30-
elif [ ! -x "${covbuild}" ]; then
31-
echo >&2 "The command ${covbuild} is not executable. Save command the full filename of cov-build in .coverity-build"
32-
exit 1
33-
fi
62+
# only print the output of a command
63+
# when debugging is enabled
64+
# used to hide the token when debugging is not enabled
65+
debugrun() {
66+
if [ "${COVERITY_SUBMIT_DEBUG}" = "1" ]
67+
then
68+
run "${@}"
69+
return $?
70+
else
71+
"${@}"
72+
return $?
73+
fi
74+
}
75+
76+
scanit() {
77+
export PATH="${PATH}:/opt/${COVERITY_BUILD_VERSION}/bin/"
78+
covbuild="${COVERITY_BUILD_PATH}"
79+
[ -z "${covbuild}" ] && covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
80+
if [ -z "${covbuild}" ]; then
81+
fatal "Cannot find 'cov-build' binary in \$PATH. Export variable COVERITY_BUILD_PATH or set it in .coverity-scan.conf"
82+
elif [ ! -x "${covbuild}" ]; then
83+
fatal "The command '${covbuild}' is not executable. Export variable COVERITY_BUILD_PATH or set it in .coverity-scan.conf"
84+
fi
85+
86+
version="$(grep "^#define PACKAGE_VERSION" config.h | cut -d '"' -f 2)"
87+
progress "Working on netdata version: ${version}"
88+
89+
progress "Cleaning up old builds..."
90+
run make clean || echo >&2 "Nothing to clean"
3491

35-
version="$(grep "^#define PACKAGE_VERSION" config.h | cut -d '"' -f 2)"
36-
echo >&2 "Working on netdata version: ${version}"
92+
[ -d "cov-int" ] && rm -rf "cov-int"
3793

38-
echo >&2 "Cleaning up old builds..."
39-
make clean || echo >&2 "Nothing to clean"
94+
[ -f netdata-coverity-analysis.tgz ] && run rm netdata-coverity-analysis.tgz
4095

41-
[ -d "cov-int" ] && rm -rf "cov-int"
96+
progress "Configuring netdata source..."
97+
run autoreconf -ivf
98+
run ./configure --disable-lto \
99+
--enable-https \
100+
--enable-jsonc \
101+
--enable-plugin-nfacct \
102+
--enable-plugin-freeipmi \
103+
--enable-plugin-cups \
104+
--enable-backend-prometheus-remote-write \
105+
${NULL}
42106

43-
[ -f netdata-coverity-analysis.tgz ] && rm netdata-coverity-analysis.tgz
107+
# TODO: enable these plugins too
108+
# --enable-plugin-xenstat \
109+
# --enable-backend-kinesis \
110+
# --enable-backend-mongodb \
44111

45-
autoreconf -ivf
46-
./configure --enable-plugin-nfacct --enable-plugin-freeipmi
47-
"${covbuild}" --dir cov-int make -j${cpus} || exit 1
112+
progress "Analyzing netdata..."
113+
run "${covbuild}" --dir cov-int make -j${cpus} || exit 1
48114

49-
echo >&2 "Compressing data..."
50-
tar czvf netdata-coverity-analysis.tgz cov-int || exit 1
115+
echo >&2 "Compressing analysis..."
116+
run tar czvf netdata-coverity-analysis.tgz cov-int || exit 1
51117

52-
echo >&2 "Sending analysis for version ${version} ..."
53-
COVERITY_SUBMIT_RESULT=$(curl --progress-bar --form token="${token}" \
54-
--form email=${COVERITY_SCAN_SUBMIT_MAIL} \
55-
56-
--form version="${version}" \
57-
--form description="netdata, real-time performance monitoring, done right." \
58-
https://scan.coverity.com/builds?project=${REPOSITORY})
118+
echo >&2 "Sending analysis to coverity for netdata version ${version} ..."
119+
COVERITY_SUBMIT_RESULT=$(debugrun curl --progress-bar \
120+
--form token="${token}" \
121+
--form email=${email} \
122+
123+
--form version="${version}" \
124+
--form description="netdata, monitor everything, in real-time." \
125+
https://scan.coverity.com/builds?project=${repo})
59126

60-
echo ${COVERITY_SUBMIT_RESULT} | grep -q -e 'Build successfully submitted' || echo >&2 "scan results were not pushed to coverity. Message was: ${COVERITY_SUBMIT_RESULT}"
127+
echo ${COVERITY_SUBMIT_RESULT} | grep -q -e 'Build successfully submitted' || echo >&2 "scan results were not pushed to coverity. Message was: ${COVERITY_SUBMIT_RESULT}"
61128

62-
echo >&2 "Coverity scan mechanism completed"
129+
progress "Coverity scan completed"
130+
}
131+
132+
installit() {
133+
progress "Downloading coverity..."
134+
cd /tmp || exit 1
135+
136+
[ -f "${COVERITY_BUILD_VERSION}.tar.gz" ] && run rm -f "${COVERITY_BUILD_VERSION}.tar.gz"
137+
debugrun curl --remote-name --remote-header-name --show-error --location --data "token=${token}&project=${repo}" https://scan.coverity.com/download/linux64
138+
139+
if [ -f "${COVERITY_BUILD_VERSION}.tar.gz" ]; then
140+
progress "Installing coverity..."
141+
cd /opt || exit 1
142+
run sudo tar -z -x -f "/tmp/${COVERITY_BUILD_VERSION}.tar.gz" || exit 1
143+
rm "/tmp/${COVERITY_BUILD_VERSION}.tar.gz"
144+
export PATH=${PATH}:/opt/${COVERITY_BUILD_VERSION}/bin/
145+
else
146+
fatal "Failed to download coverity tool tarball!"
147+
fi
148+
149+
# Validate the installation
150+
covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
151+
if [ -z "$covbuild" ]; then
152+
fatal "Failed to install coverity."
153+
fi
154+
155+
progress "Coverity scan tools are installed."
156+
return 0
157+
}
158+
159+
if [ "${1}" = "install" ]
160+
then
161+
shift 1
162+
installit "${@}"
163+
exit $?
164+
else
165+
scanit "${@}"
166+
exit $?
167+
fi

0 commit comments

Comments
 (0)