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