summaryrefslogtreecommitdiff
path: root/ci-build.sh
blob: 945cdfb43ef9d70a50c836d61d03fe07b4e294aa (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
#!/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"
	;;
    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 "  nodebug : Same as fast but with GST_DEBUG disabled"
	echo "  full    : doc/introspection build + distcheck + valgrind"
	exit 42
	;;
esac

# modules to be built (if present)
CORE="orc gstreamer gst-plugins-base "
MODULES="gst-plugins-good gst-plugins-ugly gst-plugins-bad gst-libav gst-rtsp-server gnonlin gst-editing-services"
EXTRA_MODULES="gst-python"

# modules for which we run make check/distcheck
CHECK_MODULES="orc gstreamer gst-plugins-base gst-plugins-ugly gst-libav gst-rtsp-server"
VALGRIND_MODULES=""

ERROR_RETURN=255

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

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"
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 instrospection, no docs
		# Full variant => introspection and docs
		case "$FLAVOR" in
		    fast)
			AGARGS="--disable-gtk-doc --disable-docbook --disable-introspection";;
		    nodebug)
			AGARGS="--disable-gst-debug --disable-gtk-doc --disable-docbook --disable-introspection";;
		    full)
			AGARGS="--prefix=$INSTALLPREFIX --enable-gtk-doc --enable-docbook --enable-introspection";;
		    *)
			AGARGS="";;
		esac
		./autogen.sh --cache-file=$INSTALLPREFIX/config.cache $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

	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_check()
{
    if test -d $WORKSPACE/$1; then
	cd $WORKSPACE/$1

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

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

	if test "x$FLAVOR" == "xfull"; then
	    if test "x$1" != "xgst-libav"; then
		echo "+ $1 : make distcheck"
		logname=$LOGDIR/$1-make-distcheck.log
		make distcheck V=1 > $logname 2>&1

		if test $? -ne 0
		then
		    echo "MAKE DISTCHECK FAILURE"
		    cat $logname
		    exit $ERROR_RETURN
		fi
	    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

    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
    build $m
done

# make check (for those activated)
for m in $CHECK_MODULES; do
    make_check $m
done

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

beach