Automatic upload of ABI report (end)
[openjpeg.git] / tools / travis-ci / abi-check.sh
1 #!/bin/bash
2
3 # This script executes the abi-check step when running under travis-ci (in run step)
4
5 # Set-up some bash options
6 set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
7 set -o errexit   ## set -e : exit the script if any statement returns a non-true return value
8 set -o pipefail  ## Fail on error in pipe
9 set -o xtrace    ## set -x : Print a trace of simple commands and their arguments after they are expanded and before they are executed.
10
11 # Exit if not ABI check
12 if [ "${OPJ_CI_ABI_CHECK:-}" != "1" ]; then
13         exit 0
14 fi
15
16 OPJ_UPLOAD_ABI_REPORT=0
17 OPJ_LATEST_VERSION="2.1"
18 OPJ_LIMIT_ABI_BUILDS="-limit 2"
19 OPJ_REPO="https://github.com/uclouvain/openjpeg.git"
20 OPJ_SSH_REPO=${OPJ_REPO/https:\/\/github.com\//git@github.com:}
21 OPJ_UPLOAD_BRANCH="gh-pages"
22 OPJ_UPLOAD_DIR="abi-check"
23 if [ "${TRAVIS_REPO_SLUG:-}" != "" ]; then
24         if [ "$(echo "${TRAVIS_REPO_SLUG}" | sed 's/\(^.*\)\/.*/\1/')" == "uclouvain" ] && [ "${TRAVIS_PULL_REQUEST:-}" == "false" ]; then
25                 # Upload updated report to gh-pages
26                 OPJ_UPLOAD_ABI_REPORT=1
27                 # Build full report
28                 #OPJ_LIMIT_ABI_BUILDS=
29         fi
30 fi
31
32 OPJ_SOURCE_DIR=$(cd $(dirname $0)/../.. && pwd)
33
34 # INSTALL REQUIRED PACKAGES
35
36 mkdir ${HOME}/abi-check
37 cd ${HOME}/abi-check
38 # Let's get tools not available with apt
39 mkdir tools
40 # Travis doesn't allow package wdiff...
41 wget -qO - http://mirrors.kernel.org/gnu/wdiff/wdiff-latest.tar.gz | tar -xz
42 cd wdiff-*
43 ./configure --prefix=${HOME}/abi-check/tools/wdiff &> /dev/null
44 make &> /dev/null
45 make check &> /dev/null
46 make install &> /dev/null
47 cd ..
48 export PATH=${PWD}/tools/wdiff/bin:$PATH
49 wget -qO - https://tools.ietf.org/tools/rfcdiff/rfcdiff-1.42.tgz | tar -xz
50 mv rfcdiff-1.42 ${PWD}/tools/rfcdiff
51 export PATH=${PWD}/tools/rfcdiff:$PATH
52 wget -qO - https://github.com/lvc/installer/archive/0.10.tar.gz | tar -xz
53 mkdir ${PWD}/tools/abi-tracker
54 make -C installer-0.10 install prefix=${PWD}/tools/abi-tracker target=abi-tracker
55 export PATH=${PWD}/tools/abi-tracker/bin:$PATH
56
57 # RUN THE ABI-CHECK SCRIPTS
58
59 mkdir work
60 cd work
61
62 # If upload is scheduled, clone the gh-pages branch and work from there
63 if [ ${OPJ_UPLOAD_ABI_REPORT} -eq 1 ]; then
64         git clone -b $OPJ_UPLOAD_BRANCH --single-branch $OPJ_REPO .
65         cd $OPJ_UPLOAD_DIR
66         rm -rf installed/openjpeg/current/*
67 fi
68
69 # Let's create all we need
70 grep -v Git ${OPJ_SOURCE_DIR}/tools/abi-tracker/openjpeg.json > ./openjpeg.json
71 #abi-monitor ${OPJ_LIMIT_ABI_BUILDS} -get openjpeg.json
72 if [ "${OPJ_LIMIT_ABI_BUILDS}" != "" ]; then
73         cp -f ${OPJ_SOURCE_DIR}/tools/abi-tracker/openjpeg.json ./openjpeg.json
74 else
75         # Old versions of openjpeg don't like -fvisibility=hidden...
76         grep -v Configure ${OPJ_SOURCE_DIR}/tools/abi-tracker/openjpeg.json > ./openjpeg.json
77 fi
78 cp -rf ${OPJ_SOURCE_DIR} src/openjpeg/current
79 abi-monitor ${OPJ_LIMIT_ABI_BUILDS} -rebuild openjpeg.json
80 abi-tracker -build openjpeg.json
81
82 EXIT_CODE=0
83
84 # Check API
85 abi-compliance-checker -l openjpeg -old $(find ./abi_dump/openjpeg/$OPJ_LATEST_VERSION -name '*.dump') -new $(find ./abi_dump/openjpeg/current -name '*.dump') -header openjpeg.h -api -s || EXIT_CODE=1
86
87 # Check ABI
88 if [ "${OPJ_LIMIT_ABI_BUILDS}" != "" ]; then
89         abi-compliance-checker -l openjpeg -old $(find ./abi_dump/openjpeg/$OPJ_LATEST_VERSION -name '*.dump') -new $(find ./abi_dump/openjpeg/current -name '*.dump') -header openjpeg.h -abi -s || EXIT_CODE=1
90 else
91         echo "Disable ABI check for now, problems with symbol visibility..."
92 fi
93
94 rm -rf src/openjpeg/current
95 rm -rf build_logs
96
97 if [ ${OPJ_UPLOAD_ABI_REPORT} -eq 1 ]; then
98         git config user.name "OpenJPEG Travis CI"
99         git config user.email "info@openjpeg.org"
100
101         # Commit the "changes", i.e. the new version.
102         # The delta will show diffs between new and old versions.
103         git diff > ../diff.patch
104         git add .
105         git commit -m "Update ABI/API compatibility reports after commit ${TRAVIS_COMMIT:-}"
106
107         # Get the deploy key by using Travis's stored variables to decrypt travis_rsa.enc
108         openssl aes-256-cbc -K $encrypted_99d63218f67a_key -iv $encrypted_99d63218f67a_iv -in ${OPJ_SOURCE_DIR}/tools/travis-ci/travis_rsa.enc -out travis_rsa -d
109         chmod 600 travis_rsa
110         eval `ssh-agent -s`
111         ssh-add travis_rsa
112
113         # Now that we're all set up, we can push.
114         git push $OPJ_SSH_REPO $OPJ_UPLOAD_BRANCH
115 fi
116
117 rm -rf src installed
118
119 exit $EXIT_CODE