Commit | Line | Data |
---|---|---|
51c9c62d | 1 | #!/bin/bash |
2b68721a | 2 | # |
3579dc14 MJ |
3 | # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
4 | # 2016-2019 Michael Jeanson <mjeanson@efficios.com> | |
2b68721a MJ |
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 | ||
51c9c62d MJ |
19 | set -exu |
20 | ||
3579dc14 MJ |
21 | # Version compare functions |
22 | vercomp () { | |
23 | set +u | |
24 | if [[ "$1" == "$2" ]]; then | |
25 | return 0 | |
26 | fi | |
27 | local IFS=. | |
4afa623f MJ |
28 | # Ignore the shellcheck warning, we want splitting to happen based on IFS. |
29 | # shellcheck disable=SC2206 | |
3579dc14 MJ |
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 | ||
51c9c62d MJ |
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 | ||
e04f80ef MJ |
86 | # Required variables |
87 | WORKSPACE=${WORKSPACE:-} | |
88 | ||
94a6d1fb | 89 | platform=${platform:-} |
a57a60d9 MJ |
90 | conf=${conf:-} |
91 | build=${build:-} | |
3579dc14 MJ |
92 | cc=${cc:-} |
93 | ||
aff4e3d1 JR |
94 | # Controls if the tests are run |
95 | LTTNG_UST_RUN_TESTS="${LTTNG_UST_RUN_TESTS:=yes}" | |
a57a60d9 | 96 | |
4afa623f MJ |
97 | SRCDIR="$WORKSPACE/src/lttng-ust" |
98 | TMPDIR="$WORKSPACE/tmp" | |
99 | PREFIX="/build" | |
100 | LIBDIR="lib" | |
101 | ||
102 | # RHEL and SLES both use lib64 but don't bother shipping a default autoconf | |
103 | # site config that matches this. | |
104 | if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release ) && ( "$(uname -m)" == "x86_64" ) ]]; then | |
105 | LIBDIR_ARCH="${LIBDIR}64" | |
106 | else | |
107 | LIBDIR_ARCH="$LIBDIR" | |
108 | fi | |
109 | ||
3579dc14 | 110 | DEPS_INC="$WORKSPACE/deps/build/include" |
4afa623f | 111 | DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH" |
5bd69da1 | 112 | DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig" |
1d56e325 MJ |
113 | #DEPS_BIN="$WORKSPACE/deps/build/bin" |
114 | #DEPS_JAVA="$WORKSPACE/deps/build/share/java" | |
2b68721a | 115 | |
3579dc14 | 116 | export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}" |
5bd69da1 | 117 | export PKG_CONFIG_PATH="$DEPS_PKGCONFIG" |
3579dc14 MJ |
118 | export CPPFLAGS="-I$DEPS_INC" |
119 | export LDFLAGS="-L$DEPS_LIB" | |
c3bc676b | 120 | |
3579dc14 MJ |
121 | # Create tmp directory |
122 | rm -rf "$TMPDIR" | |
123 | mkdir -p "$TMPDIR" | |
1f4fba8c MJ |
124 | |
125 | export TMPDIR | |
72d087d4 | 126 | export CFLAGS="-g -O2" |
1f4fba8c | 127 | |
3579dc14 MJ |
128 | # Set compiler variables |
129 | case "$cc" in | |
130 | gcc) | |
131 | export CC=gcc | |
132 | export CXX=g++ | |
133 | ;; | |
2356937a MJ |
134 | gcc-*) |
135 | export CC=gcc-${cc#gcc-} | |
136 | export CXX=g++-${cc#gcc-} | |
3579dc14 MJ |
137 | ;; |
138 | clang) | |
139 | export CC=clang | |
140 | export CXX=clang++ | |
141 | ;; | |
2356937a MJ |
142 | clang-*) |
143 | export CC=clang-${cc#clang-} | |
144 | export CXX=clang++-${cc#clang-} | |
3579dc14 MJ |
145 | ;; |
146 | *) | |
147 | if [ "x$cc" != "x" ]; then | |
148 | export CC="$cc" | |
149 | fi | |
150 | ;; | |
151 | esac | |
152 | ||
153 | if [ "x${CC:-}" != "x" ]; then | |
154 | echo "Selected compiler:" | |
155 | "$CC" -v | |
156 | fi | |
157 | ||
3b3282a6 | 158 | # Set platform variables |
94a6d1fb | 159 | case "$platform" in |
2356937a | 160 | freebsd*) |
0f7217a0 MJ |
161 | export MAKE=gmake |
162 | export TAR=tar | |
163 | export NPROC="getconf _NPROCESSORS_ONLN" | |
164 | export CPPFLAGS="-I/usr/local/include $CPPFLAGS" | |
165 | export LDFLAGS="-L/usr/local/lib $LDFLAGS" | |
166 | export PYTHON="python3" | |
167 | export PYTHON_CONFIG="python3-config" | |
168 | export CLASSPATH='/usr/local/share/java/classes/*' | |
df63a3ac | 169 | export JAVA_HOME='/usr/local/openjdk11' |
0f7217a0 MJ |
170 | ;; |
171 | ||
3b3282a6 | 172 | *) |
3579dc14 MJ |
173 | export MAKE=make |
174 | export TAR=tar | |
175 | export NPROC=nproc | |
176 | export PYTHON="python3" | |
177 | export PYTHON_CONFIG="python3-config" | |
d956cb6e | 178 | export CLASSPATH='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar' |
3579dc14 | 179 | ;; |
3b3282a6 MJ |
180 | esac |
181 | ||
51c9c62d MJ |
182 | # Print build env details |
183 | print_os || true | |
184 | print_tooling || true | |
185 | ||
3579dc14 MJ |
186 | # Enter the source directory |
187 | cd "$SRCDIR" | |
c3bc676b | 188 | |
3579dc14 MJ |
189 | # Run bootstrap in the source directory prior to configure |
190 | ./bootstrap | |
ab89ec98 | 191 | |
3579dc14 MJ |
192 | # Get source version from configure script |
193 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
1d56e325 | 194 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
c3bc676b | 195 | |
0b93ba40 MJ |
196 | # Gerrit will trigger build on FreeBSD regardless of the branch, exit |
197 | # successfuly when the version is < 2.13. | |
94a6d1fb | 198 | if [[ $platform == freebsd* ]] && verlt "$PACKAGE_VERSION" "2.13"; then |
0b93ba40 MJ |
199 | mkdir -p "$WORKSPACE/tap/no-log" |
200 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" | |
201 | echo "ok 1 - FreeBSD build unsupported in < 2.13" >> "$WORKSPACE/tap/no-log/tests.log" | |
202 | exit 0 | |
203 | fi | |
204 | ||
3579dc14 MJ |
205 | # Set configure options and environment variables for each build |
206 | # configuration. | |
4afa623f | 207 | CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH") |
c3bc676b | 208 | case "$conf" in |
3b3282a6 | 209 | static) |
3579dc14 MJ |
210 | echo "Static lib only configuration" |
211 | ||
212 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
1d56e325 MJ |
213 | |
214 | # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies. | |
215 | exit 1 | |
3b3282a6 MJ |
216 | ;; |
217 | ||
67122b96 | 218 | agents) |
3579dc14 | 219 | echo "Java and Python agents configuration" |
3b3282a6 | 220 | |
3579dc14 | 221 | CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent") |
efb13b46 MJ |
222 | |
223 | # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13 | |
224 | if verlt "$PACKAGE_VERSION" "2.14"; then | |
225 | CONF_OPTS+=("--enable-java-agent-log4j2") | |
226 | fi | |
3b3282a6 MJ |
227 | ;; |
228 | ||
a76416f2 JR |
229 | debug-rcu) |
230 | echo "Enable RCU sanity checks for debugging" | |
3579dc14 | 231 | export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU" |
a76416f2 JR |
232 | ;; |
233 | ||
c3bc676b | 234 | *) |
3579dc14 | 235 | echo "Standard configuration" |
6871000c MJ |
236 | |
237 | # Something is broken in docbook-xml on yocto | |
238 | if [[ "$platform" = yocto* ]]; then | |
239 | CONF_OPTS+=("--disable-man-pages") | |
240 | fi | |
c3bc676b JRJ |
241 | ;; |
242 | esac | |
243 | ||
2b68721a | 244 | # Build type |
67122b96 MJ |
245 | # oot : out-of-tree build |
246 | # dist : build via make dist | |
247 | # oot-dist: build via make dist out-of-tree | |
248 | # * : normal tree build | |
2b68721a | 249 | # |
3579dc14 MJ |
250 | # Make sure to move to the build directory and run configure |
251 | # before continuing. | |
2b68721a | 252 | case "$build" in |
3b3282a6 MJ |
253 | oot) |
254 | echo "Out of tree build" | |
67122b96 | 255 | |
3579dc14 MJ |
256 | # Create and enter a temporary build directory |
257 | builddir=$(mktemp -d) | |
258 | cd "$builddir" | |
67122b96 | 259 | |
51c9c62d | 260 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
3b3282a6 MJ |
261 | ;; |
262 | ||
263 | dist) | |
3579dc14 | 264 | echo "Distribution in-tree build" |
3b3282a6 | 265 | |
3579dc14 MJ |
266 | # Run configure and generate the tar file |
267 | # in the source directory | |
0b93ba40 | 268 | ./configure --enable-jni-interface || failed_configure |
3b3282a6 MJ |
269 | $MAKE dist |
270 | ||
3579dc14 MJ |
271 | # Create and enter a temporary build directory |
272 | builddir=$(mktemp -d) | |
273 | cd "$builddir" | |
3b3282a6 | 274 | |
3579dc14 MJ |
275 | # Extract the distribution tar in the build directory, |
276 | # ignore the first directory level | |
277 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
3b3282a6 | 278 | |
67122b96 | 279 | # Build in extracted source tree |
51c9c62d | 280 | ./configure "${CONF_OPTS[@]}" || failed_configure |
3b3282a6 MJ |
281 | ;; |
282 | ||
67122b96 | 283 | oot-dist) |
3579dc14 | 284 | echo "Distribution out of tree build" |
67122b96 | 285 | |
3579dc14 MJ |
286 | # Create and enter a temporary build directory |
287 | builddir=$(mktemp -d) | |
288 | cd "$builddir" | |
289 | ||
290 | # Run configure out of tree and generate the tar file | |
0b93ba40 | 291 | "$SRCDIR/configure" --enable-jni-interface || failed_configure |
67122b96 MJ |
292 | $MAKE dist |
293 | ||
3579dc14 MJ |
294 | dist_srcdir="$(mktemp -d)" |
295 | cd "$dist_srcdir" | |
67122b96 | 296 | |
3579dc14 MJ |
297 | # Extract the distribution tar in the new source directory, |
298 | # ignore the first directory level | |
299 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
67122b96 | 300 | |
3579dc14 MJ |
301 | # Create and enter a second temporary build directory |
302 | builddir="$(mktemp -d)" | |
303 | cd "$builddir" | |
67122b96 | 304 | |
3579dc14 MJ |
305 | # Run configure from the extracted distribution tar, |
306 | # out of the source tree | |
51c9c62d | 307 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
67122b96 MJ |
308 | ;; |
309 | ||
3b3282a6 | 310 | *) |
1f4fba8c | 311 | echo "Standard in-tree build" |
51c9c62d | 312 | ./configure "${CONF_OPTS[@]}" || failed_configure |
3b3282a6 | 313 | ;; |
2b68721a MJ |
314 | esac |
315 | ||
3579dc14 MJ |
316 | # We are now inside a configured build directory |
317 | ||
3b3282a6 | 318 | # BUILD! |
a57a60d9 | 319 | $MAKE -j "$($NPROC)" V=1 |
c3bc676b | 320 | |
3579dc14 MJ |
321 | # Install in the workspace |
322 | $MAKE install DESTDIR="$WORKSPACE" | |
323 | ||
324 | # Run tests, don't fail now, we want to run the archiving steps | |
1d56e325 | 325 | failed_tests=0 |
aff4e3d1 JR |
326 | if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then |
327 | $MAKE --keep-going check || failed_tests=1 | |
c3bc676b | 328 | |
aff4e3d1 JR |
329 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
330 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" | |
c3bc676b | 331 | |
aff4e3d1 JR |
332 | # The test suite prior to 2.8 did not produce TAP logs |
333 | if verlt "$PACKAGE_VERSION" "2.8"; then | |
334 | mkdir -p "$WORKSPACE/tap/no-log" | |
335 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" | |
336 | echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log" | |
337 | fi | |
0fe4a4b4 MJ |
338 | fi |
339 | ||
1f4fba8c | 340 | # Clean the build directory |
3b3282a6 | 341 | $MAKE clean |
c3bc676b | 342 | |
3b3282a6 | 343 | # Cleanup rpath in executables and shared libraries |
1d56e325 | 344 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
4afa623f | 345 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \; |
3b3282a6 MJ |
346 | |
347 | # Remove libtool .la files | |
4afa623f | 348 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \; |
2b68721a | 349 | |
1d56e325 MJ |
350 | # Exit with failure if any of the tests failed |
351 | exit $failed_tests | |
3b3282a6 MJ |
352 | |
353 | # EOF |