make coverity-scan.sh usable by hand (#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 --
Costa Tsaousis committed
Aug 31, 2019 at 21:10 UTC
fd9eb73ccc705846eeaf816c590187077a9b7450
3 files changed
+145
-75
.gitignore
+1
-2
@@ -77,8 +77,7 @@ packaging/makeself/tmp/
77
# coverity
78
cov-int/
79
netdata-coverity-analysis.tgz
80
-.coverity-token
81
-.coverity-build
80
+.coverity-scan.conf
81
82
.cproject/
83
.idea/
coverity-install.sh
+1
-35
@@ -5,38 +5,4 @@
5
#
6
# Author: Pavlos Emm. Katsoulakis (paul@netdata.cloud)
7
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 "${@}"
coverity-scan.sh
+143
-38
@@ -1,62 +1,167 @@
1
#!/usr/bin/env bash
2
# Coverity scan script
3
#
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
-#
4
# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# Author : Costa Tsaousis (costa@netdata.cloud)
7
# Author : Pawel Krupa (paulfantom)
8
# Author : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
9
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="you@example.com"
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)
39
[ -z "${cpus}" ] && cpus=1
40
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
+
57
token="${COVERITY_SCAN_TOKEN}"
18
-([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)"
58
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"
60
fi
61
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"
91
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"
93
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
95
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}
106
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 \
111
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
114
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
117
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
- --form file=@netdata-coverity-analysis.tgz \
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
+ --form file=@netdata-coverity-analysis.tgz \
123
+ --form version="${version}" \
124
+ --form description="netdata, monitor everything, in real-time." \
125
+ https://scan.coverity.com/builds?project=${repo})
126
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}"
128
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