Commit | Line | Data |
---|---|---|
51c9c62d | 1 | #!/bin/bash |
2b68721a | 2 | # |
2c34ea14 MJ |
3 | # SPDX-FileCopyrightText: 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
4 | # SPDX-FileCopyrightText: 2016-2023 Michael Jeanson <mjeanson@efficios.com> | |
5 | # SPDX-License-Identifier: GPL-2.0-or-later | |
2b68721a | 6 | |
51c9c62d MJ |
7 | set -exu |
8 | ||
3579dc14 MJ |
9 | # Version compare functions |
10 | vercomp () { | |
11 | set +u | |
12 | if [[ "$1" == "$2" ]]; then | |
13 | return 0 | |
14 | fi | |
15 | local IFS=. | |
4afa623f MJ |
16 | # Ignore the shellcheck warning, we want splitting to happen based on IFS. |
17 | # shellcheck disable=SC2206 | |
3579dc14 MJ |
18 | local i ver1=($1) ver2=($2) |
19 | # fill empty fields in ver1 with zeros | |
20 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do | |
21 | ver1[i]=0 | |
22 | done | |
23 | for ((i=0; i<${#ver1[@]}; i++)); do | |
24 | if [[ -z ${ver2[i]} ]]; then | |
25 | # fill empty fields in ver2 with zeros | |
26 | ver2[i]=0 | |
27 | fi | |
28 | if ((10#${ver1[i]} > 10#${ver2[i]})); then | |
29 | return 1 | |
30 | fi | |
31 | if ((10#${ver1[i]} < 10#${ver2[i]})); then | |
32 | return 2 | |
33 | fi | |
34 | done | |
35 | set -u | |
36 | return 0 | |
37 | } | |
38 | ||
39 | verlte() { | |
40 | vercomp "$1" "$2"; local res="$?" | |
41 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] | |
42 | } | |
43 | ||
44 | verlt() { | |
45 | vercomp "$1" "$2"; local res="$?" | |
46 | [ "$res" -eq "2" ] | |
47 | } | |
48 | ||
49 | vergte() { | |
50 | vercomp "$1" "$2"; local res="$?" | |
51 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
52 | } | |
53 | ||
54 | vergt() { | |
55 | vercomp "$1" "$2"; local res="$?" | |
56 | [ "$res" -eq "1" ] | |
57 | } | |
58 | ||
59 | verne() { | |
60 | vercomp "$1" "$2"; local res="$?" | |
61 | [ "$res" -ne "0" ] | |
62 | } | |
63 | ||
2c34ea14 MJ |
64 | print_header() { |
65 | set +x | |
66 | ||
67 | local message=" $1 " | |
68 | local message_len | |
69 | local padding_len | |
70 | ||
71 | message_len="${#message}" | |
72 | padding_len=$(( (80 - (message_len)) / 2 )) | |
73 | ||
74 | printf '\n'; printf -- '#%.0s' {1..80}; printf '\n' | |
75 | printf -- '-%.0s' {1..80}; printf '\n' | |
76 | printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n' | |
77 | printf -- '-%.0s' {1..80}; printf '\n' | |
78 | printf -- '#%.0s' {1..80}; printf '\n\n' | |
79 | ||
80 | set -x | |
81 | } | |
82 | ||
51c9c62d MJ |
83 | failed_configure() { |
84 | # Assume we are in the configured build directory | |
2c34ea14 | 85 | print_header "BEGIN config.log" |
51c9c62d | 86 | cat config.log |
2c34ea14 | 87 | print_header "END config.log" |
51c9c62d MJ |
88 | |
89 | # End the build with failure | |
90 | exit 1 | |
91 | } | |
92 | ||
2c34ea14 MJ |
93 | print_header "LTTng-UST build script starting" |
94 | ||
e04f80ef MJ |
95 | # Required variables |
96 | WORKSPACE=${WORKSPACE:-} | |
97 | ||
2c34ea14 | 98 | # Axis |
94a6d1fb | 99 | platform=${platform:-} |
a57a60d9 MJ |
100 | conf=${conf:-} |
101 | build=${build:-} | |
3579dc14 MJ |
102 | cc=${cc:-} |
103 | ||
2c34ea14 MJ |
104 | # Build steps that can be overriden by the environment |
105 | LTTNG_UST_MAKE_INSTALL="${LTTNG_UST_MAKE_INSTALL:-yes}" | |
106 | LTTNG_UST_MAKE_CLEAN="${LTTNG_UST_MAKE_CLEAN:-yes}" | |
107 | LTTNG_UST_GEN_COMPILE_COMMANDS="${LTTNG_UST_GEN_COMPILE_COMMANDS:-no}" | |
108 | LTTNG_UST_RUN_TESTS="${LTTNG_UST_RUN_TESTS:-yes}" | |
109 | LTTNG_UST_CLANG_TIDY="${LTTNG_UST_CLANG_TIDY:-no}" | |
a57a60d9 | 110 | |
4afa623f MJ |
111 | SRCDIR="$WORKSPACE/src/lttng-ust" |
112 | TMPDIR="$WORKSPACE/tmp" | |
113 | PREFIX="/build" | |
114 | LIBDIR="lib" | |
32dde2a3 | 115 | LIBDIR_ARCH="$LIBDIR" |
4afa623f MJ |
116 | |
117 | # RHEL and SLES both use lib64 but don't bother shipping a default autoconf | |
118 | # site config that matches this. | |
47ca4354 | 119 | if [[ ( -f /etc/redhat-release || -f /etc/products.d/SLES.prod || -f /etc/yocto-release ) ]]; then |
85322e5d MJ |
120 | # Detect the userspace bitness in a distro agnostic way |
121 | if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then | |
122 | LIBDIR_ARCH="${LIBDIR}64" | |
85322e5d | 123 | fi |
4afa623f MJ |
124 | fi |
125 | ||
3579dc14 | 126 | DEPS_INC="$WORKSPACE/deps/build/include" |
4afa623f | 127 | DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH" |
5bd69da1 | 128 | DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig" |
1d56e325 MJ |
129 | #DEPS_BIN="$WORKSPACE/deps/build/bin" |
130 | #DEPS_JAVA="$WORKSPACE/deps/build/share/java" | |
2b68721a | 131 | |
3579dc14 | 132 | export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}" |
5bd69da1 | 133 | export PKG_CONFIG_PATH="$DEPS_PKGCONFIG" |
3579dc14 MJ |
134 | export CPPFLAGS="-I$DEPS_INC" |
135 | export LDFLAGS="-L$DEPS_LIB" | |
c3bc676b | 136 | |
2c34ea14 MJ |
137 | exit_status=0 |
138 | ||
139 | # Use bear to generate compile_commands.json when enabled | |
140 | BEAR="" | |
141 | if [ "$LTTNG_UST_GEN_COMPILE_COMMANDS" = "yes" ]; then | |
142 | BEAR="bear" | |
143 | fi | |
144 | ||
3579dc14 MJ |
145 | # Create tmp directory |
146 | rm -rf "$TMPDIR" | |
147 | mkdir -p "$TMPDIR" | |
1f4fba8c MJ |
148 | |
149 | export TMPDIR | |
72d087d4 | 150 | export CFLAGS="-g -O2" |
2c34ea14 | 151 | export CXXFLAGS="-g -O2" |
1f4fba8c | 152 | |
3579dc14 MJ |
153 | # Set compiler variables |
154 | case "$cc" in | |
155 | gcc) | |
156 | export CC=gcc | |
157 | export CXX=g++ | |
158 | ;; | |
2356937a MJ |
159 | gcc-*) |
160 | export CC=gcc-${cc#gcc-} | |
161 | export CXX=g++-${cc#gcc-} | |
3579dc14 MJ |
162 | ;; |
163 | clang) | |
164 | export CC=clang | |
165 | export CXX=clang++ | |
166 | ;; | |
2356937a MJ |
167 | clang-*) |
168 | export CC=clang-${cc#clang-} | |
169 | export CXX=clang++-${cc#clang-} | |
3579dc14 MJ |
170 | ;; |
171 | *) | |
172 | if [ "x$cc" != "x" ]; then | |
173 | export CC="$cc" | |
174 | fi | |
175 | ;; | |
176 | esac | |
177 | ||
3b3282a6 | 178 | # Set platform variables |
94a6d1fb | 179 | case "$platform" in |
2356937a | 180 | freebsd*) |
0f7217a0 MJ |
181 | export MAKE=gmake |
182 | export TAR=tar | |
183 | export NPROC="getconf _NPROCESSORS_ONLN" | |
184 | export CPPFLAGS="-I/usr/local/include $CPPFLAGS" | |
185 | export LDFLAGS="-L/usr/local/lib $LDFLAGS" | |
186 | export PYTHON="python3" | |
187 | export PYTHON_CONFIG="python3-config" | |
188 | export CLASSPATH='/usr/local/share/java/classes/*' | |
e16ea2bf | 189 | export JAVA_HOME='/usr/local/openjdk17' |
0f7217a0 MJ |
190 | ;; |
191 | ||
3b3282a6 | 192 | *) |
3579dc14 MJ |
193 | export MAKE=make |
194 | export TAR=tar | |
195 | export NPROC=nproc | |
196 | export PYTHON="python3" | |
197 | export PYTHON_CONFIG="python3-config" | |
d956cb6e | 198 | export CLASSPATH='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar' |
3579dc14 | 199 | ;; |
3b3282a6 MJ |
200 | esac |
201 | ||
51c9c62d | 202 | # Print build env details |
2c34ea14 | 203 | print_header "Build environment details" |
8c956c4b | 204 | print_hardware || true |
51c9c62d MJ |
205 | print_os || true |
206 | print_tooling || true | |
207 | ||
3579dc14 MJ |
208 | # Enter the source directory |
209 | cd "$SRCDIR" | |
c3bc676b | 210 | |
3579dc14 | 211 | # Run bootstrap in the source directory prior to configure |
2c34ea14 | 212 | print_header "Bootstrap autotools" |
3579dc14 | 213 | ./bootstrap |
ab89ec98 | 214 | |
3579dc14 MJ |
215 | # Get source version from configure script |
216 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
1d56e325 | 217 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
c3bc676b | 218 | |
3579dc14 MJ |
219 | # Set configure options and environment variables for each build |
220 | # configuration. | |
2c34ea14 | 221 | CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode") |
c3bc676b | 222 | case "$conf" in |
3b3282a6 | 223 | static) |
2c34ea14 | 224 | print_header "Conf: Static lib only" |
3579dc14 MJ |
225 | |
226 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
1d56e325 MJ |
227 | |
228 | # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies. | |
229 | exit 1 | |
3b3282a6 MJ |
230 | ;; |
231 | ||
67122b96 | 232 | agents) |
2c34ea14 | 233 | print_header "Conf: Java and Python agents" |
3b3282a6 | 234 | |
3579dc14 | 235 | CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent") |
efb13b46 MJ |
236 | |
237 | # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13 | |
238 | if verlt "$PACKAGE_VERSION" "2.14"; then | |
239 | CONF_OPTS+=("--enable-java-agent-log4j2") | |
240 | fi | |
3b3282a6 MJ |
241 | ;; |
242 | ||
a76416f2 | 243 | debug-rcu) |
2c34ea14 MJ |
244 | print_header "Conf: Enable RCU sanity checks for debugging" |
245 | ||
3579dc14 | 246 | export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU" |
a76416f2 JR |
247 | ;; |
248 | ||
c3bc676b | 249 | *) |
2c34ea14 | 250 | print_header "Conf: Standard" |
6871000c MJ |
251 | |
252 | # Something is broken in docbook-xml on yocto | |
253 | if [[ "$platform" = yocto* ]]; then | |
254 | CONF_OPTS+=("--disable-man-pages") | |
255 | fi | |
c3bc676b JRJ |
256 | ;; |
257 | esac | |
258 | ||
2b68721a | 259 | # Build type |
67122b96 MJ |
260 | # oot : out-of-tree build |
261 | # dist : build via make dist | |
262 | # oot-dist: build via make dist out-of-tree | |
263 | # * : normal tree build | |
2b68721a | 264 | # |
3579dc14 MJ |
265 | # Make sure to move to the build directory and run configure |
266 | # before continuing. | |
2b68721a | 267 | case "$build" in |
3b3282a6 | 268 | oot) |
2c34ea14 | 269 | print_header "Build: Out of tree" |
67122b96 | 270 | |
3579dc14 MJ |
271 | # Create and enter a temporary build directory |
272 | builddir=$(mktemp -d) | |
273 | cd "$builddir" | |
67122b96 | 274 | |
51c9c62d | 275 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
3b3282a6 MJ |
276 | ;; |
277 | ||
278 | dist) | |
2c34ea14 | 279 | print_header "Build: Distribution In-tree" |
3b3282a6 | 280 | |
3579dc14 MJ |
281 | # Run configure and generate the tar file |
282 | # in the source directory | |
0b93ba40 | 283 | ./configure --enable-jni-interface || failed_configure |
3b3282a6 MJ |
284 | $MAKE dist |
285 | ||
3579dc14 MJ |
286 | # Create and enter a temporary build directory |
287 | builddir=$(mktemp -d) | |
288 | cd "$builddir" | |
3b3282a6 | 289 | |
3579dc14 MJ |
290 | # Extract the distribution tar in the build directory, |
291 | # ignore the first directory level | |
292 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
3b3282a6 | 293 | |
67122b96 | 294 | # Build in extracted source tree |
51c9c62d | 295 | ./configure "${CONF_OPTS[@]}" || failed_configure |
3b3282a6 MJ |
296 | ;; |
297 | ||
67122b96 | 298 | oot-dist) |
2c34ea14 | 299 | print_header "Build: Distribution Out of tree" |
67122b96 | 300 | |
3579dc14 MJ |
301 | # Create and enter a temporary build directory |
302 | builddir=$(mktemp -d) | |
303 | cd "$builddir" | |
304 | ||
305 | # Run configure out of tree and generate the tar file | |
0b93ba40 | 306 | "$SRCDIR/configure" --enable-jni-interface || failed_configure |
67122b96 MJ |
307 | $MAKE dist |
308 | ||
3579dc14 MJ |
309 | dist_srcdir="$(mktemp -d)" |
310 | cd "$dist_srcdir" | |
67122b96 | 311 | |
3579dc14 MJ |
312 | # Extract the distribution tar in the new source directory, |
313 | # ignore the first directory level | |
314 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
67122b96 | 315 | |
3579dc14 MJ |
316 | # Create and enter a second temporary build directory |
317 | builddir="$(mktemp -d)" | |
318 | cd "$builddir" | |
67122b96 | 319 | |
3579dc14 MJ |
320 | # Run configure from the extracted distribution tar, |
321 | # out of the source tree | |
51c9c62d | 322 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
67122b96 MJ |
323 | ;; |
324 | ||
3b3282a6 | 325 | *) |
2c34ea14 MJ |
326 | print_header "Build: Standard In-tree" |
327 | ||
51c9c62d | 328 | ./configure "${CONF_OPTS[@]}" || failed_configure |
3b3282a6 | 329 | ;; |
2b68721a MJ |
330 | esac |
331 | ||
3579dc14 MJ |
332 | # We are now inside a configured build directory |
333 | ||
3b3282a6 | 334 | # BUILD! |
2c34ea14 MJ |
335 | print_header "BUILD!" |
336 | $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V=1 | |
337 | ||
338 | # Install in the workspace if enabled | |
339 | if [ "$LTTNG_UST_MAKE_INSTALL" = "yes" ]; then | |
340 | print_header "Install" | |
341 | ||
342 | $MAKE install V=1 DESTDIR="$WORKSPACE" | |
343 | ||
344 | # Cleanup rpath in executables and shared libraries | |
345 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; | |
346 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \; | |
347 | ||
348 | # Remove libtool .la files | |
349 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete | |
350 | fi | |
351 | ||
352 | # Run clang-tidy on the topmost commit | |
353 | if [ "$LTTNG_UST_CLANG_TIDY" = "yes" ]; then | |
354 | print_header "Run clang-tidy" | |
c3bc676b | 355 | |
2c34ea14 MJ |
356 | # This would be better by linting only the lines touched by a patch but it |
357 | # doesn't seem to work, the lines are always filtered and no error is | |
358 | # reported. | |
359 | #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix | |
360 | ||
361 | # Instead, run clan-tidy on all the files touched by the patch. | |
362 | while read -r filepath; do | |
363 | if [[ "$filepath" =~ (\.cpp|\.hhp|\.c|\.h)$ ]]; then | |
364 | clang-tidy --fix-errors "$(realpath "$filepath")" | |
365 | fi | |
366 | done < <(git diff-tree --no-commit-id --diff-filter=d --name-only -r HEAD) | |
367 | ||
368 | # If the tree has local changes, the formatting was incorrect | |
369 | GIT_DIFF_OUTPUT=$(git diff) | |
370 | if [ -n "$GIT_DIFF_OUTPUT" ]; then | |
371 | echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff" | |
372 | git diff > "$WORKSPACE/clang-tidy-fixes.diff" | |
373 | ||
374 | # Restore the unfixed files so they can be viewed in the warnings web | |
375 | # interface | |
376 | git checkout . | |
377 | exit_status=1 | |
378 | fi | |
379 | fi | |
3579dc14 MJ |
380 | |
381 | # Run tests, don't fail now, we want to run the archiving steps | |
aff4e3d1 | 382 | if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then |
2c34ea14 | 383 | $MAKE --keep-going check || exit_status=1 |
c3bc676b | 384 | |
aff4e3d1 JR |
385 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
386 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" | |
c3bc676b | 387 | |
4174b905 MJ |
388 | # Copy the test suites top-level log which includes all tests failures |
389 | rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log" | |
0fe4a4b4 MJ |
390 | fi |
391 | ||
1f4fba8c | 392 | # Clean the build directory |
2c34ea14 MJ |
393 | if [ "$LTTNG_UST_MAKE_CLEAN" = "yes" ]; then |
394 | print_header "Clean" | |
c3bc676b | 395 | |
2c34ea14 MJ |
396 | $MAKE clean |
397 | fi | |
3b3282a6 | 398 | |
2c34ea14 | 399 | print_header "LTTng-UST build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)" |
2b68721a | 400 | |
1d56e325 | 401 | # Exit with failure if any of the tests failed |
2c34ea14 | 402 | exit $exit_status |
3b3282a6 MJ |
403 | |
404 | # EOF | |
2c34ea14 | 405 | # vim: expandtab tabstop=4 shiftwidth=4 |