diff options
-rw-r--r-- | .travis.yml | 58 | ||||
-rwxr-xr-x | build.sh | 131 | ||||
-rwxr-xr-x | build_matrix.sh | 105 |
3 files changed, 238 insertions, 56 deletions
diff --git a/.travis.yml b/.travis.yml index c4cf2117..1b55b899 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,6 @@ os: dist: focal -compiler: - - gcc - - clang - # # Linux runs on all of the architectures listed above; macOS runs on # 64-bit x86 and 64-bit ARM, but Travis doesn't currently have a 64-bit @@ -88,22 +84,6 @@ env: # usual processing: false. - coverity_scan_script_test_mode=false - MAKEFLAGS='-j 2' # Travis CI VMs come with 2 cores - matrix: - # NOTE: REMOTE= is for the libpcap build, which is done with autotools - # even if we're building tcpdump with CMake. - # It's irrelevant if we're building tcpdump with the system libpcap. - - BUILD_LIBPCAP=no CMAKE=no CRYPTO=no - - BUILD_LIBPCAP=no CMAKE=no CRYPTO=yes - - BUILD_LIBPCAP=no CMAKE=yes CRYPTO=no - - BUILD_LIBPCAP=no CMAKE=yes CRYPTO=yes - - BUILD_LIBPCAP=yes CMAKE=no REMOTE=disable CRYPTO=no - - BUILD_LIBPCAP=yes CMAKE=no REMOTE=disable CRYPTO=yes - - BUILD_LIBPCAP=yes CMAKE=no REMOTE=enable CRYPTO=no - - BUILD_LIBPCAP=yes CMAKE=no REMOTE=enable CRYPTO=yes - - BUILD_LIBPCAP=yes CMAKE=yes REMOTE=disable CRYPTO=no - - BUILD_LIBPCAP=yes CMAKE=yes REMOTE=disable CRYPTO=yes - - BUILD_LIBPCAP=yes CMAKE=yes REMOTE=enable CRYPTO=no - - BUILD_LIBPCAP=yes CMAKE=yes REMOTE=enable CRYPTO=yes addons: coverity_scan: @@ -149,46 +129,12 @@ install: - if [ "$TRAVIS_OS_NAME" = osx ]; then brew install libsmi | grep -v '%'; fi before_script: - - if [ "$BUILD_LIBPCAP" = yes ]; then (cd .. && echo '$ git clone [...] libpcap.git' && git clone --depth 3 --branch=master --quiet git://github.com/the-tcpdump-group/libpcap.git && cd libpcap && ./configure "--${REMOTE}-remote" --prefix=/tmp && make && make install); fi + - (cd .. && echo '$ git clone [...] libpcap.git' && git clone --depth 3 --branch=master --quiet git://github.com/the-tcpdump-group/libpcap.git) script: # On the other hand, using travis_terminate on macOS appears to # *cause* the problem, so we do so only on Linux. # - if [ "$COVERITY_SCAN_BRANCH" = 1 ]; then if [ "$TRAVIS_OS_NAME" = linux ]; then travis_terminate 0; else exit 0; fi; fi - - if [ "$TRAVIS_OS_NAME" = osx ]; then OSX_SSL_DIR=$(ls /usr/local/Cellar/openssl); echo "OSX_SSL_DIR=$OSX_SSL_DIR"; fi - - touch .devel configure - - if [ "$CMAKE" = no ]; then echo '$ ./configure [...]' && echo travis_fold:start:script.configure; fi - - if [ "$CMAKE" = no ]; then PKG_CONFIG_PATH=/tmp/lib/pkgconfig ./configure --with-crypto=${CRYPTO} CPPFLAGS="-I/usr/local/Cellar/openssl/$OSX_SSL_DIR/include/" --prefix=/tmp; fi - - if [ "$CMAKE" = no ]; then echo -n travis_fold:end:script.configure; fi - - if [ "$CMAKE" = yes ]; then mkdir build; fi - - if [ "$CMAKE" = yes ]; then cd build; fi - - if [ "$CMAKE" = yes ]; then echo '$ cmake [...]' && echo travis_fold:start:script.cmake; fi - - if [ "$CMAKE" = yes ]; then cmake -DWITH_CRYPTO="$CRYPTO" -DCMAKE_PREFIX_PATH=/tmp -DCMAKE_INSTALL_PREFIX=/tmp ..; fi - - if [ "$CMAKE" = yes ]; then echo -n travis_fold:end:script.cmake; fi - - make -s CFLAGS=-Werror - - echo '$ make install [...]' && echo travis_fold:start:script.make_install - - PATH=$PATH make install - - echo -n travis_fold:end:script.make_install - - if [ "$TRAVIS_OS_NAME" = linux ]; then echo '$ ldd tcpdump' && echo travis_fold:start:script.ldd_tcpdump; fi - - if [ "$TRAVIS_OS_NAME" = linux ]; then ldd tcpdump; fi - - if [ "$TRAVIS_OS_NAME" = linux ]; then echo -n travis_fold:end:script.ldd_tcpdump; fi - - if [ "$BUILD_LIBPCAP" = yes ]; then make check; fi - - ./tcpdump --version - - ./tcpdump -h - - ./tcpdump -D - - sudo ./tcpdump -J - - sudo ./tcpdump -L - - if [ "$TRAVIS_OS_NAME" = linux -a "$TRAVIS_CPU_ARCH" != ppc64le -a "$TRAVIS_CPU_ARCH" != s390x -a "$TRAVIS_CPU_ARCH" != arm64 ]; then sudo ./tcpdump -#n -c 10; fi - - if [ "$CMAKE" = no ]; then make releasetar; fi - - echo '$ cat Makefile [...]'; echo travis_fold:start:script.cat_makefile - - if [ "$CMAKE" = no ]; then cat Makefile | sed -n '1,/DO NOT DELETE THIS LINE -- mkdep uses it/p'; fi - - if [ "$CMAKE" = yes ]; then cat Makefile; fi - - echo -n travis_fold:end:script.cat_makefile - - echo '$ cat config.h'; echo travis_fold:start:script.cat_config_h - - cat config.h - - echo -n travis_fold:end:script.cat_config_h - - if [ "$CMAKE" = no ]; then echo '$ cat config.log'; echo travis_fold:start:script.cat_config_log; fi - - if [ "$CMAKE" = no ]; then cat config.log; fi - - if [ "$CMAKE" = no ]; then echo -n travis_fold:end:script.cat_config_log; fi + - ./build_matrix.sh - if [ "$TRAVIS_OS_NAME" = osx ]; then sleep 10; fi diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..083559aa --- /dev/null +++ b/build.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash + +# This script runs one build with setup environment variables: BUILD_LIBPCAP, +# REMOTE, CC, CMAKE, CRYPTO and SMB +# (default: BUILD_LIBPCAP=no, REMOTE=no, CC=gcc, CMAKE=no, CRYPTO=no, SMB=no). + +set -e + +# BUILD_LIBPCAP: no or yes +BUILD_LIBPCAP=${BUILD_LIBPCAP:-no} +# REMOTE: no or yes +REMOTE=${REMOTE:-no} +# CC: gcc or clang +CC=${CC:-gcc} +# CMAKE: no or yes +CMAKE=${CMAKE:-no} +# CRYPTO: no or yes +CRYPTO=${CRYPTO:-no} +# SMB: no or yes +SMB=${SMB:-no} +# Install directory prefix +PREFIX=/tmp/local +# For TESTrun +export TCPDUMP_BIN=/tmp/local/bin/tcpdump + +travis_fold() { + local action="$1" + local name="$2" + if [ "$TRAVIS" != true ]; then return; fi + echo -ne "travis_fold:$action:$LABEL.script.$name\\r" + sleep 1 +} + +# Run a command after displaying it +run_after_echo() { + echo -n '$ ' + echo "$@" + $@ +} + +# LABEL is needed to build the travis fold labels +LABEL="$BUILD_LIBPCAP.$REMOTE.$CC.$CMAKE.$CRYPTO.$SMB" +if [ "$CMAKE" = no ]; then + echo '$ ./configure [...]' + travis_fold start configure + if [ "$BUILD_LIBPCAP" = yes ]; then + echo "Using PKG_CONFIG_PATH=$PKG_CONFIG_PATH" + ./configure --with-crypto="$CRYPTO" --enable-smb="$SMB" --prefix=$PREFIX + export LD_LIBRARY_PATH=$PREFIX/lib + else + ./configure --disable-local-libpcap --with-crypto="$CRYPTO" --enable-smb="$SMB" --prefix=$PREFIX + fi + travis_fold end configure +else + rm -rf build + mkdir build + cd build + echo '$ cmake [...]' + travis_fold start cmake + if [ "$BUILD_LIBPCAP" = yes ]; then + cmake -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$PREFIX .. + export LD_LIBRARY_PATH=$PREFIX/lib + else + cmake -DWITH_CRYPTO="$CRYPTO" -DENABLE_SMB="$SMB" -DCMAKE_INSTALL_PREFIX=$PREFIX .. + fi + travis_fold end cmake +fi +run_after_echo "make -s clean" +run_after_echo "make -s CFLAGS=-Werror" +echo '$ make install' +travis_fold start make_install +make install +travis_fold end make_install +run_after_echo "$TCPDUMP_BIN --version" +run_after_echo "$TCPDUMP_BIN -h" +run_after_echo "$TCPDUMP_BIN -D" +system=$(uname -s) +if [ "$system" = Linux ]; then + run_after_echo "ldd $TCPDUMP_BIN" +fi +if [ "$TRAVIS" = true ]; then + if [ -n "$LD_LIBRARY_PATH" ]; then + run_after_echo "sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $TCPDUMP_BIN -J" + run_after_echo "sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $TCPDUMP_BIN -L" + else + run_after_echo "sudo $TCPDUMP_BIN -J" + run_after_echo "sudo $TCPDUMP_BIN -L" + fi +fi +if [ "$BUILD_LIBPCAP" = yes ]; then + run_after_echo "make check" +fi +if [ "$CMAKE" = no ]; then + system=$(uname -s) + if [ "$system" = Darwin ] || [ "$system" = Linux ]; then + run_after_echo "make releasetar" + fi +fi +if [ "$TRAVIS" = true ]; then + if [ "$TRAVIS_OS_NAME" = linux ] && [ "$TRAVIS_CPU_ARCH" != ppc64le ] && [ "$TRAVIS_CPU_ARCH" != s390x ] && [ "$TRAVIS_CPU_ARCH" != arm64 ]; then + if [ -n "$LD_LIBRARY_PATH" ]; then + run_after_echo "sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH $TCPDUMP_BIN -#n -c 10" + else + run_after_echo "sudo $TCPDUMP_BIN -#n -c 10" + fi + fi +fi +# The DEBUG_BUILD variable is not set by default to avoid Travis error message: +# "The job exceeded the maximum log length, and has been terminated." +# Setting it needs to reduce the matrix cases. +if [ "$TRAVIS" = true ] && [ -n "$DEBUG_BUILD" ] ; then + echo '$ cat Makefile [...]' + travis_fold start cat_makefile + if [ "$CMAKE" = no ]; then + sed -n '1,/DO NOT DELETE THIS LINE -- mkdep uses it/p' < Makefile + else + cat Makefile + fi + travis_fold end cat_makefile + echo '$ cat config.h' + travis_fold start cat_config_h + cat config.h + travis_fold end cat_config_h + if [ "$CMAKE" = no ]; then + echo '$ cat config.log' + travis_fold start cat_config_log + cat config.log + travis_fold end cat_config_log + fi +fi +# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent : diff --git a/build_matrix.sh b/build_matrix.sh new file mode 100755 index 00000000..c996b863 --- /dev/null +++ b/build_matrix.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash + +# This script executes the matrix loops, exclude tests and cleaning. +# It calls the build.sh script which runs one build with setup environment +# variables: BUILD_LIBPCAP, REMOTE, CC, CMAKE, CRYPTO and SMB +# (default: BUILD_LIBPCAP=no, REMOTE=no, CC=gcc, CMAKE=no, CRYPTO=no, SMB=no). +# The matrix can be configured with environment variables +# MATRIX_BUILD_LIBPCAP, MATRIX_REMOTE, MATRIX_CC, MATRIX_CMAKE, MATRIX_CRYPTO +# and MATRIX_SMB +# (default: MATRIX_BUILD_LIBPCAP='no yes', MATRIX_REMOTE='no yes', +# MATRIX_CC='gcc clang', MATRIX_CMAKE='no yes', MATRIX_CRYPTO='no yes', +# MATRIX_SMB='no yes'). + +set -e + +# ANSI color escape sequences +ANSI_MAGENTA="\\033[35;1m" +ANSI_RESET="\\033[0m" +# Install directory prefix +PREFIX=/tmp/local +COUNT=0 + +travis_fold() { + local action="$1" + local name="$2" + if [ "$TRAVIS" != true ]; then return; fi + echo -ne "travis_fold:$action:$LABEL.script.$name\\r" + sleep 1 +} + +# Display text in magenta +echo_magenta() { + echo -ne "$ANSI_MAGENTA" + echo "$@" + echo -ne "$ANSI_RESET" +} + +build_tcpdump() { + for CC in ${MATRIX_CC:-gcc clang}; do + export CC + # Exclude gcc on OSX (it is just an alias for clang) + if [ "$CC" = gcc ] && [ "$TRAVIS_OS_NAME" = osx ]; then continue; fi + for CMAKE in ${MATRIX_CMAKE:-no yes}; do + export CMAKE + for CRYPTO in ${MATRIX_CRYPTO:-no yes}; do + export CRYPTO + for SMB in ${MATRIX_SMB:-no yes}; do + export SMB + COUNT=$((COUNT+1)) + echo_magenta "===== SETUP $COUNT: build_libpcap=$BUILD_LIBPCAP remote:${REMOTE:-?} compiler:$CC cmake:$CMAKE crypto=$CRYPTO smb=$SMB =====" + # LABEL is needed to build the travis fold labels + LABEL="$BUILD_LIBPCAP.$REMOTE.$CC.$CMAKE.$CRYPTO.$SMB" + # Run one build with setup environment variables: + # BUILD_LIBPCAP, REMOTE, CC, CMAKE, CRYPTO and SMB + ./build.sh + echo 'Cleaning...' + travis_fold start cleaning + if [ "$CMAKE" = yes ]; then rm -rf build; else make distclean; fi + rm -rf $PREFIX/bin/tcpdump* + git status -suall + # Cancel changes in configure + git checkout configure + travis_fold end cleaning + done + done + done + done +} + +choose_libpcap() { + if [ "$BUILD_LIBPCAP" = no ]; then + echo_magenta 'Use system libpcap' + rm -rf /tmp/local + else + # Build libpcap with autoconf + CMAKE_SAVE=$CMAKE + CMAKE=no + echo_magenta "Build libpcap (cmake:$CMAKE remote:$REMOTE)" + (cd ../libpcap && ./build.sh && make distclean) + CMAKE=$CMAKE_SAVE + fi +} + +touch .devel configure +for BUILD_LIBPCAP in ${MATRIX_BUILD_LIBPCAP:-no yes}; do +export BUILD_LIBPCAP + if [ "$BUILD_LIBPCAP" = yes ]; then + for REMOTE in ${MATRIX_REMOTE:-no yes}; do + export REMOTE + choose_libpcap + # Set PKG_CONFIG_PATH for configure when building libpcap + if [ "$CMAKE" != no ]; then + export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig + fi + build_tcpdump + done + else + choose_libpcap + build_tcpdump + fi +done + +rm -rf $PREFIX +echo_magenta "Tested setup count: $COUNT" +# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent : |