774a1441bf2b94aae6d2a4549c4282a7c8089f5e
[dpdk.git] / .ci / linux-build.sh
1 #!/bin/sh -xe
2
3 # Builds are run as root in containers, no need for sudo
4 [ "$(id -u)" != '0' ] || alias sudo=
5
6 on_error() {
7     if [ $? = 0 ]; then
8         exit
9     fi
10     FILES_TO_PRINT="build/meson-logs/testlog.txt"
11     FILES_TO_PRINT="$FILES_TO_PRINT build/.ninja_log"
12     FILES_TO_PRINT="$FILES_TO_PRINT build/meson-logs/meson-log.txt"
13     FILES_TO_PRINT="$FILES_TO_PRINT build/gdb.log"
14
15     for pr_file in $FILES_TO_PRINT; do
16         if [ -e "$pr_file" ]; then
17             cat "$pr_file"
18         fi
19     done
20 }
21 # We capture the error logs as artifacts in Github Actions, no need to dump
22 # them via a EXIT handler.
23 [ -n "$GITHUB_WORKFLOW" ] || trap on_error EXIT
24
25 install_libabigail() {
26     version=$1
27     instdir=$2
28
29     wget -q "http://mirrors.kernel.org/sourceware/libabigail/${version}.tar.gz"
30     tar -xf ${version}.tar.gz
31     cd $version && autoreconf -vfi && cd -
32     mkdir $version/build
33     cd $version/build && ../configure --prefix=$instdir && cd -
34     make -C $version/build all install
35     rm -rf $version
36     rm ${version}.tar.gz
37 }
38
39 configure_coredump() {
40     # No point in configuring coredump without gdb
41     which gdb >/dev/null || return 0
42     ulimit -c unlimited
43     sudo sysctl -w kernel.core_pattern=/tmp/dpdk-core.%e.%p
44 }
45
46 catch_coredump() {
47     ls /tmp/dpdk-core.*.* 2>/dev/null || return 0
48     for core in /tmp/dpdk-core.*.*; do
49         binary=$(sudo readelf -n $core |grep $(pwd)/build/ 2>/dev/null |head -n1)
50         [ -x $binary ] || binary=
51         sudo gdb $binary -c $core \
52             -ex 'info threads' \
53             -ex 'thread apply all bt full' \
54             -ex 'quit'
55     done |tee -a build/gdb.log
56     return 1
57 }
58
59 if [ "$AARCH64" = "true" ]; then
60     # Note: common/cnxk is disabled for Ubuntu 18.04
61     # https://bugs.dpdk.org/show_bug.cgi?id=697
62     OPTS="$OPTS -Ddisable_drivers=common/cnxk"
63     if [ "${CC%%clang}" != "$CC" ]; then
64         OPTS="$OPTS --cross-file config/arm/arm64_armv8_linux_clang_ubuntu1804"
65     else
66         OPTS="$OPTS --cross-file config/arm/arm64_armv8_linux_gcc"
67     fi
68 fi
69
70 if [ "$PPC64LE" = "true" ]; then
71     OPTS="$OPTS --cross-file config/ppc/ppc64le-power8-linux-gcc-ubuntu1804"
72 fi
73
74 if [ "$BUILD_DOCS" = "true" ]; then
75     OPTS="$OPTS -Denable_docs=true"
76 fi
77
78 if [ "$BUILD_32BIT" = "true" ]; then
79     OPTS="$OPTS -Dc_args=-m32 -Dc_link_args=-m32"
80     OPTS="$OPTS -Dcpp_args=-m32 -Dcpp_link_args=-m32"
81     export PKG_CONFIG_LIBDIR="/usr/lib32/pkgconfig"
82 fi
83
84 if [ "$DEF_LIB" = "static" ]; then
85     OPTS="$OPTS -Dexamples=l2fwd,l3fwd"
86 else
87     OPTS="$OPTS -Dexamples=all"
88 fi
89
90 OPTS="$OPTS -Dplatform=generic"
91 OPTS="$OPTS --default-library=$DEF_LIB"
92 OPTS="$OPTS --buildtype=debugoptimized"
93 OPTS="$OPTS -Dcheck_includes=true"
94 if [ "$MINI" = "true" ]; then
95     OPTS="$OPTS -Denable_drivers=net/null"
96     OPTS="$OPTS -Ddisable_libs=*"
97 fi
98 meson build --werror $OPTS
99 ninja -C build
100
101 if [ "$AARCH64" != "true" ] && [ "$PPC64LE" != "true" ]; then
102     failed=
103     configure_coredump
104     devtools/test-null.sh || failed="true"
105     catch_coredump
106     [ "$failed" != "true" ]
107 fi
108
109 if [ "$ABI_CHECKS" = "true" ]; then
110     if [ "$(cat libabigail/VERSION 2>/dev/null)" != "$LIBABIGAIL_VERSION" ]; then
111         rm -rf libabigail
112         # if we change libabigail, invalidate existing abi cache
113         rm -rf reference
114     fi
115
116     if [ ! -d libabigail ]; then
117         install_libabigail "$LIBABIGAIL_VERSION" $(pwd)/libabigail
118         echo $LIBABIGAIL_VERSION > libabigail/VERSION
119     fi
120
121     export PATH=$(pwd)/libabigail/bin:$PATH
122
123     REF_GIT_REPO=${REF_GIT_REPO:-https://dpdk.org/git/dpdk}
124
125     if [ "$(cat reference/VERSION 2>/dev/null)" != "$REF_GIT_TAG" ]; then
126         rm -rf reference
127     fi
128
129     if [ ! -d reference ]; then
130         refsrcdir=$(readlink -f $(pwd)/../dpdk-$REF_GIT_TAG)
131         git clone --single-branch -b "$REF_GIT_TAG" $REF_GIT_REPO $refsrcdir
132         meson $OPTS -Dexamples= $refsrcdir $refsrcdir/build
133         ninja -C $refsrcdir/build
134         DESTDIR=$(pwd)/reference ninja -C $refsrcdir/build install
135         devtools/gen-abi.sh reference
136         find reference/usr/local -name '*.a' -delete
137         rm -rf reference/usr/local/bin
138         rm -rf reference/usr/local/share
139         echo $REF_GIT_TAG > reference/VERSION
140     fi
141
142     DESTDIR=$(pwd)/install ninja -C build install
143     devtools/gen-abi.sh install
144     devtools/check-abi.sh reference install ${ABI_CHECKS_WARN_ONLY:-}
145 fi
146
147 if [ "$RUN_TESTS" = "true" ]; then
148     failed=
149     configure_coredump
150     sudo meson test -C build --suite fast-tests -t 3 || failed="true"
151     catch_coredump
152     [ "$failed" != "true" ]
153 fi