jjb: lttng-ust: split gerrit jobs by branch
[lttng-ci.git] / scripts / lttng-ust / build.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # 2016-2019 Michael Jeanson <mjeanson@efficios.com>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 set -exu
20
21 # Version compare functions
22 vercomp () {
23 set +u
24 if [[ "$1" == "$2" ]]; then
25 return 0
26 fi
27 local IFS=.
28 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
29 # shellcheck disable=SC2206
30 local i ver1=($1) ver2=($2)
31 # fill empty fields in ver1 with zeros
32 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
33 ver1[i]=0
34 done
35 for ((i=0; i<${#ver1[@]}; i++)); do
36 if [[ -z ${ver2[i]} ]]; then
37 # fill empty fields in ver2 with zeros
38 ver2[i]=0
39 fi
40 if ((10#${ver1[i]} > 10#${ver2[i]})); then
41 return 1
42 fi
43 if ((10#${ver1[i]} < 10#${ver2[i]})); then
44 return 2
45 fi
46 done
47 set -u
48 return 0
49 }
50
51 verlte() {
52 vercomp "$1" "$2"; local res="$?"
53 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
54 }
55
56 verlt() {
57 vercomp "$1" "$2"; local res="$?"
58 [ "$res" -eq "2" ]
59 }
60
61 vergte() {
62 vercomp "$1" "$2"; local res="$?"
63 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
64 }
65
66 vergt() {
67 vercomp "$1" "$2"; local res="$?"
68 [ "$res" -eq "1" ]
69 }
70
71 verne() {
72 vercomp "$1" "$2"; local res="$?"
73 [ "$res" -ne "0" ]
74 }
75
76 failed_configure() {
77 # Assume we are in the configured build directory
78 echo "#################### BEGIN config.log ####################"
79 cat config.log
80 echo "#################### END config.log ####################"
81
82 # End the build with failure
83 exit 1
84 }
85
86 # Required variables
87 WORKSPACE=${WORKSPACE:-}
88
89 platform=${platform:-}
90 conf=${conf:-}
91 build=${build:-}
92 cc=${cc:-}
93
94 # Controls if the tests are run
95 LTTNG_UST_RUN_TESTS="${LTTNG_UST_RUN_TESTS:=yes}"
96
97 SRCDIR="$WORKSPACE/src/lttng-ust"
98 TMPDIR="$WORKSPACE/tmp"
99 PREFIX="/build"
100 LIBDIR="lib"
101 LIBDIR_ARCH="$LIBDIR"
102
103 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
104 # site config that matches this.
105 if [[ ( -f /etc/redhat-release || -f /etc/products.d/SLES.prod || -f /etc/yocto-release ) ]]; then
106 # Detect the userspace bitness in a distro agnostic way
107 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
108 LIBDIR_ARCH="${LIBDIR}64"
109 fi
110 fi
111
112 DEPS_INC="$WORKSPACE/deps/build/include"
113 DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH"
114 DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
115 #DEPS_BIN="$WORKSPACE/deps/build/bin"
116 #DEPS_JAVA="$WORKSPACE/deps/build/share/java"
117
118 export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
119 export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
120 export CPPFLAGS="-I$DEPS_INC"
121 export LDFLAGS="-L$DEPS_LIB"
122
123 # Create tmp directory
124 rm -rf "$TMPDIR"
125 mkdir -p "$TMPDIR"
126
127 export TMPDIR
128 export CFLAGS="-g -O2"
129
130 # Set compiler variables
131 case "$cc" in
132 gcc)
133 export CC=gcc
134 export CXX=g++
135 ;;
136 gcc-*)
137 export CC=gcc-${cc#gcc-}
138 export CXX=g++-${cc#gcc-}
139 ;;
140 clang)
141 export CC=clang
142 export CXX=clang++
143 ;;
144 clang-*)
145 export CC=clang-${cc#clang-}
146 export CXX=clang++-${cc#clang-}
147 ;;
148 *)
149 if [ "x$cc" != "x" ]; then
150 export CC="$cc"
151 fi
152 ;;
153 esac
154
155 if [ "x${CC:-}" != "x" ]; then
156 echo "Selected compiler:"
157 "$CC" -v
158 fi
159
160 # Set platform variables
161 case "$platform" in
162 freebsd*)
163 export MAKE=gmake
164 export TAR=tar
165 export NPROC="getconf _NPROCESSORS_ONLN"
166 export CPPFLAGS="-I/usr/local/include $CPPFLAGS"
167 export LDFLAGS="-L/usr/local/lib $LDFLAGS"
168 export PYTHON="python3"
169 export PYTHON_CONFIG="python3-config"
170 export CLASSPATH='/usr/local/share/java/classes/*'
171 export JAVA_HOME='/usr/local/openjdk11'
172 ;;
173
174 *)
175 export MAKE=make
176 export TAR=tar
177 export NPROC=nproc
178 export PYTHON="python3"
179 export PYTHON_CONFIG="python3-config"
180 export CLASSPATH='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar'
181 ;;
182 esac
183
184 # Print build env details
185 print_os || true
186 print_tooling || true
187
188 # Enter the source directory
189 cd "$SRCDIR"
190
191 # Run bootstrap in the source directory prior to configure
192 ./bootstrap
193
194 # Get source version from configure script
195 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
196 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
197
198 # Set configure options and environment variables for each build
199 # configuration.
200 CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH")
201 case "$conf" in
202 static)
203 echo "Static lib only configuration"
204
205 CONF_OPTS+=("--enable-static" "--disable-shared")
206
207 # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies.
208 exit 1
209 ;;
210
211 agents)
212 echo "Java and Python agents configuration"
213
214 CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent")
215
216 # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
217 if verlt "$PACKAGE_VERSION" "2.14"; then
218 CONF_OPTS+=("--enable-java-agent-log4j2")
219 fi
220 ;;
221
222 debug-rcu)
223 echo "Enable RCU sanity checks for debugging"
224 export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU"
225 ;;
226
227 *)
228 echo "Standard configuration"
229
230 # Something is broken in docbook-xml on yocto
231 if [[ "$platform" = yocto* ]]; then
232 CONF_OPTS+=("--disable-man-pages")
233 fi
234 ;;
235 esac
236
237 # Build type
238 # oot : out-of-tree build
239 # dist : build via make dist
240 # oot-dist: build via make dist out-of-tree
241 # * : normal tree build
242 #
243 # Make sure to move to the build directory and run configure
244 # before continuing.
245 case "$build" in
246 oot)
247 echo "Out of tree build"
248
249 # Create and enter a temporary build directory
250 builddir=$(mktemp -d)
251 cd "$builddir"
252
253 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
254 ;;
255
256 dist)
257 echo "Distribution in-tree build"
258
259 # Run configure and generate the tar file
260 # in the source directory
261 ./configure --enable-jni-interface || failed_configure
262 $MAKE dist
263
264 # Create and enter a temporary build directory
265 builddir=$(mktemp -d)
266 cd "$builddir"
267
268 # Extract the distribution tar in the build directory,
269 # ignore the first directory level
270 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
271
272 # Build in extracted source tree
273 ./configure "${CONF_OPTS[@]}" || failed_configure
274 ;;
275
276 oot-dist)
277 echo "Distribution out of tree build"
278
279 # Create and enter a temporary build directory
280 builddir=$(mktemp -d)
281 cd "$builddir"
282
283 # Run configure out of tree and generate the tar file
284 "$SRCDIR/configure" --enable-jni-interface || failed_configure
285 $MAKE dist
286
287 dist_srcdir="$(mktemp -d)"
288 cd "$dist_srcdir"
289
290 # Extract the distribution tar in the new source directory,
291 # ignore the first directory level
292 $TAR xvf "$builddir"/*.tar.* --strip 1
293
294 # Create and enter a second temporary build directory
295 builddir="$(mktemp -d)"
296 cd "$builddir"
297
298 # Run configure from the extracted distribution tar,
299 # out of the source tree
300 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
301 ;;
302
303 *)
304 echo "Standard in-tree build"
305 ./configure "${CONF_OPTS[@]}" || failed_configure
306 ;;
307 esac
308
309 # We are now inside a configured build directory
310
311 # BUILD!
312 $MAKE -j "$($NPROC)" V=1
313
314 # Install in the workspace
315 $MAKE install DESTDIR="$WORKSPACE"
316
317 # Run tests, don't fail now, we want to run the archiving steps
318 failed_tests=0
319 if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then
320 $MAKE --keep-going check || failed_tests=1
321
322 # Copy tap logs for the jenkins tap parser before cleaning the build dir
323 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
324
325 # Copy the test suites top-level log which includes all tests failures
326 rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log"
327
328 # The test suite prior to 2.8 did not produce TAP logs
329 if verlt "$PACKAGE_VERSION" "2.8"; then
330 mkdir -p "$WORKSPACE/tap/no-log"
331 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
332 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
333 fi
334 fi
335
336 # Clean the build directory
337 $MAKE clean
338
339 # Cleanup rpath in executables and shared libraries
340 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
341 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
342
343 # Remove libtool .la files
344 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
345
346 # Exit with failure if any of the tests failed
347 exit $failed_tests
348
349 # EOF
This page took 0.047454 seconds and 5 git commands to generate.