3 # Copyright (C) 2015 - Michael Jeanson <mjeanson@efficios.com>
4 # Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # The project name and token have to be provided trough env variables
21 #COVERITY_SCAN_PROJECT_NAME=""
22 #COVERITY_SCAN_TOKEN=""
23 COVERITY_SCAN_DESCRIPTION
="Automated CI build"
24 COVERITY_SCAN_NOTIFICATION_EMAIL
="ci-notification@lists.lttng.org"
25 COVERITY_SCAN_BUILD_OPTIONS
=""
26 #COVERITY_SCAN_BUILD_OPTIONS="--return-emit-failures 8 --parse-error-threshold 85"
28 SRCDIR
="$WORKSPACE/src/${COVERITY_SCAN_PROJECT_NAME}"
29 TMPDIR
="$WORKSPACE/tmp"
33 export CFLAGS
="-O0 -g -DDEBUG"
35 TOOL_ARCHIVE
="$TMPDIR/cov-analysis-${PLATFORM}.tgz"
36 TOOL_URL
=https
://scan.coverity.com
/download
/${PLATFORM}
37 TOOL_BASE
="$TMPDIR/coverity-scan-analysis"
39 UPLOAD_URL
="https://scan.coverity.com/builds"
40 SCAN_URL
="https://scan.coverity.com"
42 RESULTS_DIR_NAME
="cov-int"
43 RESULTS_DIR
="$WORKSPACE/$RESULTS_DIR_NAME"
44 RESULTS_ARCHIVE
=analysis-results.tgz
46 # Create tmp directory
52 case "$COVERITY_SCAN_PROJECT_NAME" in
54 CONF_OPTS
="--enable-python-bindings --enable-python-bindings-doc"
66 CONF_OPTS
="--enable-java-agent-all --enable-python-agent"
67 export CLASSPATH
="/usr/share/java/log4j-1.2.jar"
70 echo "Generic project, no configure options."
76 if [ -d "$WORKSPACE/deps/liburcu" ]; then
77 URCU_INCS
="$WORKSPACE/deps/liburcu/build/include/"
78 URCU_LIBS
="$WORKSPACE/deps/liburcu/build/lib/"
80 export CPPFLAGS
="-I$URCU_INCS ${CPPFLAGS:-}"
81 export LDFLAGS
="-L$URCU_LIBS ${LDFLAGS:-}"
82 export LD_LIBRARY_PATH
="$URCU_LIBS:${LD_LIBRARY_PATH:-}"
86 # lttng-ust dependency
87 if [ -d "$WORKSPACE/deps/lttng-ust" ]; then
88 UST_INCS
="$WORKSPACE/deps/lttng-ust/build/include/"
89 UST_LIBS
="$WORKSPACE/deps/lttng-ust/build/lib/"
91 export CPPFLAGS
="-I$UST_INCS ${CPPFLAGS:-}"
92 export LDFLAGS
="-L$UST_LIBS ${LDFLAGS:-}"
93 export LD_LIBRARY_PATH
="$UST_LIBS:${LD_LIBRARY_PATH:-}"
96 if [ -d "$WORKSPACE/src/linux" ]; then
97 export KERNELDIR
="$WORKSPACE/src/linux"
101 # Verify upload is permitted
103 AUTH_RES
=$
(curl
-s --form project
="$COVERITY_SCAN_PROJECT_NAME" --form token
="$COVERITY_SCAN_TOKEN" $SCAN_URL/api
/upload_permitted
)
105 if [ "$AUTH_RES" = "Access denied" ]; then
106 echo -e "\033[33;1mCoverity Scan API access denied. Check COVERITY_SCAN_PROJECT_NAME and COVERITY_SCAN_TOKEN.\033[0m"
109 AUTH
=$
(echo "$AUTH_RES" | jq .upload_permitted
)
110 if [ "$AUTH" = "true" ]; then
111 echo -e "\033[33;1mCoverity Scan analysis authorized per quota.\033[0m"
113 WHEN
=$
(echo "$AUTH_RES" | jq .next_upload_permitted_at
)
114 echo -e "\033[33;1mCoverity Scan analysis NOT authorized until $WHEN.\033[0m"
120 # Download Coverity Scan Analysis Tool
121 if [ ! -d "$TOOL_BASE" ]; then
122 if [ ! -e "$TOOL_ARCHIVE" ]; then
123 echo -e "\033[33;1mDownloading Coverity Scan Analysis Tool...\033[0m"
125 wget
-nv -O "$TOOL_ARCHIVE" "$TOOL_URL" --post-data "project=$COVERITY_SCAN_PROJECT_NAME&token=$COVERITY_SCAN_TOKEN"
129 # Extract Coverity Scan Analysis Tool
130 echo -e "\033[33;1mExtracting Coverity Scan Analysis Tool...\033[0m"
131 mkdir
-p "$TOOL_BASE"
132 cd "$TOOL_BASE" ||
exit 1
133 tar xzf
"$TOOL_ARCHIVE"
137 TOOL_DIR
=$
(find "$TOOL_BASE" -type d
-name 'cov-analysis*')
138 export PATH
=$TOOL_DIR/bin
:$PATH
142 COVERITY_SCAN_VERSION
=$
(git describe
--always |
sed 's|-|.|g')
145 if [ -f "./bootstrap" ]; then
147 .
/configure
$CONF_OPTS
151 echo -e "\033[33;1mRunning Coverity Scan Analysis Tool...\033[0m"
152 cov-build
--dir "$RESULTS_DIR" $COVERITY_SCAN_BUILD_OPTIONS make -j"$NPROC" V
=1
153 cov-import-scm
--dir "$RESULTS_DIR" --scm git
--log "$RESULTS_DIR/scm_log.txt"
158 echo -e "\033[33;1mTarring Coverity Scan Analysis results...\033[0m"
159 tar czf
$RESULTS_ARCHIVE $RESULTS_DIR_NAME
162 echo -e "\033[33;1mUploading Coverity Scan Analysis results...\033[0m"
165 --silent --write-out "\n%{http_code}\n" \
166 --form project
="$COVERITY_SCAN_PROJECT_NAME" \
167 --form token
="$COVERITY_SCAN_TOKEN" \
168 --form email
="$COVERITY_SCAN_NOTIFICATION_EMAIL" \
169 --form file=@
"$RESULTS_ARCHIVE" \
170 --form version
="$COVERITY_SCAN_VERSION" \
171 --form description
="$COVERITY_SCAN_DESCRIPTION" \
174 status_code
=$
(echo "$response" |
sed -n '$p')
175 if [ "$status_code" != "201" ]; then
176 TEXT
=$
(echo "$response" |
sed '$d')
177 echo -e "\033[33;1mCoverity Scan upload failed: $TEXT.\033[0m"