]> The Tcpdump Group git mirrors - tcpdump/commitdiff
CI: Port recent improvements from tcpslice. [skip appveyor]
authorDenis Ovsienko <[email protected]>
Fri, 30 Jul 2021 08:44:04 +0000 (09:44 +0100)
committerDenis Ovsienko <[email protected]>
Fri, 30 Jul 2021 09:33:35 +0000 (10:33 +0100)
Introduce TCPDUMP_TAINTED, improve OS and compiler identification, print
matrix progress to stderr.

build.sh
build_common.sh
build_matrix.sh

index 87701dd089d8e0c9983df58330733111903bc26e..7d8e2406b574eb01a64451a2b7b833985a11d590 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -9,6 +9,7 @@
 : "${CMAKE:=no}"
 : "${CRYPTO:=no}"
 : "${SMB:=no}"
+: "${TCPDUMP_TAINTED:=no}"
 
 . ./build_common.sh
 # Install directory prefix
@@ -53,11 +54,7 @@ run_after_echo make -s clean
 # these cases, please remember to raise the bar here so if the warnings appear
 # again, it will trigger an error.
 # shellcheck disable=SC2006
-case `uname -s` in
-    *)
-        CFLAGS=`cc_werr_cflags`
-        ;;
-esac
+[ "$TCPDUMP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
 run_after_echo make -s ${CFLAGS:+CFLAGS="$CFLAGS"}
 run_after_echo make install
 print_so_deps "$TCPDUMP_BIN"
index 8ace59e4dddabf766cc5c0cd297080671f234a44..a803957a9da16f1ebc7639fb24f71b808596c618 100644 (file)
@@ -30,26 +30,19 @@ mktempdir_diy() {
 mktempdir() {
     mktempdir_prefix=${1:-tmp}
     # shellcheck disable=SC2006
-    case `uname -s` in
-    Darwin|FreeBSD|NetBSD)
+    case `os_id` in
+    Darwin-*|FreeBSD-*|NetBSD-*)
         # In these operating systems mktemp(1) always appends an implicit
         # ".XXXXXXXX" suffix to the requested template when creating a
         # temporary directory.
         mktemp -d -t "$mktempdir_prefix"
         ;;
-    AIX)
-        mktempdir_diy "$mktempdir_prefix"
+    SunOS-5.10|SunOS-5.11)
+        # Although the suffix is optional, specify it for consistent results.
+        mktemp -d -t "${mktempdir_prefix}.XXXXXXXX"
         ;;
-    SunOS)
-        # shellcheck disable=SC2006
-        case `uname -r` in
-        5.10|5.11)
-            mktemp -d -t "${mktempdir_prefix}.XXXXXXXX"
-            ;;
-        *)
-            mktempdir_diy "$mktempdir_prefix"
-            ;;
-        esac
+    SunOS-*|AIX-*)
+        mktempdir_diy "$mktempdir_prefix"
         ;;
     *)
         # At least Linux and OpenBSD implementations require explicit trailing
@@ -61,13 +54,16 @@ mktempdir() {
 
 print_sysinfo() {
     uname -a
+    printf 'OS identification: '
+    os_id
     date
 }
 
 # Try to make the current C compiler print its version information (usually
 # multi-line) to stdout.
 # shellcheck disable=SC2006
-print_cc_version() {
+cc_version_nocache() {
+    : "${CC:?}"
     case `basename "$CC"` in
     gcc*|egcc*|clang*)
         # GCC and Clang recognize --version, print to stdout and exit with 0.
@@ -86,16 +82,16 @@ print_cc_version() {
         "$CC" -V 2>&1 || :
         ;;
     cc)
-        case `uname -s` in
-        SunOS)
+        case `os_id` in
+        SunOS-*)
             # Most likely Sun C.
             "$CC" -V 2>&1 || :
             ;;
-        Darwin)
+        Darwin-*)
             # Most likely Clang.
             "$CC" --version
             ;;
-        Linux|FreeBSD|NetBSD|OpenBSD)
+        Linux-*|FreeBSD-*|NetBSD-*|OpenBSD-*)
             # Most likely Clang or GCC.
             "$CC" --version
             ;;
@@ -107,11 +103,23 @@ print_cc_version() {
     esac
 }
 
+# shellcheck disable=SC2006
+cc_version() {
+    echo "${cc_version_cached:=`cc_version_nocache`}"
+}
+
+print_cc_version() {
+    cc_version
+    printf 'Compiler identification: '
+    cc_id
+}
+
 # For the current C compiler try to print a short and uniform identification
 # string (such as "gcc-9.3.0") that is convenient to use in a case statement.
 # shellcheck disable=SC2006
-cc_id() {
-    cc_id_firstline=`print_cc_version | head -1`
+cc_id_nocache() {
+    cc_id_firstline=`cc_version | head -1`
+    : "${cc_id_firstline:?}"
 
     cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.*clang version \([0-9\.]*\).*$/clang-\1/'`
     if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
@@ -138,6 +146,17 @@ cc_id() {
     fi
 }
 
+# shellcheck disable=SC2006
+cc_id() {
+    echo "${cc_id_cached:=`cc_id_nocache`}"
+}
+
+# Call this function each time CC has changed.
+discard_cc_cache() {
+    cc_version_cached=
+    cc_id_cached=
+}
+
 # For the current C compiler try to print CFLAGS value that tells to treat
 # warnings as errors.
 # shellcheck disable=SC2006
@@ -157,6 +176,42 @@ cc_werr_cflags() {
     esac
 }
 
+# Tell whether "gcc" is a symlink to Clang (this is the case on macOS).
+# shellcheck disable=SC2006
+gcc_is_clang_in_disguise() {
+    case `cc_id`/`basename "${CC:?}"` in
+    clang-*/gcc)
+        return 0
+        ;;
+    esac
+    return 1
+}
+
+# shellcheck disable=SC2006
+os_id() {
+    # OS does not change between builds or in the middle of a build, so it is
+    # fine to cache uname output.
+    : "${os_id_sysname:=`uname -s`}"
+    printf '%s-' "$os_id_sysname"
+    : "${os_id_release:=`uname -r`}"
+    case "$os_id_sysname" in
+    AIX)
+        : "${os_id_version:=`uname -v`}"
+        echo "${os_id_version}.${os_id_release}"
+        ;;
+    Darwin|NetBSD|OpenBSD|SunOS)
+        echo "$os_id_release"
+        ;;
+    FreeBSD|Linux)
+        # Meaningful version is usually the substring before the first dash.
+        echo "$os_id_release" | sed 's/^\([0-9\.]*\).*$/\1/'
+        ;;
+    *)
+        echo 'UNKNOWN'
+        ;;
+    esac
+}
+
 increment() {
     # No arithmetic expansion in Solaris /bin/sh before 11.
     echo "${1:?} + 1" | bc
@@ -177,8 +232,8 @@ run_after_echo() {
 
 print_so_deps() {
     # shellcheck disable=SC2006
-    case `uname -s` in
-    Darwin)
+    case `os_id` in
+    Darwin-*)
         run_after_echo otool -L "${1:?}"
         ;;
     *)
@@ -202,7 +257,7 @@ handle_matrix_debug() {
 
 purge_directory() {
     # shellcheck disable=SC2006
-    if [ "`uname -s`" = SunOS ] && [ "`uname -r`" = 5.11 ]; then
+    if [ "`os_id`" = SunOS-5.11 ]; then
         # In Solaris 11 /bin/sh the pathname expansion of "*" always includes
         # "." and "..", so the straightforward rm would always fail.
         (
index 8d13fcffb688153f66415a9ebf05026b752175bb..c5f699a0c177864b159cff4351177334fd3747a8 100755 (executable)
 : "${MATRIX_CMAKE:=no yes}"
 : "${MATRIX_CRYPTO:=no yes}"
 : "${MATRIX_SMB:=no yes}"
+# Set this variable to "yes" before calling this script to disregard all
+# warnings in a particular environment (CI or a local working copy).  Set it
+# to "yes" in this script or in build.sh when a matrix subset is known to be
+# not warning-free because of the OS, the compiler or whatever other factor
+# that the scripts can detect both in and out of CI.
+: "${TCPDUMP_TAINTED:=no}"
 
 . ./build_common.sh
 print_sysinfo
@@ -24,6 +30,7 @@ if [ -z "$PREFIX" ]; then
     export PREFIX
 fi
 COUNT=0
+export TCPDUMP_TAINTED
 
 build_tcpdump() {
     for CMAKE in $MATRIX_CMAKE; do
@@ -34,7 +41,7 @@ build_tcpdump() {
                 export SMB
                 # shellcheck disable=SC2006
                 COUNT=`increment $COUNT`
-                echo_magenta "===== SETUP $COUNT: BUILD_LIBPCAP=$BUILD_LIBPCAP REMOTE=${REMOTE:-?} CC=$CC CMAKE=$CMAKE CRYPTO=$CRYPTO SMB=$SMB ====="
+                echo_magenta "===== SETUP $COUNT: BUILD_LIBPCAP=$BUILD_LIBPCAP REMOTE=${REMOTE:-?} CC=$CC CMAKE=$CMAKE CRYPTO=$CRYPTO SMB=$SMB =====" >&2
                 # Run one build with setup environment variables:
                 # BUILD_LIBPCAP, REMOTE, CC, CMAKE, CRYPTO and SMB
                 run_after_echo ./build.sh
@@ -56,9 +63,8 @@ build_tcpdump() {
 touch .devel configure
 for CC in $MATRIX_CC; do
     export CC
-    # Exclude gcc on macOS (it is just an alias for clang).
-    # shellcheck disable=SC2006
-    if [ "$CC" = gcc ] && [ "`uname -s`" = Darwin ]; then
+    discard_cc_cache
+    if gcc_is_clang_in_disguise; then
         echo '(skipped)'
         continue
     fi
@@ -68,7 +74,7 @@ for CC in $MATRIX_CC; do
             for REMOTE in $MATRIX_REMOTE; do
                 export REMOTE
                 # Build libpcap with Autoconf.
-                echo_magenta "Build libpcap (CMAKE=no REMOTE=$REMOTE)"
+                echo_magenta "Build libpcap (CMAKE=no REMOTE=$REMOTE)" >&2
                 (cd ../libpcap && CMAKE=no ./build.sh)
                 # Set PKG_CONFIG_PATH for configure when building libpcap
                 if [ "$CMAKE" != no ]; then
@@ -78,7 +84,7 @@ for CC in $MATRIX_CC; do
                 build_tcpdump
             done
         else
-            echo_magenta 'Use system libpcap'
+            echo_magenta 'Use system libpcap' >&2
             purge_directory "$PREFIX"
             (cd ../libpcap; make distclean || echo '(Ignoring the make error.)')
             build_tcpdump
@@ -87,5 +93,5 @@ for CC in $MATRIX_CC; do
 done
 
 run_after_echo rm -rf "$PREFIX"
-echo_magenta "Tested setup count: $COUNT"
+echo_magenta "Tested setup count: $COUNT" >&2
 # vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :