1#!/bin/bash 2 3set -ex 4 5setup_env() { 6 # Travis sets CC/CXX to the system toolchain, so our .travis.yml 7 # exports USE_{CC,CXX} for this script to use. 8 if [ -n "$USE_CC" ]; then 9 export CC=$USE_CC 10 fi 11 if [ -n "$USE_CXX" ]; then 12 export CXX=$USE_CXX 13 fi 14 # Use -jN for faster builds. Travis build machines under Docker 15 # have a lot of cores, but are memory-limited, so the kernel 16 # will OOM if we try to use them all, so use at most 4. 17 # See https://github.com/travis-ci/travis-ci/issues/1972 18 export NCPUS=$(getconf _NPROCESSORS_ONLN) 19 export JOBS=$(( $NCPUS < 4 ? $NCPUS : 4 )) 20} 21 22# We have to do this by hand rather than use the coverity addon because of 23# matrix explosion: https://github.com/travis-ci/travis-ci/issues/1975 24# We also do it by hand because when we're throttled, the addon will exit 25# the build immediately and skip the main script! 26coverity_scan() { 27 if [ "${COVERITY_SCAN}" != "true" ] || \ 28 [ -n "${TRAVIS_TAG}" ] || \ 29 [ "${TRAVIS_PULL_REQUEST}" = "true" ] 30 then 31 echo "Skipping coverity scan." 32 return 33 fi 34 35 export COVERITY_SCAN_PROJECT_NAME="${TRAVIS_REPO_SLUG}" 36 export COVERITY_SCAN_NOTIFICATION_EMAIL="google-breakpad-dev@googlegroups.com" 37 export COVERITY_SCAN_BUILD_COMMAND="make -j${JOBS}" 38 export COVERITY_SCAN_BUILD_COMMAND_PREPEND="git clean -q -x -d -f; git checkout -f; ./configure" 39 export COVERITY_SCAN_BRANCH_PATTERN="master" 40 41 curl -s "https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh" | bash || : 42} 43 44# Do an in-tree build and make sure tests pass. 45build() { 46 ./configure --with-tests-as-root 47 make -j${JOBS} check VERBOSE=1 48 make distclean 49} 50 51# Do an out-of-tree build and make sure we can create a release tarball. 52build_out_of_tree() { 53 mkdir -p build/native 54 pushd build/native >/dev/null 55 ../../configure --with-tests-as-root 56 make -j${JOBS} distcheck VERBOSE=1 57 popd >/dev/null 58} 59 60main() { 61 setup_env 62 build 63 build_out_of_tree 64 65 # Do scans last as they like to dirty the tree and some tests 66 # expect a clean tree (like code style checks). 67 coverity_scan 68} 69 70main "$@" 71