|
| 1 | +#!/bin/bash -u |
| 2 | +# We use set -e and bash with -u to bail on first non zero exit code of any |
| 3 | +# processes launched or upon any unbound variable. |
| 4 | +# We use set -x to print commands before running them to help with |
| 5 | +# debugging. |
| 6 | +set -ex |
| 7 | +__dirname=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
| 8 | +echo "using CC: $CC" |
| 9 | +echo "using TARGET: $TARGET" |
| 10 | + |
| 11 | +# Ensure APP defaults to rippled if it's not set. |
| 12 | +: ${APP:=rippled} |
| 13 | +if [[ ${BUILD:-scons} == "cmake" ]]; then |
| 14 | + echo "cmake building ${APP}" |
| 15 | + CMAKE_TARGET=$CC.$TARGET |
| 16 | + if [[ ${CI:-} == true ]]; then |
| 17 | + CMAKE_TARGET=$CMAKE_TARGET.ci |
| 18 | + fi |
| 19 | + mkdir -p "build/${CMAKE_TARGET}" |
| 20 | + pushd "build/${CMAKE_TARGET}" |
| 21 | + cmake ../.. -Dtarget=$CMAKE_TARGET |
| 22 | + cmake --build . -- -j${NUM_PROCESSORS:-2} |
| 23 | + popd |
| 24 | + export APP_PATH="$PWD/build/${CMAKE_TARGET}/${APP}" |
| 25 | + echo "using APP_PATH: $APP_PATH" |
| 26 | + |
| 27 | +else |
| 28 | + export APP_PATH="$PWD/build/$CC.$TARGET/${APP}" |
| 29 | + echo "using APP_PATH: $APP_PATH" |
| 30 | + # Make sure vcxproj is up to date |
| 31 | + scons vcxproj |
| 32 | + git diff --exit-code |
| 33 | + # $CC will be either `clang` or `gcc` |
| 34 | + # http://docs.travis-ci.com/user/migrating-from-legacy/?utm_source=legacy-notice&utm_medium=banner&utm_campaign=legacy-upgrade |
| 35 | + # indicates that 2 cores are available to containers. |
| 36 | + scons -j${NUM_PROCESSORS:-2} $CC.$TARGET |
| 37 | +fi |
| 38 | +# We can be sure we're using the build/$CC.$TARGET variant |
| 39 | +# (-f so never err) |
| 40 | +rm -f build/${APP} |
| 41 | + |
| 42 | +# See what we've actually built |
| 43 | +ldd $APP_PATH |
| 44 | + |
| 45 | +if [[ ${APP} == "rippled" ]]; then |
| 46 | + export APP_ARGS="--unittest --quiet --unittest-log" |
| 47 | + # Only report on src/ripple files |
| 48 | + export LCOV_FILES="*/src/ripple/*" |
| 49 | + # Nothing to explicitly exclude |
| 50 | + export LCOV_EXCLUDE_FILES="LCOV_NO_EXCLUDE" |
| 51 | +else |
| 52 | + : ${APP_ARGS:=} |
| 53 | + : ${LCOV_FILES:="*/src/*"} |
| 54 | + # Don't exclude anything |
| 55 | + : ${LCOV_EXCLUDE_FILES:="LCOV_NO_EXCLUDE"} |
| 56 | +fi |
| 57 | + |
| 58 | +if [[ $TARGET == "coverage" ]]; then |
| 59 | + export PATH=$PATH:$LCOV_ROOT/usr/bin |
| 60 | + |
| 61 | + # Create baseline coverage data file |
| 62 | + lcov --no-external -c -i -d . -o baseline.info |
| 63 | +fi |
| 64 | + |
| 65 | +if [[ ${TARGET} == debug ]]; then |
| 66 | + # Execute unit tests under gdb, printing a call stack |
| 67 | + # if we get a crash. |
| 68 | + $GDB_ROOT/bin/gdb -return-child-result -quiet -batch \ |
| 69 | + -ex "set env MALLOC_CHECK_=3" \ |
| 70 | + -ex "set print thread-events off" \ |
| 71 | + -ex run \ |
| 72 | + -ex "thread apply all backtrace full" \ |
| 73 | + -ex "quit" \ |
| 74 | + --args $APP_PATH $APP_ARGS |
| 75 | +else |
| 76 | + $APP_PATH $APP_ARGS |
| 77 | +fi |
| 78 | + |
| 79 | +if [[ $TARGET == "coverage" ]]; then |
| 80 | + # Create test coverage data file |
| 81 | + lcov --no-external -c -d . -o tests.info |
| 82 | + |
| 83 | + # Combine baseline and test coverage data |
| 84 | + lcov -a baseline.info -a tests.info -o lcov-all.info |
| 85 | + |
| 86 | + # Included files |
| 87 | + lcov -e "lcov-all.info" "${LCOV_FILES}" -o lcov.pre.info |
| 88 | + |
| 89 | + # Excluded files |
| 90 | + lcov --remove lcov.pre.info "${LCOV_EXCLUDE_FILES}" -o lcov.info |
| 91 | + |
| 92 | + # Push the results (lcov.info) to codecov |
| 93 | + codecov -X gcov # don't even try and look for .gcov files ;) |
| 94 | +fi |
| 95 | + |
| 96 | + |
0 commit comments