summaryrefslogtreecommitdiff
path: root/ci-build.sh
blob: f6ac4291268134d6dd2452596997913aa6561022 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/bin/bash

# Script for GStreamer jenkins/repo CI

# Note: the caller is responsible to set these environment variables if required
# CC          : "ccache gcc" if ccache is installed
# CXX         : "ccache g++" if ccache is installed
# MAKEFLAGS   " "-j6" if on a quad-core machine (adjust based on machine)

# TODO: make it possible to configure what steps should be executed
# for each modules

# setup a prefix directory where everything is installed (for re-use later)
# build them one by one
# install them in the prefix
# report failures at the end
# run this from a directory that contains the checkouts for each of the
# modules

FLAVOR=$1

case "$FLAVOR" in
    fast)
	echo "Using fast variant"
	;;
    fast-build-only)
	echo "Using fast (build only) variant"
	;;
    check)
	echo "Running checks only"
	;;
    validate)
	echo "Using validate variant"
	;;
    nodebug)
	echo "Using nodebug variant"
	;;
    full)
	echo "Using full variant"
	;;
    *)
	echo "Flavor not specified or unsupported"
	echo
	echo " Usage : $0 <flavor>"
	echo
	echo "Available choices:"
	echo "  fast            : Builds without doc/introspection and runs unit tests"
	echo "  fast-build-only : Builds without doc/introspection"
	echo "  check           : Run checks only"
	echo "  nodebug         : Same as fast but with GST_DEBUG disabled"
	echo "  full            : doc/introspection build + distcheck + valgrind"
	echo "  validate        : Builds without doc/introspection and runs gst-validate"
	exit 42
	;;
esac

# modules to be built (if present)
CORE="orc gstreamer gst-plugins-base "
case "$FLAVOR" in
    validate)
	MODULES="gst-plugins-good gst-plugins-ugly gst-libav gst-plugins-bad gst-rtsp-server";;
    *)
	MODULES="gst-plugins-good gst-plugins-ugly gst-libav gst-plugins-bad gst-rtsp-server gst-editing-services gst-python";;
esac

# modules for which we run make check/distcheck
case "$FLAVOR" in
    full)
	# FIXME : distcheck fails for gst-libav
	CHECK_MODULES="orc gstreamer gst-plugins-base gst-plugins-good gst-plugins-ugly gst-plugins-bad gst-rtsp-server gst-editing-services gst-python";;
    validate)
	CHECK_MODULES="";;
    *)
	CHECK_MODULES="orc gstreamer gst-plugins-base gst-plugins-good gst-plugins-ugly gst-plugins-bad gst-libav gst-rtsp-server gst-editing-services gst-python";;
esac

# FIXME : Gradually add more modules
VALGRIND_MODULES=""

ERROR_RETURN=255

echo
echo "======================================================"
echo

if [ -z $VALIDATE_HTTP_PORT ];
then
    echo "Using default validate HTTP port: 8039"
    VALIDATE_HTTP_PORT=8039
else
    echo "Using specified validate HTTP port:" $VALIDATE_HTTP_PORT
fi

if [ -z $VALIDATE_MODULES ];
then
    echo "Using default validate modules: validate ges"
    VALIDATE_MODULES="validate ges"
else
    echo "Using specified validate modules:" $VALIDATE_MODULES
fi

if [ -z $WORKSPACE ];
then
    echo "Out-of-jenkins build"
    if [ -d $PWD/gstreamer ];
    then
	echo "Using current directory as workspace"
    else
	echo "This script must be run from the directory containing the various modules to build"
	exit
    fi
    WORKSPACE=$PWD
    BUILD_TAG="local"
else
    echo "Jenkins build"
fi
echo

# Create an output directory for all results
#
# output/
#   prefix/      # symbolic link to $BUILD_TAG/prefix (if flavor full)
#   $BUILD_TAG/
#      logs/     # Where logs from the various steps are stored
#      prefix/   # Install prefix (if flavor:full)
#      registry.dat  # Llocation of the registry (if flavor full)

OUTPUTDIR=$WORKSPACE/output/$BUILD_TAG

LOGDIR=$OUTPUTDIR/logs
mkdir -p $LOGDIR

echo
echo "======================================================"
echo
echo "Modules scheduled to be built:"
echo "  $CORE $MODULES"
echo
echo "Modules scheduled to be checked (make check):"
echo "  $CHECK_MODULES"
echo

if test "x$FLAVOR" == "xfull"; then
    echo "Modules scheduled to be checked for leaks (make check-valgrind):"
    echo "  $VALGRIND_MODULES"
    echo

    # # prefix directory
    # INSTALLPREFIX=$WORKSPACE/output/prefix

    # mkdir -p $OUTPUTDIR/prefix
    # ln -sf $OUTPUTDIR/prefix $INSTALLPREFIX

    # # setup the various env variables
    # export PATH="$INSTALLPREFIX/bin":$PATH
    # export LD_LIBRARY_PATH="$INSTALLPREFIX/lib":$LD_LIBRARY_PATH
    # export DYLD_LIBRARY_PATH="$INSTALLPREFIX/lib":$DYLD_LIBRARY_PATH
    # export GI_TYPELIB_PATH="$INSTALLPREFIX/share/gir-1.0":$GI_TYPELIB_PATH
    # export PKG_CONFIG_PATH="$INSTALLPREFIX/lib/pkgconfig/":$PKG_CONFIG_PATH
    # export GST_REGISTRY="$INSTALLPREFIX/gstreamer-registry.dat"

    # Checks are disabled for full variants
    export GST_CHECKS="nothing-at-all-go-away-die-die"
fi

echo "======================================================"
echo
echo "Grabbing Environment variables  => output/$BUILD_TAG/env.log"
echo

env > $LOGDIR/env.log 2>&1

echo

# build the specified module
build()
{
    if test -d $WORKSPACE/$1; then
	echo "Building $1"

	cd $WORKSPACE/$1

	# If needed, re-run autogen
	if test ! -e Makefile
	then
	    if test -e autoregen.sh
	    then
		echo "+ $1: autoregen.sh"
		logname=$LOGDIR/$1-autoregen.log
		./autoregen.sh > $logname 2>&1
		if test $? -ne 0
		then
		    echo "AUTOREGEN FAILURE"
		    cat $logname
		    exit $ERROR_RETURN
		fi
	    else
		echo "+ $1: autogen.sh"
		logname=$LOGDIR/$1-autogen.log
		# Fast variant => no docs
		# Full variant => introspection and docs
		case "$FLAVOR" in
		    fast*)
			AGARGS="--disable-gtk-doc --disable-docbook --enable-introspection";;
		    validate)
			AGARGS="--disable-gtk-doc --disable-docbook --enable-introspection --disable-examples --disable-tests --disable-check";;
		    nodebug)
			AGARGS="--disable-gst-debug --disable-gtk-doc --disable-docbook --enable-introspection";;
		    full)
			AGARGS="--enable-gtk-doc --enable-docbook --enable-introspection";;
		    *)
			AGARGS="";;
		esac
		./autogen.sh $AGARGS > $logname 2>&1

		if test $? -ne 0
		then
		    echo "AUTOGEN FAILURE"
		    cat $logname
		    exit $ERROR_RETURN
		fi
	    fi
	else
	    echo "+ $1: git submodule update"
	    git submodule update 2>&1 > /dev/null
	fi

	echo "+ $1 : make"

	logname=$LOGDIR/$1-make.log
	make V=1 > $logname 2>&1
	if test $? -ne 0
	then
	    echo "MAKE FAILURE"
	    cat $logname
	    exit $ERROR_RETURN
	fi

	case "$FLAVOR" in
	    validate)
		echo "+ $1 : Skipping build-checks";;
	    *)
		if test $1 != "orc" -a $1 != "gst-devtools/validate" -a $1 != "gst-python"
		then
		    echo "+ $1 : make build-checks"
		    logname=$LOGDIR/$1-build-checks.log
		    make build-checks V=1 > $logname 2>&1
		    if test $? -ne 0
		    then
			echo "MAKE BUILD-CHECKS FAILURE"
			cat $logname
			exit $ERROR_RETURN
		    fi
		fi
	esac

	# if test "x$FLAVOR" == "xfull"; then
	#     echo "+ $1 : make install"
	#     logname=$LOGDIR/$1-make-install.log
	#     make install V=1 > $logname 2>&1
	#     if test $? -ne 0
	#     then
	# 	echo "MAKE INSTALL FAILURE"
	# 	cat $logname
	# 	exit $ERROR_RETURN
	#     fi
	# fi

	echo "+ $1 : make clean-cruft"
	make clean-cruft > /dev/null 2>&1
    fi
}

make_distcheck()
{
    if test -d $WORKSPACE/$1; then
	cd $WORKSPACE/$1

	echo "+ $1 : make distcheck"
	logname=$LOGDIR/$1-make-distcheck.log
	GST_CHECKS=none make distcheck V=1 > $logname 2>&1
	
	if test $? -ne 0
	then
	    echo "MAKE DISTCHECK FAILURE"
	    cat $logname
	    exit $ERROR_RETURN
	fi
    fi
}

make_check()
{
    if test -d $WORKSPACE/$1; then
	cd $WORKSPACE/$1

	echo "+ $1 : make check"
	logname=$LOGDIR/$1-make-check.log
	# remove pending xml check files
	rm -f tests/check/*/*.xml

	GST_CHECK_XML=1 make check V=1 > $logname 2>&1

	if test $? -ne 0
	then
	    echo "+ $1 : MAKE CHECK FAILURE"
	    cat $logname
	    # We don't want to error out except for gst-python
	    if test $1 == "gst-python"
	       then
		   exit $ERROR_RETURN
	    fi
	fi
    fi
}

valgrind()
{
    if test -d $WORKSPACE/$1; then
	cd $WORKSPACE/$1

	echo "+ $1 : make check-valgrind"
	logname=$LOGDIR/$1-make-check-valgrind.log
	make check-valgrind V=1 > $logname 2>&1

	if test $? -ne 0
	then
	    echo "MAKE CHECK-valgrind FAILURE"
	    cat $logname
	    exit $ERROR_RETURN
	fi
    fi
}

beach()
{
    echo "======================================================"
    echo
    echo "Checking available elements"
    echo

    gst-inspect-1.0 | tail -n1

    echo
    echo "Checking blacklisted elements"

    gst-inspect-1.0 -b

    if test "x$FLAVOR" == "xvalidate"; then
	echo
	echo "======================================================"
	echo
	mkdir -p $LOGDIR/gst-devtools
	build "gst-devtools/validate"
	cd $WORKSPACE
	build "gst-editing-services"
	cd $WORKSPACE
	mkdir -p "validate-output"
	gst-validate-launcher $VALIDATE_MODULES --shuffle -fs -m -n --fail-on-testlist-change -M $WORKSPACE/validate-output --xunit-file $WORKSPACE/xunit.xml --http-server-port $VALIDATE_HTTP_PORT
    fi

    echo
    echo "======================================================"
    echo
    echo "Cleaning up build directories"

    # ccache will have cached all non-changed compilation, we can safely make clean
    repo forall -c make clean > /dev/null 2>&1

    # if test "x$FLAVOR" == "xfull"; then
    # 	echo
    # 	echo "======================================================"
    # 	echo
    # 	echo "Compressing/storing output prefix"
    # 	cd $OUTPUTDIR
    # 	tar cvJf $BUILD_TAG.tar.xz prefix > /dev/null
    # 	ls -lah $BUILD_TAG.tar.xz
    # 	rm -Rf prefix
    # 	echo
    # 	echo "======================================================"
    # 	rm $INSTALLPREFIX
    # fi

    echo "Update done"
    exit
}


# build selected modules
for m in $CORE $MODULES; do
    case "$FLAVOR" in
	check)
	;;
	*)
	    build $m
	    ;;
    esac
done

# make check (for those activated)
for m in $CHECK_MODULES; do
    case "$FLAVOR" in
	full)
	    make_distcheck $m
	    ;;
	fast-build-only)
	    ;;
	*)
	    make_check $m
	    ;;
    esac
done

# make valgrind (for those activated)
for m in $VALGRIND_MODULES; do
    cd $WORKSPACE/$m
done

case "$FLAVOR" in
    fast-build-only)
	echo "Not cleaning up"
	;;
    *)
	beach
	;;
esac