jenkins: disable python bindings on macos for now
[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         # Disable Python bindings on macOS.  Something is not working
92         # there.
93         if [ "$NODE_NAME" = zygalski ]; then
94             CONFIGUREFLAGS_0="--enable-languages=cpp qt"
95         fi
96         ;;
97     *gnupg*)
98         # Common configure options.
99         CONFIGUREFLAGS="--enable-wks-tools --enable-gpg2-is-gpg"
100
101         # For Windows builds...
102         if [ "$XTARGET" = w32 ]; then
103             # ... we need to tweak it a little and we leave out some
104             # stuff...
105             CONFIGUREFLAGS="$CONFIGUREFLAGS --with-zlib=$ORIGINAL_PREFIX --with-bzip2=$ORIGINAL_PREFIX"
106         else
107             # ... that we enable for all other builds.
108             CONFIGUREFLAGS="$CONFIGUREFLAGS --enable-g13 --enable-symcryptrun"
109         fi
110
111         if [ "$NODE_NAME" = zygalski ]; then
112             CONFIGUREFLAGS="$CONFIGUREFLAGS --with-libiconv-prefix=$HOME/pkg"
113         fi
114         if [ "$NODE_NAME" = openbsd60 ]; then
115             CONFIGUREFLAGS="$CONFIGUREFLAGS --with-libiconv-prefix=$HOME/compat --with-bzip2=$HOME/compat"
116         fi
117
118         # Disable NTBTLS for now until it is actually mature and used.
119         CONFIGUREFLAGS="$CONFIGUREFLAGS --disable-ntbtls"
120         ;;
121 esac
122
123 # The libraries use RUNPATH when linking the tests, so they locate
124 # their dependencies that way.  GnuPG, however, does not.  Therefore,
125 # we set LD_LIBRARY_PATH.
126 test_environment="LD_LIBRARY_PATH=$ORIGINAL_PREFIX/lib"
127
128 # HACKHACKHACK:
129 #
130 # Because newer Debian toolchains prefer RUNPATH over RPATH, and
131 # RUNPATH has lower precedence than LD_LIBRARY_PATH, we need to
132 # explicitly add libtool's .libs directory:
133 test_environment="LD_LIBRARY_PATH=$(pwd)/obj/src/.libs:$ORIGINAL_PREFIX/lib"
134 #
135 # If we don't do this, the version tests fail because the runtime
136 # linker will pick up the library from LD_LIBRARY_PATH.  Also, testing
137 # the installed version is not what we want ofc.
138 #
139 # KCAHKCAHKCAH
140
141 # See if we have a GPGME checkout for the tesets.
142 xtest_gpgme_srcdir="$HOME/src/gpgme-for-gnupgs-tests"
143 if [ -d "$xtest_gpgme_srcdir/obj" ]; then
144     export XTEST_GPGME_SRCDIR="$xtest_gpgme_srcdir"
145     export XTEST_GPGME_BUILDDIR="$xtest_gpgme_srcdir/obj"
146 fi
147
148 # We build on the "obj" subdir.
149 abs_configure="$(pwd)/configure"
150 mkdir -p obj
151 cd obj
152
153
154 # Print the environment.
155 env
156 ulimit -a
157 set +x
158 for f in /etc/gcrypt/hwf.deny /etc/gcrypt/fips_enabled ; do
159   if [ -f "$f" ]; then
160     echo "=== $f ==="
161     cat -n "$f"
162   fi
163 done
164 set -x
165
166
167 # Switch on the different targets.
168 case "$XTARGET" in
169     native)
170         ../configure --prefix=$PREFIX --enable-maintainer-mode \
171                    $CONFIGUREFLAGS \
172                    "$CONFIGUREFLAGS_0" \
173                    CFLAGS="$CFLAGS" \
174                    CXXFLAGS="$CXXFLAGS -std=c++11"
175         $MAKE $MAKEFLAGS
176
177         env $test_environment $MAKE -k check verbose=2 \
178             || echo "FAIL: make check failed with status $?"
179         # Jenkins looks for "FAIL:" to mark a build unstable,
180         # hence || ... here
181
182         $MAKE install
183         ;;
184     sanitizer)
185         # asan breaks the configure tests, so we disable it here.
186         ASAN_OPTIONS=detect_leaks=0 \
187         $SCANBUILD \
188             ../configure --prefix=$PREFIX --enable-maintainer-mode \
189                    $CONFIGUREFLAGS \
190                    "$CONFIGUREFLAGS_0" \
191                    CFLAGS="$CFLAGS $SANFLAGS -fPIC" \
192                    CXXFLAGS="$CXXFLAGS $SANFLAGS -fPIC -std=c++11"
193         $SCANBUILD $MAKE $MAKEFLAGS
194
195         env $test_environment $MAKE -k check verbose=2 \
196             || echo "FAIL: make check failed with status $?"
197         # Jenkins looks for "FAIL:" to mark a build unstable,
198         # hence || ... here
199
200         $MAKE install
201         ;;
202     w32)
203         export w32root=$PREFIX
204
205         # autogen.rc adds --with-gpg-error-prefix=@SYSROOT@, so we cannot
206         # install to a prefix that doesn't also contain all the dependencies,
207         # patch that out, so that the gpg-error-config and friends are located
208         # using PATH
209         if [ -f "/home/jenkins/bin/$(dirname $JOB_NAME)-w32.patch" ]; then
210           ( cd .. && patch -p1 <"/home/jenkins/bin/$(dirname $JOB_NAME)-w32.patch" )
211         fi
212         # We need to point it to npth then...
213         case "$JOB_NAME" in
214             gnupg/XTARGET=w32|gnupg-2.2/XTARGET=w32)
215                 CONFIGUREFLAGS="${CONFIGUREFLAGS} --with-npth-prefix=$ORIGINAL_PREFIX"
216                 ;;
217             gnupg-2.0/XTARGET=w32)
218                 CONFIGUREFLAGS="${CONFIGUREFLAGS} --with-pth-prefix=$ORIGINAL_PREFIX --with-adns=$ORIGINAL_PREFIX"
219                 ;;
220         esac
221
222         # gpg1's autogen.sh does not add --enable-maintainer-mode, so
223         # version.texi is not generated.  we add it here to be sure.
224         # likewise for --prefix
225         ../autogen.sh --build-w32 --enable-maintainer-mode --prefix=$PREFIX \
226           $CONFIGUREFLAGS
227         $MAKE $MAKEFLAGS
228         $MAKE install
229
230         case "$JOB_NAME" in
231                 gnupg/*|gnupg-2.2/*)
232                         bash /home/jenkins/bin/make-windows-cd.sh
233                         # We need to pass the absolute path of the iso.
234                         bash $HOME/bin/run-tests-w32.bash "$(readlink -f gnupg-test.iso)" || echo "FAIL: error running tests on Windows."
235                         ;;
236         esac
237         ;;
238     distcheck)
239         CONFIGUREFLAGS=
240         WORKDIR="$(mktemp -d)"
241         cleanup()
242         {
243           cd /tmp
244           fix_permissions "$WORKDIR"
245           rm -rf -- "$WORKDIR" || true
246         }
247         trap cleanup EXIT
248
249           # We use a different WORKDIR to avoid problems with too long
250           # file names
251           cd "$WORKDIR"
252           $abs_configure --prefix=$PREFIX --enable-maintainer-mode \
253                    $CONFIGUREFLAGS
254
255           # Extract the directory / tarname from the package
256           tarname=$(awk <config.h '
257                      /^#define PACKAGE_TARNAME/ {gsub(/"/,"",$3);name=$3};
258                      /^#define PACKAGE_VERSION/ {gsub(/"/,"",$3);vers=$3};
259                      END {print name "-" vers}')
260
261           # HACKHACKHACK: Because newer Debian toolchains prefer
262           # RUNPATH over RPATH, and RUNPATH has lower precedence than
263           # LD_LIBRARY_PATH, we need to explicitly add libtool's .libs
264           # directory:
265           test_environment="LD_LIBRARY_PATH=$(pwd)/${tarname}/_build/sub/src/.libs:$ORIGINAL_PREFIX/lib"
266           # KCAHKCAHKCAH
267
268           if ! env $test_environment $MAKE $MAKEFLAGS distcheck ; then
269               # Jenkins looks for "FAIL:" to mark a build unstable,
270               # hence we ignore errors here.
271               echo "FAIL: make distcheck failed with status $?"
272               exit 0
273           fi
274
275           if [ -f "${tarname}.tar.bz2" ]; then
276              bzcat "${tarname}.tar.bz2" | tar xf -
277           elif [ -f "${tarname}.tar.gz" ]; then
278              zcat "${tarname}.tar.gz" | tar xf -
279           else
280              echo "No tarball named $tarname found - skipping installation" >&2
281              exit 0
282           fi
283           # And do a final build using the generated tarball
284           cd ${tarname}
285           ./configure --prefix=$PREFIX $CONFIGUREFLAGS
286           $MAKE $MAKEFLAGS
287           $MAKE $MAKEFLAGS install
288
289         ;;
290     *)
291         echo "Bad XTARGET: '$XTARGET'"
292         exit 2
293 esac