956884c193560e65600a0652ebcd6cf7ad85017a
[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 # Setup important envars
9 PREFIX=$HOME/prefix/$XTARGET
10 ORIGINAL_PREFIX=$HOME/prefix/$XTARGET
11 export PATH=/home/jenkins/bin:$PREFIX/bin:$PATH
12
13 # Print the environment.
14 env
15 ulimit -a
16
17 # Tweak the prefix we're installing this project into.  For gnupg-1.4
18 # and friends.
19 case "$JOB_NAME" in
20     *-1.4*)
21         PREFIX=$PREFIX-1.4
22         ;;
23     *-2.0*)
24         PREFIX=$PREFIX-2.0
25         ;;
26     *-2.2*)
27         PREFIX=$PREFIX-2.2
28         ;;
29 esac
30 mkdir -p $PREFIX
31
32
33 fix_permissions()
34 {
35   find $1 -type d -exec chmod +w {} + || true
36 }
37
38 fix_permissions .
39
40 # Clean everything
41 git clean -fdx
42
43 # Run out autogen - note that --force is not required due to the git clean.
44 ./autogen.sh
45
46 # Out current box seems to have cache coherency problems, thus we have
47 # disabled all but one CPU.
48 MAKEFLAGS="-j2"
49
50
51 SCANBUILD=
52 if [ "$(uname)" = Linux ] \
53        && [ "$ROOT_BUILD_CAUSE_TIMERTRIGGER" = true ]; then
54     # We only do scan-builds (which are really slow) on nightly
55     # builds.
56     SCANBUILD="scan-build -o ${WORKSPACE}/clangScanBuildReports -v"
57 fi
58 CONFIGUREFLAGS=
59 SANFLAGS=""
60 if [ "$(uname)" = Linux ]; then
61     # XXX: We should really have an analyzer target
62     SANFLAGS="-fsanitize=undefined -fsanitize=address"
63 fi
64
65 if [ "$(uname)" = Darwin ]; then
66     # XXX until we properly set this somewhere else
67     cversion="_DARWIN_C_SOURCE=900000L"
68     CFLAGS="$CFLAGS -D$cversion"
69     CXXFLAGS="$CXXFLAGS -D$cversion"
70 fi
71
72 # Tweak the build depending on the package.
73 case "$JOB_NAME" in
74     *tgpg*)
75         MAKEFLAGS="$MAKEFLAGS GPG=/usr/bin/gpg2"
76         ;;
77     *gpgme*)
78         # using libasan for python broke again, so disable the python bindings for the native build
79         if [ "$XTARGET" = native ] && [ "$label" != macos ]; then
80             CONFIGUREFLAGS_0="--enable-languages=cpp qt"
81         fi
82         ;;
83     *gnupg*)
84         if [ "$XTARGET" = native ]; then
85             CONFIGUREFLAGS="--enable-wks-tools --enable-g13 --enable-symcryptrun --enable-gpg2-is-gpg"
86         fi
87         if [ "$XTARGET" = w32 ]; then
88             CONFIGUREFLAGS="--enable-wks-tools --enable-gpg2-is-gpg --with-zlib=$ORIGINAL_PREFIX --with-bzip2=$ORIGINAL_PREFIX"
89         fi
90         if [ "$NODE_NAME" = zygalski ]; then
91             CONFIGUREFLAGS="$CONFIGUREFLAGS --with-libiconv-prefix=$HOME/pkg"
92         fi
93         ;;
94 esac
95
96 # See if we have a GPGME checkout for the tesets.
97 xtest_gpgme_srcdir="$HOME/src/gpgme-for-gnupgs-tests"
98 if [ -d "$xtest_gpgme_srcdir/obj" ]; then
99     export XTEST_GPGME_SRCDIR="$xtest_gpgme_srcdir"
100     export XTEST_GPGME_BUILDDIR="$xtest_gpgme_srcdir/obj"
101 fi
102
103 # We build on the "obj" subdir.
104 abs_configure="$(pwd)/configure"
105 mkdir -p obj
106 cd obj
107
108 # Switch on the different targets.
109 case "$XTARGET" in
110     native)
111         ASAN_OPTIONS=detect_leaks=0 \
112         $SCANBUILD \
113             ../configure --prefix=$PREFIX --enable-maintainer-mode \
114                    $CONFIGUREFLAGS \
115                    "$CONFIGUREFLAGS_0" \
116                    CFLAGS="$CFLAGS $SANFLAGS -fPIC" \
117                    CXXFLAGS="$CXXFLAGS $SANFLAGS -fPIC -std=c++11" \
118                    LD_LIBRARY_PATH=$PREFIX/lib
119         $SCANBUILD make $MAKEFLAGS
120
121           make check verbose=2 LD_LIBRARY_PATH=$PREFIX/lib || true
122         # Jenkins looks for "tests? failed" to mark a build unstable,
123         # hence || true here
124
125         make install
126         ;;
127     w32)
128         export w32root=$PREFIX
129
130         # autogen.rc adds --with-gpg-error-prefix=@SYSROOT@, so we cannot
131         # install to a prefix that doesn't also contain all the dependencies,
132         # patch that out, so that the gpg-error-config and friends are located
133         # using PATH
134         if [ -f "/home/jenkins/bin/$(dirname $JOB_NAME)-w32.patch" ]; then
135           ( cd .. && patch -p1 <"/home/jenkins/bin/$(dirname $JOB_NAME)-w32.patch" )
136         fi
137         # We need to point it to npth and adns then...
138         CONFIGUREFLAGS="${CONFIGUREFLAGS} --with-npth-prefix=$ORIGINAL_PREFIX --with-adns=$ORIGINAL_PREFIX"
139
140         # gpg1's autogen.sh does not add --enable-maintainer-mode, so
141         # version.texi is not generated.  we add it here to be sure.
142         # likewise for --prefix
143         ../autogen.sh --build-w32 --enable-maintainer-mode --prefix=$PREFIX \
144           $CONFIGUREFLAGS
145         make $MAKEFLAGS
146         make install
147
148         case "$JOB_NAME" in
149                 gnupg/*|gnupg-2.2/*)
150                         bash /home/jenkins/bin/make-windows-cd.sh
151                         ;;
152         esac
153         ;;
154     distcheck)
155         CONFIGUREFLAGS=
156         WORKDIR="$(mktemp -d)"
157         cleanup()
158         {
159           cd /tmp
160           fix_permissions "$WORKDIR"
161           rm -rf -- "$WORKDIR" || true
162         }
163         trap cleanup EXIT
164
165           # We use a different WORKDIR to avoid problems with too long
166           # file names
167           cd "$WORKDIR"
168           $abs_configure --prefix=$PREFIX --enable-maintainer-mode \
169                    $CONFIGUREFLAGS LD_LIBRARY_PATH=$PREFIX/lib
170           make $MAKEFLAGS distcheck LD_LIBRARY_PATH=$PREFIX/lib
171
172           # Extract the tarname from the package
173           tarname=$(awk <config.h '
174                      /^#define PACKAGE_TARNAME/ {gsub(/"/,"",$3);name=$3};
175                      /^#define PACKAGE_VERSION/ {gsub(/"/,"",$3);vers=$3};
176                      END {print name "-" vers}')
177           if [ -f "${tarname}.tar.bz2" ]; then
178              bzcat "${tarname}.tar.bz2" | tar xf -
179           elif [ -f "${tarname}.tar.gz" ]; then
180              zcat "${tarname}.tar.gz" | tar xf -
181           else
182              echo "No tarball named $tarname found - skipping installation" >&2
183              exit 0
184           fi
185           # And do a final build using the generated tarball
186           cd ${tarname}
187           ./configure --prefix=$PREFIX $CONFIGUREFLAGS LD_LIBRARY_PATH=$PREFIX/lib
188           make $MAKEFLAGS         LD_LIBRARY_PATH=$PREFIX/lib
189           make $MAKEFLAGS install LD_LIBRARY_PATH=$PREFIX/lib
190
191         ;;
192     *)
193         echo "Bad XTARGET: '$XTARGET'"
194         exit 2
195 esac