|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | # Coverity scan script
|
3 | 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 |
| -# |
8 | 4 | # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
|
9 | 5 | #
|
10 | 6 | # Author : Costa Tsaousis ([email protected])
|
11 | 7 | # Author : Pawel Krupa (paulfantom)
|
12 | 8 | # Author : Pavlos Emm. Katsoulakis ([email protected])
|
13 | 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="[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) |
15 | 39 | [ -z "${cpus}" ] && cpus=1
|
16 | 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 | + |
17 | 57 | token="${COVERITY_SCAN_TOKEN}"
|
18 |
| -([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)" |
19 | 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" |
22 | 60 | fi
|
23 | 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" |
34 | 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" |
37 | 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 |
40 | 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} |
42 | 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 \ |
44 | 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 |
48 | 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 |
51 | 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 |
| - |
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}) |
59 | 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}" |
61 | 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 |
0 commit comments