jenkins: set LD_LIBRARY_PATH for GnuPG tests
[gnupg-doc.git] / misc / jenkins / bin / build.bash
1 #!/bin/bash
2 # Script used jenkins to run builds for GnuPG and related packages.
3
4 # Stop on error and be nice to other processes.
5 set -xe
6 renice -n 10 -p $$
7
8 # Configuration.
9 MAKE=make
10
11 # Platform-specific configuration.
12 case "$(uname)" in
13     OpenBSD)
14         MAKE=gmake
15         ;;
16 esac
17
18 # Setup important envars
19 PREFIX=$HOME/prefix/$XTARGET
20 ORIGINAL_PREFIX=$HOME/prefix/$XTARGET
21 export PATH=$PREFIX/bin:$PATH
22
23 # Tweak the prefix we're installing this project into.  For gnupg-1.4
24 # and friends.
25 case "$JOB_NAME" in
26     *-1.4*)
27         PREFIX=$PREFIX-1.4
28         ;;
29     *-2.0*)
30         PREFIX=$PREFIX-2.0
31         ;;
32     *-2.2*)
33         PREFIX=$PREFIX-2.2
34         ;;
35 esac
36 mkdir -p $PREFIX
37
38
39 fix_permissions()
40 {
41   find $1 -type d -exec chmod +w {} + || true
42 }
43
44 fix_permissions .
45
46 # Clean everything
47 git clean -fdx
48
49 # Run out autogen - note that --force is not required due to the git clean.
50 ./autogen.sh
51
52 # Parallel jobs.
53 MAKEFLAGS="-j6"
54
55 # Parallel tests with our test suite.
56 export TESTFLAGS="--parallel"
57
58 SCANBUILD=
59 if [ "$(uname)" = Linux ] \
60        && [ "$ROOT_BUILD_CAUSE_TIMERTRIGGER" = true ]; then
61     # We only do scan-builds (which are really slow) on nightly
62     # builds.
63     SCANBUILD="scan-build -o ${WORKSPACE}/clangScanBuildReports -v"
64 fi
65 CONFIGUREFLAGS=
66 SANFLAGS=""
67 if [ "$(uname)" = Linux ]; then
68     # XXX: We should check if the sanitizers are available.
69     SANFLAGS="-fsanitize=undefined -fsanitize=address"
70 fi
71
72 if [ "$(uname)" = Darwin ]; then
73     # XXX until we properly set this somewhere else
74     cversion="_DARWIN_C_SOURCE=900000L"
75     CFLAGS="$CFLAGS -D$cversion"
76     CXXFLAGS="$CXXFLAGS -D$cversion"
77 fi
78
79 # Tweak the build depending on the package.
80 case "$JOB_NAME" in
81     *tgpg*)
82         MAKEFLAGS="$MAKEFLAGS GPG=/usr/bin/gpg2"
83         ;;
84     *gpgme*)
85         # using libasan for python broke again, so disable the python
86         # bindings for the sanitizer build
87         if [ "$XTARGET" = sanitizer ]; then
88             CONFIGUREFLAGS_0="--enable-languages=cpp qt"
89         fi
90         ;;
91     *gnupg*)
92         if [ "$XTARGET" = native ]; then
93             CONFIGUREFLAGS="--enable-wks-tools --enable-g13 --enable-symcryptrun --enable-gpg2-is-gpg"
94         fi
95         if [ "$XTARGET" = w32 ]; then
96             CONFIGUREFLAGS="--enable-wks-tools --enable-gpg2-is-gpg --with-zlib=$ORIGINAL_PREFIX --with-bzip2=$ORIGINAL_PREFIX"
97         fi
98         if [ "$NODE_NAME" = zygalski ]; then
99             CONFIGUREFLAGS="$CONFIGUREFLAGS --with-libiconv-prefix=$HOME/pkg"
100         fi
101         if [ "$NODE_NAME" = openbsd60 ]; then
102             CONFIGUREFLAGS="$CONFIGUREFLAGS --with-libiconv-prefix=/usr/local"
103         fi
104
105         # The libraries use rpath when linking the tests, so they
106         # locate their dependencies that way.  GnuPG, however, does
107         # not.  Therefore, we set LD_LIBRARY_PATH.
108         test_environment="LD_LIBRARY_PATH=$ORIGINAL_PREFIX/lib"
109         ;;
110 esac
111
112 # See if we have a GPGME checkout for the tesets.
113 xtest_gpgme_srcdir="$HOME/src/gpgme-for-gnupgs-tests"
114 if [ -d "$xtest_gpgme_srcdir/obj" ]; then
115     export XTEST_GPGME_SRCDIR="$xtest_gpgme_srcdir"
116     export XTEST_GPGME_BUILDDIR="$xtest_gpgme_srcdir/obj"
117 fi
118
119 # We build on the "obj" subdir.
120 abs_configure="$(pwd)/configure"
121 mkdir -p obj
122 cd obj
123
124
125 # Print the environment.
126 env
127 ulimit -a
128 set +x
129 for f in /etc/gcrypt/hwf.deny /etc/gcrypt/fips_enabled ; do
130   if [ -f "$f" ]; then
131     echo "=== $f ==="
132     cat -n "$f"
133   fi
134 done
135 set -x
136
137
138 # Switch on the different targets.
139 case "$XTARGET" in
140     native)
141         ../configure --prefix=$PREFIX --enable-maintainer-mode \
142                    $CONFIGUREFLAGS \
143                    "$CONFIGUREFLAGS_0" \
144                    CFLAGS="$CFLAGS" \
145                    CXXFLAGS="$CXXFLAGS -std=c++11"
146         $MAKE $MAKEFLAGS
147
148         env $test_environment $MAKE -k check verbose=2 || true
149         # Jenkins looks for "tests? failed" to mark a build unstable,
150         # hence || true here
151
152         $MAKE install
153         ;;
154     sanitizer)
155         # asan breaks the configure tests, so we disable it here.
156         ASAN_OPTIONS=detect_leaks=0 \
157         $SCANBUILD \
158             ../configure --prefix=$PREFIX --enable-maintainer-mode \
159                    $CONFIGUREFLAGS \
160                    "$CONFIGUREFLAGS_0" \
161                    CFLAGS="$CFLAGS $SANFLAGS -fPIC" \
162                    CXXFLAGS="$CXXFLAGS $SANFLAGS -fPIC -std=c++11"
163         $SCANBUILD $MAKE $MAKEFLAGS
164
165         env $test_environment $MAKE -k check verbose=2 || true
166         # Jenkins looks for "tests? failed" to mark a build unstable,
167         # hence || true here
168
169         $MAKE install
170         ;;
171     w32)
172         export w32root=$PREFIX
173
174         # autogen.rc adds --with-gpg-error-prefix=@SYSROOT@, so we cannot
175         # install to a prefix that doesn't also contain all the dependencies,
176         # patch that out, so that the gpg-error-config and friends are located
177         # using PATH
178         if [ -f "/home/jenkins/bin/$(dirname $JOB_NAME)-w32.patch" ]; then
179           ( cd .. && patch -p1 <"/home/jenkins/bin/$(dirname $JOB_NAME)-w32.patch" )
180         fi
181         # We need to point it to npth then...
182         case "$JOB_NAME" in
183             gnupg/XTARGET=w32|gnupg-2.2/XTARGET=w32)
184                 CONFIGUREFLAGS="${CONFIGUREFLAGS} --with-npth-prefix=$ORIGINAL_PREFIX"
185                 ;;
186             gnupg-2.0/XTARGET=w32)
187                 CONFIGUREFLAGS="${CONFIGUREFLAGS} --with-pth-prefix=$ORIGINAL_PREFIX --with-adns=$ORIGINAL_PREFIX"
188                 ;;
189         esac
190
191         # gpg1's autogen.sh does not add --enable-maintainer-mode, so
192         # version.texi is not generated.  we add it here to be sure.
193         # likewise for --prefix
194         ../autogen.sh --build-w32 --enable-maintainer-mode --prefix=$PREFIX \
195           $CONFIGUREFLAGS
196         $MAKE $MAKEFLAGS
197         $MAKE install
198
199         case "$JOB_NAME" in
200                 gnupg/*|gnupg-2.2/*)
201                         bash /home/jenkins/bin/make-windows-cd.sh
202                         # We need to pass the absolute path of the iso.
203                         bash $HOME/bin/run-tests-w32.bash "$(readlink -f gnupg-test.iso)" || true
204                         ;;
205         esac
206         ;;
207     distcheck)
208         CONFIGUREFLAGS=
209         WORKDIR="$(mktemp -d)"
210         cleanup()
211         {
212           cd /tmp
213           fix_permissions "$WORKDIR"
214           rm -rf -- "$WORKDIR" || true
215         }
216         trap cleanup EXIT
217
218           # We use a different WORKDIR to avoid problems with too long
219           # file names
220           cd "$WORKDIR"
221           $abs_configure --prefix=$PREFIX --enable-maintainer-mode \
222                    $CONFIGUREFLAGS
223           env $test_environment $MAKE $MAKEFLAGS distcheck
224
225           # Extract the tarname from the package
226           tarname=$(awk <config.h '
227                      /^#define PACKAGE_TARNAME/ {gsub(/"/,"",$3);name=$3};
228                      /^#define PACKAGE_VERSION/ {gsub(/"/,"",$3);vers=$3};
229                      END {print name "-" vers}')
230           if [ -f "${tarname}.tar.bz2" ]; then
231              bzcat "${tarname}.tar.bz2" | tar xf -
232           elif [ -f "${tarname}.tar.gz" ]; then
233              zcat "${tarname}.tar.gz" | tar xf -
234           else
235              echo "No tarball named $tarname found - skipping installation" >&2
236              exit 0
237           fi
238           # And do a final build using the generated tarball
239           cd ${tarname}
240           ./configure --prefix=$PREFIX $CONFIGUREFLAGS LD_LIBRARY_PATH=$PREFIX/lib
241           $MAKE $MAKEFLAGS
242           $MAKE $MAKEFLAGS install
243
244         ;;
245     *)
246         echo "Bad XTARGET: '$XTARGET'"
247         exit 2
248 esac