Chris Luke | cd76436 | 2017-05-29 10:02:45 -0400 | [diff] [blame] | 1 | #!/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 | |
| 18 | set -ex |
| 19 | |
| 20 | token=${COVERITY_TOKEN} |
| 21 | email=vpp-committers@lists.fd.io |
| 22 | project="fd.io VPP" |
| 23 | project_encoded="fd.io+VPP" |
| 24 | url=https://scan.coverity.com |
| 25 | |
| 26 | # Cosmetic labels for the Coverity build logs |
| 27 | export COV_HOST=$(hostname -f) |
| 28 | export COV_USER=vpp |
| 29 | |
| 30 | # Work out where the root and build-root are |
| 31 | script_dir=$(readlink -f $(dirname $0)) |
| 32 | root_dir=$(readlink -f "${script_dir}/../..") |
| 33 | build_dir=$(readlink -f "${script_dir}/../../build-root") |
| 34 | |
| 35 | # Location for Coverity things |
| 36 | covdir="${build_dir}/cov-int" |
| 37 | COVERITY_TOOLS="${COVERITY_TOOLS-/scratch/cov-analysis-latest}" |
| 38 | |
| 39 | # Before we run the build, check that we can submit one |
| 40 | check=$(curl -s --form project="${project}" \ |
| 41 | --form token="${token}" "${url}/api/upload_permitted") |
| 42 | if [ "${check}" = "Access denied" ]; then |
| 43 | echo "Bad token or project name." |
| 44 | exit 1 |
| 45 | fi |
| 46 | if [ "${check}" != '{"upload_permitted":true}' ]; then |
| 47 | echo "Upload not permitted; stop now..." |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | version=$(git describe) |
| 52 | |
| 53 | # Run the build |
| 54 | cd "${root_dir}" |
| 55 | "${COVERITY_TOOLS}/bin/cov-build" --dir "${covdir}" make bootstrap build-coverity |
| 56 | cd "${build_dir}" |
| 57 | |
| 58 | # Tar the build artifacts that scan wants |
| 59 | tar -czf fd.io-vpp.tgz "$(basename ${covdir})" |
| 60 | rm -rf "${covdir}" |
| 61 | |
| 62 | # Submit the build |
| 63 | echo 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! |