travis: Enable -Wsparse-error and fail on new sparse warnings
[cascardo/ovs.git] / .travis / build.sh
1 #!/bin/bash
2
3 set -o errexit
4
5 KERNELSRC=""
6 CFLAGS="-Werror"
7
8 function install_kernel()
9 {
10     wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.16.2.tar.gz
11     tar xzvf linux-3.16.2.tar.gz > /dev/null
12     cd linux-3.16.2
13     make allmodconfig
14     make net/openvswitch/
15     KERNELSRC=$(pwd)
16     echo "Installed kernel source in $(pwd)"
17     cd ..
18 }
19
20 function install_dpdk()
21 {
22     wget http://www.dpdk.org/browse/dpdk/snapshot/dpdk-1.7.1.tar.gz
23     tar xzvf dpdk-1.7.1.tar.gz > /dev/null
24     cd dpdk-1.7.1
25     find ./ -type f | xargs sed -i 's/max-inline-insns-single=100/max-inline-insns-single=400/'
26     sed -ri 's,(CONFIG_RTE_BUILD_COMBINE_LIBS=).*,\1y,' config/common_linuxapp
27     make config CC=gcc T=x86_64-native-linuxapp-gcc
28     make CC=gcc RTE_KERNELDIR=$KERNELSRC
29     echo "Installed DPDK source in $(pwd)"
30     cd ..
31 }
32
33 function configure_ovs()
34 {
35     ./boot.sh && ./configure $*
36 }
37
38 if [ "$KERNEL" ] || [ "$DPDK" ]; then
39     install_kernel
40 fi
41
42 if [ "$DPDK" ]; then
43     install_dpdk
44     # Disregard bad function cassts until DPDK is fixed
45     CFLAGS="$CFLAGS -Wno-error=bad-function-cast -Wno-error=cast-align"
46 elif [ $CC != "clang" ]; then
47     # DPDK headers currently trigger sparse errors
48     CFLAGS="$CFLAGS -Wsparse-error"
49 fi
50
51 configure_ovs $*
52
53
54 if [ $CC = "clang" ]; then
55     make CFLAGS="$CFLAGS -Wno-error=unused-command-line-argument"
56 else
57     make CFLAGS="$CFLAGS" C=1
58 fi
59
60 if [ $TESTSUITE ]; then
61     if ! make distcheck; then
62         # testsuite.log is necessary for debugging.
63         cat */_build/tests/testsuite.log
64         exit 1
65     fi
66 fi
67
68 exit 0