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