travis-build.sh 2.0 KB

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