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