Merge pull request #866 from tSed/master
[openjpeg.git] / tools / travis-ci / install.sh
1 #!/bin/bash
2
3 # This script executes the install 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         # PATH is not yet set up
13         export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
14 fi
15
16 # Set-up some error handling
17 set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
18 set -o errexit   ## set -e : exit the script if any statement returns a non-true return value
19 set -o pipefail  ## Fail on error in pipe
20
21 function exit_handler ()
22 {
23         local exit_code="$?"
24         
25         test ${exit_code} == 0 && return;
26
27         echo -e "\nInstall failed !!!\nLast command at line ${BASH_LINENO}: ${BASH_COMMAND}";
28         exit "${exit_code}"
29 }
30 trap exit_handler EXIT
31 trap exit ERR
32
33 # We don't need anything for coverity scan builds. ABI check is managed in abi-check.sh
34 if [ "${COVERITY_SCAN_BRANCH:-}" == "1" ] || [ "${OPJ_CI_ABI_CHECK:-}" == "1" ]; then
35         exit 0
36 fi
37
38 if [ "${OPJ_CI_ASAN:-}" == "1" ]; then
39         # We need a new version of cmake than travis-ci provides
40         wget --no-check-certificate -qO - https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz | tar -xz
41         # copy to a directory that will not changed every version
42         mv cmake-3.5.2-Linux-x86_64 cmake-install
43 fi
44
45 if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then
46
47         OPJ_SOURCE_DIR=$(cd $(dirname $0)/../.. && pwd)
48
49         # We need test data
50         if [ "${TRAVIS_BRANCH:-}" != "" ]; then
51                 OPJ_DATA_BRANCH=${TRAVIS_BRANCH}
52         elif [ "${APPVEYOR_REPO_BRANCH:-}" != "" ]; then
53                 OPJ_DATA_BRANCH=${APPVEYOR_REPO_BRANCH}
54         else
55                 OPJ_DATA_BRANCH=$(git -C ${OPJ_SOURCE_DIR} branch | grep '*' | tr -d '*[[:blank:]]') #default to same branch as we're setting up
56         fi
57         OPJ_DATA_HAS_BRANCH=$(git ls-remote --heads git://github.com/uclouvain/openjpeg-data.git ${OPJ_DATA_BRANCH} | wc -l)
58         if [ ${OPJ_DATA_HAS_BRANCH} -eq 0 ]; then
59                 OPJ_DATA_BRANCH=master #default to master
60         fi
61         echo "Cloning openjpeg-data from ${OPJ_DATA_BRANCH} branch"
62         git clone --depth=1 --branch=${OPJ_DATA_BRANCH} git://github.com/uclouvain/openjpeg-data.git data
63
64         # We need jpylyzer for the test suite
65     JPYLYZER_VERSION="1.17.0"    
66         echo "Retrieving jpylyzer"
67         if [ "${APPVEYOR:-}" == "True" ]; then
68                 wget -q http://dl.bintray.com/openplanets/opf-windows/jpylyzer_${JPYLYZER_VERSION}_win32.zip
69                 mkdir jpylyzer
70                 cd jpylyzer
71                 cmake -E tar -xf ../jpylyzer_${JPYLYZER_VERSION}_win32.zip
72                 cd ..
73         else
74                 wget -qO - https://github.com/openpreserve/jpylyzer/archive/${JPYLYZER_VERSION}.tar.gz | tar -xz
75                 mv jpylyzer-${JPYLYZER_VERSION}/jpylyzer ./
76                 chmod +x jpylyzer/jpylyzer.py
77         fi
78
79         # When OPJ_NONCOMMERCIAL=1, kakadu trial binaries are used for testing. Here's the copyright notice from kakadu:
80         # Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
81         # You are free to trial these executables and even to re-distribute them, 
82         # so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
83         # Note: Binaries can only be used for non-commercial purposes.
84         if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ]; then
85                 if [ "${TRAVIS_OS_NAME:-}" == "linux" ] || uname -s | grep -i Linux &> /dev/null; then
86                         echo "Retrieving Kakadu"
87                         wget -q http://kakadusoftware.com/wp-content/uploads/2014/06/KDU77_Demo_Apps_for_Linux-x86-64_150710.zip
88                         cmake -E tar -xf KDU77_Demo_Apps_for_Linux-x86-64_150710.zip
89                         mv KDU77_Demo_Apps_for_Linux-x86-64_150710 kdu
90                 elif [ "${TRAVIS_OS_NAME:-}" == "osx" ] || uname -s | grep -i Darwin &> /dev/null; then
91                         echo "Retrieving Kakadu"
92                         wget -v http://kakadusoftware.com/wp-content/uploads/2014/06/KDU77_Demo_Apps_for_OSX109_150710.dmg_.zip
93                         cmake -E tar -xf KDU77_Demo_Apps_for_OSX109_150710.dmg_.zip
94                         wget -q http://downloads.sourceforge.net/project/catacombae/HFSExplorer/0.23/hfsexplorer-0.23-bin.zip
95                         mkdir hfsexplorer && cmake -E chdir hfsexplorer tar -xf ../hfsexplorer-0.23-bin.zip
96                         ./hfsexplorer/bin/unhfs.sh -o ./ -fsroot Kakadu-demo-apps.pkg  KDU77_Demo_Apps_for_OSX109_150710.dmg
97                         pkgutil --expand Kakadu-demo-apps.pkg ./kdu
98                         cd kdu
99                         cat libkduv77r.pkg/Payload | gzip -d | cpio -id
100                         cat kduexpand.pkg/Payload | gzip -d | cpio -id
101                         cat kducompress.pkg/Payload | gzip -d | cpio -id
102                         install_name_tool -id ${PWD}/libkdu_v77R.dylib libkdu_v77R.dylib 
103                         install_name_tool -change /usr/local/lib/libkdu_v77R.dylib ${PWD}/libkdu_v77R.dylib kdu_compress
104                         install_name_tool -change /usr/local/lib/libkdu_v77R.dylib ${PWD}/libkdu_v77R.dylib kdu_expand
105                 elif [ "${APPVEYOR:-}" == "True" ] || uname -s | grep -i MINGW &> /dev/null || uname -s | grep -i CYGWIN &> /dev/null; then
106                         echo "Retrieving Kakadu"
107                         wget -q http://kakadusoftware.com/wp-content/uploads/2014/06/KDU77_Demo_Apps_for_Win32_150710.msi_.zip
108                         cmake -E tar -xf KDU77_Demo_Apps_for_Win32_150710.msi_.zip
109                         msiexec /i KDU77_Demo_Apps_for_Win32_150710.msi /quiet /qn /norestart
110                         if [ -d "C:/Program Files/Kakadu" ]; then
111                                 cp -r "C:/Program Files/Kakadu" ./kdu
112                         else
113                                 cp -r "C:/Program Files (x86)/Kakadu" ./kdu
114                         fi
115                 fi
116         fi
117 fi
118
119 if [ "${OPJ_CI_CHECK_STYLE:-}" == "1" ]; then
120     pip install --user autopep8
121 fi