Merge branch 'master' into coc-qcc
[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 if [ "${OPJ_CI_BUILD_CONFIGURATION:-}" == "" ]; then
12         export OPJ_CI_BUILD_CONFIGURATION=Release #default
13 fi
14 OPJ_SOURCE_DIR=$(cd $(dirname $0)/../.. && pwd)
15
16 if [ "${OPJ_DO_SUBMIT:-}" == "" ]; then
17         OPJ_DO_SUBMIT=0 # Do not flood cdash by default
18 fi
19 if [ "${TRAVIS_REPO_SLUG:-}" != "" ]; then
20         OPJ_OWNER=$(echo "${TRAVIS_REPO_SLUG}" | sed 's/\(^.*\)\/.*/\1/')
21         OPJ_SITE="${OPJ_OWNER}.travis-ci.org"
22         if [ "${OPJ_OWNER}" == "uclouvain" ]; then
23                 OPJ_DO_SUBMIT=1
24         fi
25 else
26         OPJ_SITE="$(hostname)"
27 fi
28
29 if [ "${TRAVIS_OS_NAME:-}" == "" ]; then
30   # Let's guess OS for testing purposes
31         echo "Guessing OS"
32         if uname -s | grep -i Darwin &> /dev/null; then
33                 TRAVIS_OS_NAME=osx
34         elif uname -s | grep -i Linux &> /dev/null; then
35                 TRAVIS_OS_NAME=linux
36                 if [ "${CC:-}" == "" ]; then
37                         # default to gcc
38                         export CC=gcc
39                 fi
40         else
41                 echo "Failed to guess OS"; exit 1
42         fi
43         echo "${TRAVIS_OS_NAME}"
44 fi
45
46 if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
47         OPJ_OS_NAME=$(sw_vers -productName | tr -d ' ')$(sw_vers -productVersion | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
48         OPJ_CC_VERSION=$(xcodebuild -version | grep -i xcode)
49         OPJ_CC_VERSION=xcode${OPJ_CC_VERSION:6}
50 elif [ "${TRAVIS_OS_NAME}" == "linux" ]; then
51         OPJ_OS_NAME=linux
52         if which lsb_release > /dev/null; then
53                 OPJ_OS_NAME=$(lsb_release -si)$(lsb_release -sr | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
54         fi
55         if [ -z "${CC##*gcc*}" ]; then
56                 OPJ_CC_VERSION=$(${CC} --version | head -1 | sed 's/.*\ \([0-9.]*[0-9]\)/\1/')
57                 if [ -z "${CC##*mingw*}" ]; then
58                         OPJ_CC_VERSION=mingw${OPJ_CC_VERSION}
59                         # disable testing for now
60                         export OPJ_CI_SKIP_TESTS=1
61                 else
62                         OPJ_CC_VERSION=gcc${OPJ_CC_VERSION}
63                 fi
64         elif [ -z "${CC##*clang*}" ]; then
65                 OPJ_CC_VERSION=clang$(${CC} --version | grep version | sed 's/.*version \([^0-9.]*[0-9.]*\).*/\1/')
66         else
67                 echo "Compiler not supported: ${CC}"; exit 1
68         fi
69 else
70         echo "OS not supported: ${TRAVIS_OS_NAME}"; exit 1
71 fi
72
73 if [ "${OPJ_CI_ARCH:-}" == "" ]; then
74         echo "Guessing build architecture"
75         MACHINE_ARCH=$(uname -m)
76         if [ "${MACHINE_ARCH}" == "x86_64" ]; then
77                 export OPJ_CI_ARCH=x86_64
78         fi
79         echo "${OPJ_CI_ARCH}"
80 fi
81
82 if [ "${TRAVIS_BRANCH:-}" == "" ]; then
83         echo "Guessing branch"
84         TRAVIS_BRANCH=$(git -C ${OPJ_SOURCE_DIR} branch | grep '*' | tr -d '*[[:blank:]]') #default to master
85 fi
86
87 OPJ_BUILDNAME=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}-${TRAVIS_BRANCH}
88 OPJ_BUILDNAME_TEST=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}
89 if [ "${TRAVIS_PULL_REQUEST:-}" != "false" ] && [ "${TRAVIS_PULL_REQUEST:-}" != "" ]; then
90         OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${TRAVIS_PULL_REQUEST}
91 fi
92 OPJ_BUILDNAME=${OPJ_BUILDNAME}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
93 OPJ_BUILDNAME_TEST=${OPJ_BUILDNAME_TEST}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
94 if [ "${OPJ_CI_ASAN:-}" == "1" ]; then
95         OPJ_BUILDNAME=${OPJ_BUILDNAME}-ASan
96         OPJ_BUILDNAME_TEST=${OPJ_BUILDNAME_TEST}-ASan
97 fi
98
99 if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ] && [ -d kdu ]; then
100         echo "
101 Testing will use Kakadu trial binaries. Here's the copyright notice from kakadu:
102 Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
103 You are free to trial these executables and even to re-distribute them,
104 so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
105 Note: Binaries can only be used for non-commercial purposes.
106 "
107 fi
108
109 if [ -d cmake-install ]; then
110         export PATH=${PWD}/cmake-install/bin:${PATH}
111 fi
112
113 set -x
114 # This will print configuration
115 # travis-ci doesn't dump cmake version in system info, let's print it 
116 cmake --version
117
118 export OPJ_SITE=${OPJ_SITE}
119 export OPJ_BUILDNAME=${OPJ_BUILDNAME}
120 export OPJ_SOURCE_DIR=${OPJ_SOURCE_DIR}
121 export OPJ_BUILD_CONFIGURATION=${OPJ_CI_BUILD_CONFIGURATION}
122 export OPJ_DO_SUBMIT=${OPJ_DO_SUBMIT}
123
124 ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V || true
125 # ctest will exit with various error codes depending on version.
126 # ignore ctest exit code & parse this ourselves
127 set +x
128
129 # let's parse configure/build/tests for failure
130
131 echo "
132 Parsing logs for failures
133 "
134 OPJ_CI_RESULT=0
135
136 # 1st configure step
137 OPJ_CONFIGURE_XML=$(find build -path 'build/Testing/*' -name 'Configure.xml')
138 if [ ! -f "${OPJ_CONFIGURE_XML}" ]; then
139         echo "No configure log found"
140         OPJ_CI_RESULT=1
141 else
142         if ! grep '<ConfigureStatus>0</ConfigureStatus>' ${OPJ_CONFIGURE_XML} &> /dev/null; then
143                 echo "Errors were found in configure log"
144                 OPJ_CI_RESULT=1
145         fi
146 fi
147
148 # 2nd build step
149 # We must have one Build.xml file
150 OPJ_BUILD_XML=$(find build -path 'build/Testing/*' -name 'Build.xml')
151 if [ ! -f "${OPJ_BUILD_XML}" ]; then
152         echo "No build log found"
153         OPJ_CI_RESULT=1
154 else
155         if grep '<Error>' ${OPJ_BUILD_XML} &> /dev/null; then
156                 echo "Errors were found in build log"
157                 OPJ_CI_RESULT=1
158         fi
159 fi
160
161 if [ ${OPJ_CI_RESULT} -ne 0 ]; then
162         # Don't trash output with failing tests when there are configure/build errors
163         exit ${OPJ_CI_RESULT}
164 fi
165
166 if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then
167         OPJ_TEST_XML=$(find build -path 'build/Testing/*' -name 'Test.xml')
168         if [ ! -f "${OPJ_TEST_XML}" ]; then
169                 echo "No test log found"
170                 OPJ_CI_RESULT=1
171         else
172                 echo "Parsing tests for new/unknown failures"
173                 # 3rd test step
174                 OPJ_FAILEDTEST_LOG=$(find build -path 'build/Testing/Temporary/*' -name 'LastTestsFailed_*.log')
175                 if [ -f "${OPJ_FAILEDTEST_LOG}" ]; then
176                         awk -F: '{ print $2 }' ${OPJ_FAILEDTEST_LOG} > failures.txt
177                         while read FAILEDTEST; do
178                                 # Start with common errors
179                                 if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-all.txt > /dev/null; then
180                                         continue
181                                 fi
182                                 if [ -f ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt ]; then
183                                         if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt > /dev/null; then
184                                                 continue
185                                         fi
186                                 fi
187                                 echo "${FAILEDTEST}"
188                                 OPJ_CI_RESULT=1
189                         done < failures.txt
190                 fi
191         fi
192         
193         if [ ${OPJ_CI_RESULT} -eq 0 ]; then
194                 echo "No new/unknown test failure found
195                 "
196         else
197                 echo "
198 New/unknown test failure found!!!
199         "
200         fi
201         
202         # 4th memcheck step
203         OPJ_MEMCHECK_XML=$(find build -path 'build/Testing/*' -name 'DynamicAnalysis.xml')
204         if [ -f "${OPJ_MEMCHECK_XML}" ]; then
205                 if grep '<Defect Type' ${OPJ_MEMCHECK_XML} 2> /dev/null; then
206                         echo "Errors were found in dynamic analysis log"
207                         OPJ_CI_RESULT=1
208                 fi
209         fi
210
211
212 fi
213
214 exit ${OPJ_CI_RESULT}