jjb: lttng-ust: fix gerrit FreeBSD build for < stable-2.13
[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 local i ver1=($1) ver2=($2)
29 # fill empty fields in ver1 with zeros
30 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
31 ver1[i]=0
32 done
33 for ((i=0; i<${#ver1[@]}; i++)); do
34 if [[ -z ${ver2[i]} ]]; then
35 # fill empty fields in ver2 with zeros
36 ver2[i]=0
37 fi
38 if ((10#${ver1[i]} > 10#${ver2[i]})); then
39 return 1
40 fi
41 if ((10#${ver1[i]} < 10#${ver2[i]})); then
42 return 2
43 fi
44 done
45 set -u
46 return 0
47 }
48
49 verlte() {
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
52 }
53
54 verlt() {
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "2" ]
57 }
58
59 vergte() {
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
62 }
63
64 vergt() {
65 vercomp "$1" "$2"; local res="$?"
66 [ "$res" -eq "1" ]
67 }
68
69 verne() {
70 vercomp "$1" "$2"; local res="$?"
71 [ "$res" -ne "0" ]
72 }
73
74 failed_configure() {
75 # Assume we are in the configured build directory
76 echo "#################### BEGIN config.log ####################"
77 cat config.log
78 echo "#################### END config.log ####################"
79
80 # End the build with failure
81 exit 1
82 }
83
84 # Required variables
85 WORKSPACE=${WORKSPACE:-}
86
87 arch=${arch:-}
88 conf=${conf:-}
89 build=${build:-}
90 cc=${cc:-}
91
92 # Controls if the tests are run
93 LTTNG_UST_RUN_TESTS="${LTTNG_UST_RUN_TESTS:=yes}"
94
95 DEPS_INC="$WORKSPACE/deps/build/include"
96 DEPS_LIB="$WORKSPACE/deps/build/lib"
97 DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
98 #DEPS_BIN="$WORKSPACE/deps/build/bin"
99 #DEPS_JAVA="$WORKSPACE/deps/build/share/java"
100
101 export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
102 export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
103 export CPPFLAGS="-I$DEPS_INC"
104 export LDFLAGS="-L$DEPS_LIB"
105
106 SRCDIR="$WORKSPACE/src/lttng-ust"
107 TMPDIR="$WORKSPACE/tmp"
108 PREFIX="/build"
109
110 # Create tmp directory
111 rm -rf "$TMPDIR"
112 mkdir -p "$TMPDIR"
113
114 export TMPDIR
115 export CFLAGS="-g -O2"
116
117 # Set compiler variables
118 case "$cc" in
119 gcc)
120 export CC=gcc
121 export CXX=g++
122 ;;
123 gcc-*)
124 export CC=gcc-${cc#gcc-}
125 export CXX=g++-${cc#gcc-}
126 ;;
127 clang)
128 export CC=clang
129 export CXX=clang++
130 ;;
131 clang-*)
132 export CC=clang-${cc#clang-}
133 export CXX=clang++-${cc#clang-}
134 ;;
135 *)
136 if [ "x$cc" != "x" ]; then
137 export CC="$cc"
138 fi
139 ;;
140 esac
141
142 if [ "x${CC:-}" != "x" ]; then
143 echo "Selected compiler:"
144 "$CC" -v
145 fi
146
147 # Set platform variables
148 case "$arch" in
149 freebsd*)
150 export MAKE=gmake
151 export TAR=tar
152 export NPROC="getconf _NPROCESSORS_ONLN"
153 export CPPFLAGS="-I/usr/local/include $CPPFLAGS"
154 export LDFLAGS="-L/usr/local/lib $LDFLAGS"
155 export PYTHON="python3"
156 export PYTHON_CONFIG="python3-config"
157 export CLASSPATH='/usr/local/share/java/classes/*'
158 export JAVA_HOME='/usr/local/openjdk11'
159 ;;
160
161 *)
162 export MAKE=make
163 export TAR=tar
164 export NPROC=nproc
165 export PYTHON="python3"
166 export PYTHON_CONFIG="python3-config"
167 export CLASSPATH='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar'
168 ;;
169 esac
170
171 # Print build env details
172 print_os || true
173 print_tooling || true
174
175 # Enter the source directory
176 cd "$SRCDIR"
177
178 # Run bootstrap in the source directory prior to configure
179 ./bootstrap
180
181 # Get source version from configure script
182 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
183 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
184
185 # Gerrit will trigger build on FreeBSD regardless of the branch, exit
186 # successfuly when the version is < 2.13.
187 if [[ $arch == freebsd* ]] && verlt "$PACKAGE_VERSION" "2.13"; then
188 mkdir -p "$WORKSPACE/tap/no-log"
189 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
190 echo "ok 1 - FreeBSD build unsupported in < 2.13" >> "$WORKSPACE/tap/no-log/tests.log"
191 exit 0
192 fi
193
194 # Set configure options and environment variables for each build
195 # configuration.
196 CONF_OPTS=("--prefix=$PREFIX")
197 case "$conf" in
198 static)
199 echo "Static lib only configuration"
200
201 CONF_OPTS+=("--enable-static" "--disable-shared")
202
203 # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies.
204 exit 1
205 ;;
206
207 agents)
208 echo "Java and Python agents configuration"
209
210 CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent")
211
212 # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
213 if verlt "$PACKAGE_VERSION" "2.14"; then
214 CONF_OPTS+=("--enable-java-agent-log4j2")
215 fi
216 ;;
217
218 debug-rcu)
219 echo "Enable RCU sanity checks for debugging"
220 export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU"
221 ;;
222
223 *)
224 echo "Standard configuration"
225 ;;
226 esac
227
228 # Build type
229 # oot : out-of-tree build
230 # dist : build via make dist
231 # oot-dist: build via make dist out-of-tree
232 # * : normal tree build
233 #
234 # Make sure to move to the build directory and run configure
235 # before continuing.
236 case "$build" in
237 oot)
238 echo "Out of tree build"
239
240 # Create and enter a temporary build directory
241 builddir=$(mktemp -d)
242 cd "$builddir"
243
244 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
245 ;;
246
247 dist)
248 echo "Distribution in-tree build"
249
250 # Run configure and generate the tar file
251 # in the source directory
252 ./configure --enable-jni-interface || failed_configure
253 $MAKE dist
254
255 # Create and enter a temporary build directory
256 builddir=$(mktemp -d)
257 cd "$builddir"
258
259 # Extract the distribution tar in the build directory,
260 # ignore the first directory level
261 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
262
263 # Build in extracted source tree
264 ./configure "${CONF_OPTS[@]}" || failed_configure
265 ;;
266
267 oot-dist)
268 echo "Distribution out of tree build"
269
270 # Create and enter a temporary build directory
271 builddir=$(mktemp -d)
272 cd "$builddir"
273
274 # Run configure out of tree and generate the tar file
275 "$SRCDIR/configure" --enable-jni-interface || failed_configure
276 $MAKE dist
277
278 dist_srcdir="$(mktemp -d)"
279 cd "$dist_srcdir"
280
281 # Extract the distribution tar in the new source directory,
282 # ignore the first directory level
283 $TAR xvf "$builddir"/*.tar.* --strip 1
284
285 # Create and enter a second temporary build directory
286 builddir="$(mktemp -d)"
287 cd "$builddir"
288
289 # Run configure from the extracted distribution tar,
290 # out of the source tree
291 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
292 ;;
293
294 *)
295 echo "Standard in-tree build"
296 ./configure "${CONF_OPTS[@]}" || failed_configure
297 ;;
298 esac
299
300 # We are now inside a configured build directory
301
302 # BUILD!
303 $MAKE -j "$($NPROC)" V=1
304
305 # Install in the workspace
306 $MAKE install DESTDIR="$WORKSPACE"
307
308 # Run tests, don't fail now, we want to run the archiving steps
309 failed_tests=0
310 if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then
311 $MAKE --keep-going check || failed_tests=1
312
313 # Copy tap logs for the jenkins tap parser before cleaning the build dir
314 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
315
316 # The test suite prior to 2.8 did not produce TAP logs
317 if verlt "$PACKAGE_VERSION" "2.8"; then
318 mkdir -p "$WORKSPACE/tap/no-log"
319 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
320 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
321 fi
322 fi
323
324 # Clean the build directory
325 $MAKE clean
326
327 # Cleanup rpath in executables and shared libraries
328 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
329 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
330
331 # Remove libtool .la files
332 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
333
334 # Exit with failure if any of the tests failed
335 exit $failed_tests
336
337 # EOF
This page took 0.037305 seconds and 5 git commands to generate.