Enhance travis run script
[openjpeg.git] / tools / travis-ci / run.sh
1 #!/bin/bash
2
3 # This script executes the script step when running under travis-ci
4
5 # Set-up some bash options
6 set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
7 set -o errexit   ## set -e : exit the script if any statement returns a non-true return value
8 set -o pipefail  ## Fail on error in pipe
9
10 # Set-up some variables
11 OPJ_SOURCE_DIR=$(cd $(dirname $0)/../.. && pwd)
12
13 OPJ_DO_SUBMIT=0 # Do not flood cdash
14 if [ "${TRAVIS_REPO_SLUG:-}" != "" ]; then
15         OPJ_OWNER=$(echo "${TRAVIS_REPO_SLUG}" | sed 's/\(^.*\)\/.*/\1/')
16         OPJ_SITE="${OPJ_OWNER}.travis-ci.org"
17         if [ "${OPJ_OWNER}" == "uclouvain" ]; then
18                 OPJ_DO_SUBMIT=1
19         fi
20 else
21         OPJ_SITE="$(hostname)"
22 fi
23
24 if [ "${TRAVIS_OS_NAME:-}" == "" ]; then
25   # Let's guess OS for testing purposes
26         echo "Guessing OS"
27         if uname -s | grep -i Darwin &> /dev/null; then
28                 TRAVIS_OS_NAME=osx
29         elif uname -s | grep -i Linux &> /dev/null; then
30                 TRAVIS_OS_NAME=linux
31                 if [ "${CC:-}" == "" ]; then
32                         # default to gcc
33                         export CC=gcc
34                 fi
35         else
36                 echo "Failed to guess OS"; exit 1
37         fi
38         echo "${TRAVIS_OS_NAME}"
39 fi
40
41 if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
42         OPJ_OS_NAME=$(sw_vers -productName | tr -d ' ')$(sw_vers -productVersion | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
43         OPJ_CC_VERSION=$(xcodebuild -version | grep -i xcode)
44         OPJ_CC_VERSION=xcode${OPJ_CC_VERSION:6}
45 elif [ "${TRAVIS_OS_NAME}" == "linux" ]; then
46         OPJ_OS_NAME=linux
47         if which lsb_release > /dev/null; then
48                 OPJ_OS_NAME=$(lsb_release -si)$(lsb_release -sr | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
49         fi
50         if [ "${CC}" == "gcc" ]; then
51                 OPJ_CC_VERSION=gcc$(${CC} --version | head -1 | sed 's/.*\ \([0-9.]*[0-9]\)/\1/')
52         elif [ "${CC}" == "clang" ]; then
53                 OPJ_CC_VERSION=clang$(${CC} --version | grep version | sed 's/.*version \([^0-9.]*[0-9.]*\).*/\1/')
54         else
55                 echo "Compiler not supported: ${CC}"
56         fi
57 else
58         echo "OS not supported: ${TRAVIS_OS_NAME}"
59 fi
60
61 if [ "${TRAVIS_BRANCH:-}" == "" ]; then
62         echo "Guessing branch"
63         TRAVIS_BRANCH=$(git -C ../openjpeg branch | grep '*' | tr -d '*[[:blank:]]') #default to master
64 fi
65
66 OPJ_BUILDNAME=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${TRAVIS_BRANCH}
67 if [ "${TRAVIS_PULL_REQUEST:-}" != "false" ] && [ "${TRAVIS_PULL_REQUEST:-}" != "" ]; then
68         OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${TRAVIS_PULL_REQUEST}
69 fi
70 OPJ_BUILDNAME=${OPJ_BUILDNAME}-Release-3rdP
71
72 if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ -d kdu ]; then
73         echo "
74 Testing will use Kakadu trial binaries. Here's the copyright notice from kakadu:
75 Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
76 You are free to trial these executables and even to re-distribute them,
77 so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
78 Note: Binaries can only be used for non-commercial purposes.
79 "
80 fi
81
82 set -x
83 if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ -d kdu ]; then
84         if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
85                 export LD_LIBRARY_PATH=${PWD}/kdu:${LD_LIBRARY_PATH}
86         fi
87         export PATH=${PWD}/kdu:${PATH}
88 fi
89
90 mkdir build
91 cd build
92 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_CODEC=ON -DBUILD_THIRDPARTY=ON -DBUILD_TESTING=ON -DOPJ_DATA_ROOT=${PWD}/../data -DJPYLYZER_EXECUTABLE=${PWD}/../jpylyzer/jpylyzer/jpylyzer.py -DSITE=${OPJ_SITE} -DBUILDNAME=${OPJ_BUILDNAME} ${OPJ_SOURCE_DIR}
93 ctest -D ExperimentalStart
94 ctest -D ExperimentalBuild -V
95 ctest -D ExperimentalTest -j2 || true
96 ctest -D ExperimentalSubmit || true