devtools: add acronyms in dictionary for commit checks
[dpdk.git] / devtools / test-meson-builds.sh
1 #! /bin/sh -e
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2018 Intel Corporation
4
5 # Run meson to auto-configure the various builds.
6 # * all builds get put in a directory whose name starts with "build-"
7 # * if a build-directory already exists we assume it was properly configured
8 # Run ninja after configuration is done.
9
10 # set pipefail option if possible
11 PIPEFAIL=""
12 set -o | grep -q pipefail && set -o pipefail && PIPEFAIL=1
13
14 srcdir=$(dirname $(readlink -f $0))/..
15 . $srcdir/devtools/load-devel-config
16
17 MESON=${MESON:-meson}
18 use_shared="--default-library=shared"
19 builds_dir=${DPDK_BUILD_TEST_DIR:-.}
20
21 if command -v gmake >/dev/null 2>&1 ; then
22         MAKE=gmake
23 else
24         MAKE=make
25 fi
26 if command -v ninja >/dev/null 2>&1 ; then
27         ninja_cmd=ninja
28 elif command -v ninja-build >/dev/null 2>&1 ; then
29         ninja_cmd=ninja-build
30 else
31         echo "ERROR: ninja is not found" >&2
32         exit 1
33 fi
34 if command -v ccache >/dev/null 2>&1 ; then
35         CCACHE=ccache
36 else
37         CCACHE=
38 fi
39
40 default_path=$PATH
41 default_pkgpath=$PKG_CONFIG_PATH
42 default_cppflags=$CPPFLAGS
43 default_cflags=$CFLAGS
44 default_ldflags=$LDFLAGS
45
46 load_env () # <target compiler>
47 {
48         targetcc=$1
49         export PATH=$default_path
50         export PKG_CONFIG_PATH=$default_pkgpath
51         export CPPFLAGS=$default_cppflags
52         export CFLAGS=$default_cflags
53         export LDFLAGS=$default_ldflags
54         unset DPDK_MESON_OPTIONS
55         command -v $targetcc >/dev/null 2>&1 || return 1
56         DPDK_TARGET=$($targetcc -v 2>&1 | sed -n 's,^Target: ,,p')
57         . $srcdir/devtools/load-devel-config
58 }
59
60 config () # <dir> <builddir> <meson options>
61 {
62         dir=$1
63         shift
64         builddir=$1
65         shift
66         if [ -f "$builddir/build.ninja" ] ; then
67                 # for existing environments, switch to debugoptimized if unset
68                 # so that ABI checks can run
69                 if ! $MESON configure $builddir |
70                                 awk '$1=="buildtype" {print $2}' |
71                                 grep -qw debugoptimized; then
72                         $MESON configure --buildtype=debugoptimized $builddir
73                 fi
74                 return
75         fi
76         options=
77         if echo $* | grep -qw -- '--default-library=shared' ; then
78                 options="$options -Dexamples=all"
79         else
80                 options="$options -Dexamples=l3fwd" # save disk space
81         fi
82         options="$options --buildtype=debugoptimized"
83         for option in $DPDK_MESON_OPTIONS ; do
84                 options="$options -D$option"
85         done
86         options="$options $*"
87         echo "$MESON $options $dir $builddir"
88         $MESON $options $dir $builddir
89 }
90
91 compile () # <builddir>
92 {
93         builddir=$1
94         if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then
95                 # for full output from ninja use "-v"
96                 echo "$ninja_cmd -v -C $builddir"
97                 $ninja_cmd -v -C $builddir
98         elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
99                 # for keeping the history of short cmds, pipe through cat
100                 echo "$ninja_cmd -C $builddir | cat"
101                 $ninja_cmd -C $builddir | cat
102         else
103                 echo "$ninja_cmd -C $builddir"
104                 $ninja_cmd -C $builddir
105         fi
106 }
107
108 install_target () # <builddir> <installdir>
109 {
110         rm -rf $2
111         if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE$TEST_MESON_BUILD_VERBOSE" ]; then
112                 echo "DESTDIR=$2 $ninja_cmd -C $1 install"
113                 DESTDIR=$2 $ninja_cmd -C $1 install
114         else
115                 echo "DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null"
116                 DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null
117         fi
118 }
119
120 build () # <directory> <target compiler> <meson options>
121 {
122         targetdir=$1
123         shift
124         targetcc=$1
125         shift
126         # skip build if compiler not available
127         command -v ${CC##* } >/dev/null 2>&1 || return 0
128         load_env $targetcc || return 0
129         config $srcdir $builds_dir/$targetdir --werror $*
130         compile $builds_dir/$targetdir
131         if [ -n "$DPDK_ABI_REF_VERSION" ]; then
132                 abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION
133                 if [ ! -d $abirefdir/$targetdir ]; then
134                         # clone current sources
135                         if [ ! -d $abirefdir/src ]; then
136                                 git clone --local --no-hardlinks \
137                                         --single-branch \
138                                         -b $DPDK_ABI_REF_VERSION \
139                                         $srcdir $abirefdir/src
140                         fi
141
142                         rm -rf $abirefdir/build
143                         config $abirefdir/src $abirefdir/build $*
144                         compile $abirefdir/build
145                         install_target $abirefdir/build $abirefdir/$targetdir
146                         $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir
147                 fi
148
149                 install_target $builds_dir/$targetdir \
150                         $(readlink -f $builds_dir/$targetdir/install)
151                 $srcdir/devtools/gen-abi.sh \
152                         $(readlink -f $builds_dir/$targetdir/install)
153                 $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
154                         $(readlink -f $builds_dir/$targetdir/install)
155         fi
156 }
157
158 if [ "$1" = "-vv" ] ; then
159         TEST_MESON_BUILD_VERY_VERBOSE=1
160 elif [ "$1" = "-v" ] ; then
161         TEST_MESON_BUILD_VERBOSE=1
162 fi
163 # we can't use plain verbose when we don't have pipefail option so up-level
164 if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
165         echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
166         TEST_MESON_BUILD_VERY_VERBOSE=1
167 fi
168
169 # shared and static linked builds with gcc and clang
170 for c in gcc clang ; do
171         command -v $c >/dev/null 2>&1 || continue
172         for s in static shared ; do
173                 export CC="$CCACHE $c"
174                 build build-$c-$s $c --default-library=$s
175                 unset CC
176         done
177 done
178
179 # test compilation with minimal x86 instruction set
180 # Set the install path for libraries to "lib" explicitly to prevent problems
181 # with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later.
182 default_machine='nehalem'
183 ok=$(cc -march=$default_machine -E - < /dev/null > /dev/null 2>&1 || echo false)
184 if [ "$ok" = "false" ] ; then
185         default_machine='corei7'
186 fi
187 build build-x86-default cc -Dlibdir=lib -Dmachine=$default_machine $use_shared
188
189 c=aarch64-linux-gnu-gcc
190 # generic armv8a with clang as host compiler
191 export CC="clang"
192 build build-arm64-host-clang $c $use_shared \
193         --cross-file $srcdir/config/arm/arm64_armv8_linux_gcc
194 unset CC
195 # all gcc/arm configurations
196 for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do
197         export CC="$CCACHE gcc"
198         build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) $c \
199                 $use_shared --cross-file $f
200         unset CC
201 done
202
203 # Test installation of the x86-default target, to be used for checking
204 # the sample apps build using the pkg-config file for cflags and libs
205 build_path=$(readlink -f $builds_dir/build-x86-default)
206 export DESTDIR=$build_path/install
207 # No need to reinstall if ABI checks are enabled
208 if [ -z "$DPDK_ABI_REF_VERSION" ]; then
209         install_target $build_path $DESTDIR
210 fi
211
212 load_env cc
213 pc_file=$(find $DESTDIR -name libdpdk.pc)
214 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
215
216 # if pkg-config defines the necessary flags, test building some examples
217 if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then
218         export PKGCONF="pkg-config --define-prefix"
219         for example in cmdline helloworld l2fwd l3fwd skeleton timer; do
220                 echo "## Building $example"
221                 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example clean all
222         done
223 fi