blob: 81680f069a7eac67a16e1685b05a1bdf6463526c [file] [log] [blame]
Chris Lukecd764362017-05-29 10:02:45 -04001#!/bin/bash
2
3# FD.io VPP Coverity build script
4#
5# Builds VPP with the Coverity wrapper and if successful submits
6# it to the Coverity scan service for processing.
7#
8# Several environment variables are needed:
9#
10# COVERITY_TOKEN The Coverity Scan API token for this project
11# COVERITY_TOOLS The location of the Coverity tools
12#
13# The coverity tools can be fetched with:
14# wget https://scan.coverity.com/download/linux64 \
15# --post-data "token=${COVERITY_TOKEN}&project=fd.io+VPP" \
16# -O coverity_tool.tgz
17
18set -ex
19
20token=${COVERITY_TOKEN}
21email=vpp-committers@lists.fd.io
22project="fd.io VPP"
23project_encoded="fd.io+VPP"
24url=https://scan.coverity.com
25
26# Cosmetic labels for the Coverity build logs
27export COV_HOST=$(hostname -f)
28export COV_USER=vpp
29
30# Work out where the root and build-root are
31script_dir=$(readlink -f $(dirname $0))
32root_dir=$(readlink -f "${script_dir}/../..")
33build_dir=$(readlink -f "${script_dir}/../../build-root")
34
35# Location for Coverity things
36covdir="${build_dir}/cov-int"
37COVERITY_TOOLS="${COVERITY_TOOLS-/scratch/cov-analysis-latest}"
38
39# Before we run the build, check that we can submit one
40check=$(curl -s --form project="${project}" \
41 --form token="${token}" "${url}/api/upload_permitted")
42if [ "${check}" = "Access denied" ]; then
43 echo "Bad token or project name."
44 exit 1
45fi
46if [ "${check}" != '{"upload_permitted":true}' ]; then
47 echo "Upload not permitted; stop now..."
48 exit 1
49fi
50
51version=$(git describe)
52
53# Run the build
54cd "${root_dir}"
55"${COVERITY_TOOLS}/bin/cov-build" --dir "${covdir}" make bootstrap build-coverity
56cd "${build_dir}"
57
58# Tar the build artifacts that scan wants
59tar -czf fd.io-vpp.tgz "$(basename ${covdir})"
60rm -rf "${covdir}"
61
62# Submit the build
63echo curl --form token="${token}" \
64 --form email="${email}" \
65 --form file=@fd.io-vpp.tgz \
66 --form version="${version}" \
67 --form description="master:${version}" \
68 "${url}/builds?project=${project_encoded}"
69
70# All done!