change os guessing
[openjpeg.git] / tools / travis-ci / run.sh
index ec3b7d345d0518616be3285257b17c7dc206bee8..45658738b6a363dc6781a0eff884c62d00805a7b 100755 (executable)
@@ -2,11 +2,30 @@
 
 # This script executes the script step when running under travis-ci
 
+#if cygwin, check path
+case ${MACHTYPE} in
+       *cygwin*) OPJ_CI_IS_CYGWIN=1;;
+       *) ;;
+esac
+
+if [ "${OPJ_CI_IS_CYGWIN:-}" == "1" ]; then
+       # Hack for appveyor
+       if ! which wget; then
+               # PATH is not yet set up
+               export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+       fi
+fi
+
 # Set-up some bash options
 set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
 set -o errexit   ## set -e : exit the script if any statement returns a non-true return value
 set -o pipefail  ## Fail on error in pipe
 
+# ABI check is done by abi-check.sh
+if [ "${OPJ_CI_ABI_CHECK:-}" == "1" ]; then
+       exit 0
+fi
+
 # Set-up some variables
 if [ "${OPJ_CI_BUILD_CONFIGURATION:-}" == "" ]; then
        export OPJ_CI_BUILD_CONFIGURATION=Release #default
@@ -37,6 +56,8 @@ if [ "${TRAVIS_OS_NAME:-}" == "" ]; then
                        # default to gcc
                        export CC=gcc
                fi
+       elif uname -s | grep -i CYGWIN &> /dev/null; then
+               TRAVIS_OS_NAME=windows
        else
                echo "Failed to guess OS"; exit 1
        fi
@@ -66,6 +87,9 @@ elif [ "${TRAVIS_OS_NAME}" == "linux" ]; then
        else
                echo "Compiler not supported: ${CC}"; exit 1
        fi
+elif [ "${TRAVIS_OS_NAME}" == "windows" ]; then
+       OPJ_OS_NAME=windows
+       OPJ_CC_VERSION=vs2015
 else
        echo "OS not supported: ${TRAVIS_OS_NAME}"; exit 1
 fi
@@ -80,14 +104,20 @@ if [ "${OPJ_CI_ARCH:-}" == "" ]; then
 fi
 
 if [ "${TRAVIS_BRANCH:-}" == "" ]; then
-       echo "Guessing branch"
-       TRAVIS_BRANCH=$(git -C ${OPJ_SOURCE_DIR} branch | grep '*' | tr -d '*[[:blank:]]') #default to master
+       if [ "${APPVEYOR_REPO_BRANCH:-}" != "" ]; then
+               TRAVIS_BRANCH=${APPVEYOR_REPO_BRANCH}
+       else
+               echo "Guessing branch"
+               TRAVIS_BRANCH=$(git -C ${OPJ_SOURCE_DIR} branch | grep '*' | tr -d '*[[:blank:]]')
+       fi
 fi
 
 OPJ_BUILDNAME=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}-${TRAVIS_BRANCH}
 OPJ_BUILDNAME_TEST=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}
 if [ "${TRAVIS_PULL_REQUEST:-}" != "false" ] && [ "${TRAVIS_PULL_REQUEST:-}" != "" ]; then
        OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${TRAVIS_PULL_REQUEST}
+elif [ "${APPVEYOR_PULL_REQUEST_NUMBER:-}" != "" ]; then
+       OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${APPVEYOR_PULL_REQUEST_NUMBER}
 fi
 OPJ_BUILDNAME=${OPJ_BUILDNAME}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
 OPJ_BUILDNAME_TEST=${OPJ_BUILDNAME_TEST}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
@@ -121,44 +151,92 @@ export OPJ_SOURCE_DIR=${OPJ_SOURCE_DIR}
 export OPJ_BUILD_CONFIGURATION=${OPJ_CI_BUILD_CONFIGURATION}
 export OPJ_DO_SUBMIT=${OPJ_DO_SUBMIT}
 
-ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V
-
-# ctest will exit with error code 0 even if tests failed
-# let's parse discarding known failure
+ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V || true
+# ctest will exit with various error codes depending on version.
+# ignore ctest exit code & parse this ourselves
 set +x
+
+# let's parse configure/build/tests for failure
+
 echo "
-Parsing logs for new/unknown failures
+Parsing logs for failures
 "
 OPJ_CI_RESULT=0
 
-OPJ_HAS_TESTS=$(find build -path 'build/Testing/Temporary*' -name 'LastTestsFailed*' | wc -l)
-OPJ_HAS_TESTS=$(echo $OPJ_HAS_TESTS) #macos wc workaround
+# 1st configure step
+OPJ_CONFIGURE_XML=$(find build -path 'build/Testing/*' -name 'Configure.xml')
+if [ ! -f "${OPJ_CONFIGURE_XML}" ]; then
+       echo "No configure log found"
+       OPJ_CI_RESULT=1
+else
+       if ! grep '<ConfigureStatus>0</ConfigureStatus>' ${OPJ_CONFIGURE_XML} &> /dev/null; then
+               echo "Errors were found in configure log"
+               OPJ_CI_RESULT=1
+       fi
+fi
 
-if [ $OPJ_HAS_TESTS -ne 0 ]; then
-       awk -F: '{ print $2 }' build/Testing/Temporary/LastTestsFailed_*.log > failures.txt
-       while read FAILEDTEST; do
-               # Start with common errors
-               if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-all.txt > /dev/null; then
-                       continue
-               fi
-               if [ -f ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt ]; then
-                       if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt > /dev/null; then
-                               continue
-                       fi
-               fi
-               echo "${FAILEDTEST}"
+# 2nd build step
+# We must have one Build.xml file
+OPJ_BUILD_XML=$(find build -path 'build/Testing/*' -name 'Build.xml')
+if [ ! -f "${OPJ_BUILD_XML}" ]; then
+       echo "No build log found"
+       OPJ_CI_RESULT=1
+else
+       if grep '<Error>' ${OPJ_BUILD_XML} &> /dev/null; then
+               echo "Errors were found in build log"
                OPJ_CI_RESULT=1
-       done < failures.txt
+       fi
 fi
 
-# TODO parse memcheck
+if [ ${OPJ_CI_RESULT} -ne 0 ]; then
+       # Don't trash output with failing tests when there are configure/build errors
+       exit ${OPJ_CI_RESULT}
+fi
 
-if [ ${OPJ_CI_RESULT} -eq 0 ]; then
-       echo "No new/unknown failure found"
-else
-       echo "
-New/unknown failures found!!!
-"
+if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then
+       OPJ_TEST_XML=$(find build -path 'build/Testing/*' -name 'Test.xml')
+       if [ ! -f "${OPJ_TEST_XML}" ]; then
+               echo "No test log found"
+               OPJ_CI_RESULT=1
+       else
+               echo "Parsing tests for new/unknown failures"
+               # 3rd test step
+               OPJ_FAILEDTEST_LOG=$(find build -path 'build/Testing/Temporary/*' -name 'LastTestsFailed_*.log')
+               if [ -f "${OPJ_FAILEDTEST_LOG}" ]; then
+                       awk -F: '{ print $2 }' ${OPJ_FAILEDTEST_LOG} > failures.txt
+                       while read FAILEDTEST; do
+                               # Start with common errors
+                               if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-all.txt > /dev/null; then
+                                       continue
+                               fi
+                               if [ -f ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt ]; then
+                                       if grep -x "${FAILEDTEST}" ${OPJ_SOURCE_DIR}/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt > /dev/null; then
+                                               continue
+                                       fi
+                               fi
+                               echo "${FAILEDTEST}"
+                               OPJ_CI_RESULT=1
+                       done < failures.txt
+               fi
+       fi
+       
+       if [ ${OPJ_CI_RESULT} -eq 0 ]; then
+               echo "No new/unknown test failure found
+               "
+       else
+               echo "
+New/unknown test failure found!!!
+       "
+       fi
+       
+       # 4th memcheck step
+       OPJ_MEMCHECK_XML=$(find build -path 'build/Testing/*' -name 'DynamicAnalysis.xml')
+       if [ -f "${OPJ_MEMCHECK_XML}" ]; then
+               if grep '<Defect Type' ${OPJ_MEMCHECK_XML} 2> /dev/null; then
+                       echo "Errors were found in dynamic analysis log"
+                       OPJ_CI_RESULT=1
+               fi
+       fi
 fi
 
 exit ${OPJ_CI_RESULT}