diff --git a/.travis.sh b/.travis.sh index b27ec81b0..2a9e1f213 100755 --- a/.travis.sh +++ b/.travis.sh @@ -1,46 +1,85 @@ #!/bin/bash -set -e # Make sure any error makes the script to return an error code -set -x # echo - -SOURCE_DIR=`pwd` -BUILD_DIR=build - -#CMAKE_C_FLAGS="-Wall -Wextra -Wabi -O2" -#CMAKE_CXX_FLAGS="-Wall -Wextra -Wabi -O2" - -function build_and_test () +# common tasks before either build or test +function prepare () { + set -e # Make sure any error makes the script to return an error code + set -x # echo + + SOURCE_DIR=`pwd` + BUILD_DIR=build + #env git clean -fd || true rm -fr $BUILD_DIR || true mkdir $BUILD_DIR && cd $BUILD_DIR + if [ -z "$CMAKE_BUILD_TYPE" ]; then + CMAKE_BUILD_TYPE=Debug + fi + + if [ -z "$GTSAM_ALLOW_DEPRECATED_SINCE_V4" ]; then + GTSAM_ALLOW_DEPRECATED_SINCE_V4=OFF + fi + if [ ! -z "$GCC_VERSION" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 60 \ --slave /usr/bin/g++ g++ /usr/bin/g++-$GCC_VERSION sudo update-alternatives --set gcc /usr/bin/gcc-$GCC_VERSION fi +} - cmake $SOURCE_DIR \ - -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ - -DGTSAM_BUILD_TESTS=$GTSAM_BUILD_TESTS \ - -DGTSAM_BUILD_UNSTABLE=$GTSAM_BUILD_UNSTABLE \ - -DGTSAM_BUILD_EXAMPLES_ALWAYS=$GTSAM_BUILD_EXAMPLES_ALWAYS \ - -DGTSAM_ALLOW_DEPRECATED_SINCE_V4=$GTSAM_ALLOW_DEPRECATED_SINCE_V4 - - # Actual build: - make -j2 - - # Run tests: - if [ "$GTSAM_BUILD_TESTS" == "ON" ]; then - make check - fi - +# common tasks after either build or test +function finish () +{ # Print ccache stats ccache -s cd $SOURCE_DIR } -build_and_test +# compile the code with the intent of populating the cache +function build () +{ + prepare + + cmake $SOURCE_DIR \ + -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ + -DGTSAM_BUILD_TESTS=OFF \ + -DGTSAM_BUILD_UNSTABLE=ON \ + -DGTSAM_BUILD_EXAMPLES_ALWAYS=ON \ + -DGTSAM_ALLOW_DEPRECATED_SINCE_V4=$GTSAM_ALLOW_DEPRECATED_SINCE_V4 + + # Actual build: + make -j2 + + finish +} + +# run the tests +function test () +{ + prepare + + cmake $SOURCE_DIR \ + -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ + -DGTSAM_BUILD_TESTS=ON \ + -DGTSAM_BUILD_UNSTABLE=ON \ + -DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \ + -DGTSAM_ALLOW_DEPRECATED_SINCE_V4=OFF + + # Actual build: + make -j2 check + + finish +} + +# select between build or test +case $1 in + -b) + build + ;; + -t) + test + ;; +esac diff --git a/.travis.yml b/.travis.yml index d8d1c07b5..bdf8d570a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,9 +23,6 @@ install: - if [ "$TRAVIS_OS_NAME" == "osx" ]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install ccache ; fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH" ; fi -script: - - bash .travis.sh - # We first do the compile stage specified below, then the matrix expansion specified after. stages: - compile @@ -38,43 +35,52 @@ jobs: - stage: compile os: osx compiler: gcc - env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Debug + script: bash .travis.sh -b - stage: compile os: osx compiler: gcc - env: CMAKE_BUILD_TYPE=Release GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Release + script: bash .travis.sh -b # on Mac, CLANG - stage: compile os: osx compiler: clang - env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Debug + script: bash .travis.sh -b - stage: compile os: osx compiler: clang - env: CMAKE_BUILD_TYPE=Release GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Release + script: bash .travis.sh -b # on Linux, GCC - stage: compile os: linux compiler: gcc - env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Debug + script: bash .travis.sh -b - stage: compile os: linux compiler: gcc - env: CMAKE_BUILD_TYPE=Release GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Release + script: bash .travis.sh -b # on Linux, CLANG - stage: compile os: linux compiler: clang - env: CMAKE_BUILD_TYPE=Debug GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Debug + script: bash .travis.sh -b - stage: compile os: linux compiler: clang - env: CMAKE_BUILD_TYPE=Release GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Release + script: bash .travis.sh -b # on Linux, with deprecated ON to make sure that path still compiles - stage: compile os: linux compiler: clang - env: GTSAM_ALLOW_DEPRECATED_SINCE_V4=ON GTSAM_BUILD_TESTS=OFF GTSAM_BUILD_EXAMPLES_ALWAYS=ON + env: CMAKE_BUILD_TYPE=Debug GTSAM_ALLOW_DEPRECATED_SINCE_V4=ON + script: bash .travis.sh -b # Matrix configuration: os: @@ -87,13 +93,12 @@ env: global: - MAKEFLAGS="-j2" - CCACHE_SLOPPINESS=pch_defines,time_macros - - GTSAM_BUILD_UNSTABLE=ON - GTSAM_ALLOW_DEPRECATED_SINCE_V4=OFF - - GTSAM_BUILD_EXAMPLES_ALWAYS=OFF - - GTSAM_BUILD_TESTS=ON matrix: - CMAKE_BUILD_TYPE=Debug - CMAKE_BUILD_TYPE=Release +script: + - bash .travis.sh -t # Uncomment this if you want to exclude clang on linux # matrix: