debuggers.hg
changeset 16809:6ba04ec03dec
Make tools/check scripts cross-friendly
This patch introduces tools/check/funcs.sh with some
cross-friendly abstractions, then modifies the check_*
scripts to use them.
Signed-off-by: Aron Griffis <aron@hp.com>
This patch introduces tools/check/funcs.sh with some
cross-friendly abstractions, then modifies the check_*
scripts to use them.
Signed-off-by: Aron Griffis <aron@hp.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Jan 22 09:44:17 2008 +0000 (2008-01-22) |
parents | 5b9b3b41fe89 |
children | 5f3c236d1711 |
files | tools/check/check_brctl tools/check/check_crypto_lib tools/check/check_curl tools/check/check_iproute tools/check/check_openssl_devel tools/check/check_python tools/check/check_python_devel tools/check/check_python_xml tools/check/check_udev tools/check/check_x11_devel tools/check/check_xgettext tools/check/check_xml2 tools/check/check_zlib_devel tools/check/check_zlib_lib tools/check/chk tools/check/funcs.sh |
line diff
1.1 --- a/tools/check/check_brctl Tue Jan 22 09:43:53 2008 +0000 1.2 +++ b/tools/check/check_brctl Tue Jan 22 09:44:17 2008 +0000 1.3 @@ -1,27 +1,13 @@ 1.4 #!/bin/sh 1.5 # CHECK-INSTALL 1.6 1.7 -RC=0 1.8 +. funcs.sh 1.9 1.10 -case ${OS} in 1.11 +case $OS in 1.12 OpenBSD|NetBSD|FreeBSD) 1.13 - # These systems have a bridge builtin 1.14 - TOOL="brconfig" 1.15 - which ${TOOL} 1>/dev/null 2>&1 || RC=1 1.16 - ;; 1.17 + has_or_fail brconfig ;; 1.18 Linux) 1.19 - TOOL="brctl" 1.20 - which ${TOOL} 1>/dev/null 2>&1 || RC=1 1.21 - ;; 1.22 + has_or_fail brctl ;; 1.23 *) 1.24 - TOOL="" 1.25 - echo "Unknown OS" && RC=1 1.26 - ;; 1.27 + fail "unknown OS" ;; 1.28 esac 1.29 - 1.30 -if test ${RC} -ne 0; then 1.31 - echo 1.32 - echo " *** Check for the bridge control utils (${TOOL}) FAILED" 1.33 -fi 1.34 - 1.35 -exit ${RC}
2.1 --- a/tools/check/check_crypto_lib Tue Jan 22 09:43:53 2008 +0000 2.2 +++ b/tools/check/check_crypto_lib Tue Jan 22 09:44:17 2008 +0000 2.3 @@ -1,23 +1,11 @@ 2.4 #!/bin/sh 2.5 # CHECK-BUILD CHECK-INSTALL 2.6 2.7 -RC=0 2.8 +. funcs.sh 2.9 2.10 -case $(uname -s) in 2.11 +case $OS in 2.12 FreeBSD|NetBSD|OpenBSD) 2.13 - exit 0 2.14 - ;; 2.15 -*) 2.16 - ;; 2.17 + exit 0 ;; 2.18 esac 2.19 2.20 -PATH=/sbin:$PATH 2.21 -set -e 2.22 -ldconfig -p 2>&1 | grep -q libcrypto.so || RC=1 2.23 - 2.24 -if test ${RC} -ne 0; then 2.25 - echo 2.26 - echo " *** Check for crypto library FAILED" 2.27 -fi 2.28 - 2.29 -exit ${RC} 2.30 +has_lib libcrypto.so || fail "missing libcrypto.so"
3.1 --- a/tools/check/check_curl Tue Jan 22 09:43:53 2008 +0000 3.2 +++ b/tools/check/check_curl Tue Jan 22 09:44:17 2008 +0000 3.3 @@ -1,38 +1,13 @@ 3.4 #!/bin/sh 3.5 # CHECK-BUILD CHECK-INSTALL 3.6 3.7 -if [ ! "$LIBXENAPI_BINDINGS" = "y" ] 3.8 -then 3.9 - echo -n "unused, " 3.10 - exit 0 3.11 -fi 3.12 - 3.13 -RC=0 3.14 +. funcs.sh 3.15 3.16 -CURL_CONFIG="$(which curl-config)" 3.17 -tmpfile=$(mktemp) 3.18 - 3.19 -if test -z ${CURL_CONFIG}; then 3.20 - RC=1 3.21 -else 3.22 - ${CURL_CONFIG} --libs 2>&1 > /dev/null 3.23 - RC=$? 3.24 +if [ "$LIBXENAPI_BINDINGS" != "y" ]; then 3.25 + echo -n "unused, " 3.26 + exit 0 3.27 fi 3.28 3.29 -if test $RC -ne 0; then 3.30 - echo "FAILED" 3.31 - echo " *** curl-config is missing. " 3.32 - echo " *** Please install curl-devel." 3.33 -elif ! ld $($CURL_CONFIG --libs) -o $tmpfile >/dev/null 2>&1; then 3.34 - echo "FAILED" 3.35 - echo " *** dependency libraries for curl are missing: " 3.36 - RC=1 3.37 - for i in $(ld $($CURL_CONFIG --libs) -o $tmpfile 2>&1 >/dev/null); do 3.38 - case $i in 3.39 - -l*) echo lib${i#-l} 3.40 - esac 3.41 - done 3.42 -fi 3.43 -rm -f $tmpfile 3.44 - 3.45 -exit $RC 3.46 +has_or_fail curl-config 3.47 +curl_libs=`curl-config --libs` || fail "curl-config --libs failed" 3.48 +test_link $curl_libs || fail "dependency libraries for curl are missing"
4.1 --- a/tools/check/check_iproute Tue Jan 22 09:43:53 2008 +0000 4.2 +++ b/tools/check/check_iproute Tue Jan 22 09:44:17 2008 +0000 4.3 @@ -1,26 +1,15 @@ 4.4 #!/bin/sh 4.5 # CHECK-INSTALL 4.6 4.7 -RC=0 4.8 +. funcs.sh 4.9 4.10 -case ${OS} in 4.11 +PATH=/sbin:$PATH 4.12 + 4.13 +case $OS in 4.14 OpenBSD|NetBSD|FreeBSD) 4.15 - TOOL="ifconfig" 4.16 - eval ${TOOL} -a 1>/dev/null 2>&1 || RC=1 4.17 - ;; 4.18 + has_or_fail ifconfig ;; 4.19 Linux) 4.20 - TOOL="ip addr" 4.21 - eval ${TOOL} list 1>/dev/null 2>&1 || RC=1 4.22 - ;; 4.23 + has_or_fail ip ;; 4.24 *) 4.25 - TOOL="" 4.26 - echo "Unknown OS" && RC=1 4.27 - ;; 4.28 + fail "unknown OS" ;; 4.29 esac 4.30 - 4.31 -if test ${RC} -ne 0; then 4.32 - echo 4.33 - echo " *** Check for iproute (${TOOL}) FAILED" 4.34 -fi 4.35 - 4.36 -exit ${RC}
5.1 --- a/tools/check/check_openssl_devel Tue Jan 22 09:43:53 2008 +0000 5.2 +++ b/tools/check/check_openssl_devel Tue Jan 22 09:44:17 2008 +0000 5.3 @@ -1,14 +1,6 @@ 5.4 #!/bin/sh 5.5 # CHECK-BUILD 5.6 5.7 -RC=0 5.8 - 5.9 -set -e 5.10 -test -r /usr/include/openssl/md5.h || RC=1 5.11 +. funcs.sh 5.12 5.13 -if test ${RC} -ne 0; then 5.14 - echo 5.15 - echo " *** Check for openssl headers FAILED" 5.16 -fi 5.17 - 5.18 -exit ${RC} 5.19 +has_header openssl/md5.h || fail "missing openssl headers"
6.1 --- a/tools/check/check_python Tue Jan 22 09:43:53 2008 +0000 6.2 +++ b/tools/check/check_python Tue Jan 22 09:44:17 2008 +0000 6.3 @@ -1,16 +1,9 @@ 6.4 #!/bin/sh 6.5 # CHECK-BUILD CHECK-INSTALL 6.6 6.7 -RC=0 6.8 +. funcs.sh 6.9 6.10 python -c ' 6.11 import sys 6.12 sys.exit(sys.version_info[0] < 2 or sys.version_info[1] < 2) 6.13 -' || RC=1 6.14 - 6.15 -if test ${RC} -ne 0; then 6.16 - echo 6.17 - echo " *** Check for Python version >= 2.2 FAILED" 6.18 -fi 6.19 - 6.20 -exit ${RC} 6.21 +' || fail "need python version >= 2.2"
7.1 --- a/tools/check/check_python_devel Tue Jan 22 09:43:53 2008 +0000 7.2 +++ b/tools/check/check_python_devel Tue Jan 22 09:44:17 2008 +0000 7.3 @@ -1,7 +1,7 @@ 7.4 #!/bin/sh 7.5 # CHECK-BUILD 7.6 7.7 -RC=0 7.8 +. funcs.sh 7.9 7.10 python -c ' 7.11 import os.path, sys 7.12 @@ -9,11 +9,4 @@ for p in sys.path: 7.13 if os.path.exists(p + "/config/Makefile"): 7.14 sys.exit(0) 7.15 sys.exit(1) 7.16 -' || RC=1 7.17 - 7.18 -if test ${RC} -ne 0; then 7.19 - echo 7.20 - echo " *** Check for python development environment FAILED" 7.21 -fi 7.22 - 7.23 -exit ${RC} 7.24 +' || fail "can't find python devel files"
8.1 --- a/tools/check/check_python_xml Tue Jan 22 09:43:53 2008 +0000 8.2 +++ b/tools/check/check_python_xml Tue Jan 22 09:44:17 2008 +0000 8.3 @@ -1,8 +1,7 @@ 8.4 #!/bin/sh 8.5 # CHECK-INSTALL 8.6 8.7 -python -c 'import xml.dom.minidom' 2>/dev/null || { 8.8 - echo 8.9 - echo " *** Check for python-xml package FAILED" 8.10 - exit 1 8.11 -} 8.12 +. funcs.sh 8.13 + 8.14 +python -c 'import xml.dom.minidom' 2>/dev/null || \ 8.15 +fail "can't import xml.dom.minidom"
9.1 --- a/tools/check/check_udev Tue Jan 22 09:43:53 2008 +0000 9.2 +++ b/tools/check/check_udev Tue Jan 22 09:44:17 2008 +0000 9.3 @@ -1,34 +1,19 @@ 9.4 #!/bin/sh 9.5 # CHECK-INSTALL 9.6 9.7 -RC=0 9.8 +. funcs.sh 9.9 9.10 -case ${OS} in 9.11 +case $OS in 9.12 OpenBSD|NetBSD|FreeBSD) 9.13 - TOOL="vnconfig" 9.14 - which ${TOOL} 1>/dev/null 2>&1 || RC=1 9.15 + has_or_fail vnconfig 9.16 ;; 9.17 Linux) 9.18 - TOOL="udevinfo" 9.19 - UDEV_VERSION="0" 9.20 - test -x "$(which ${TOOL} 2>/dev/null)" && \ 9.21 - UDEV_VERSION=$(${TOOL} -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/') 9.22 - if test "${UDEV_VERSION}" -ge 059; then 9.23 - RC=0 9.24 - else 9.25 - TOOL="hotplug" 9.26 - which ${TOOL} 1>/dev/null 2>&1 || RC=1 9.27 - fi 9.28 + has_or_fail udevinfo 9.29 + [ "`udevinfo -V | awk '{print $NF}'`" -ge 59 ] 2>/dev/null || \ 9.30 + has hotplug || \ 9.31 + fail "udev is too old, upgrade to version 59 or later" 9.32 ;; 9.33 *) 9.34 - TOOL="" 9.35 - echo "Unknown OS" && RC=1 9.36 + fail "unknown OS" 9.37 ;; 9.38 esac 9.39 - 9.40 -if test ${RC} -ne 0; then 9.41 - echo 9.42 - echo " *** Check for ${TOOL} FAILED" 9.43 -fi 9.44 - 9.45 -exit ${RC}
10.1 --- a/tools/check/check_x11_devel Tue Jan 22 09:43:53 2008 +0000 10.2 +++ b/tools/check/check_x11_devel Tue Jan 22 09:44:17 2008 +0000 10.3 @@ -1,15 +1,8 @@ 10.4 #!/bin/sh 10.5 # CHECK-BUILD 10.6 10.7 -RC=0 10.8 - 10.9 -set -e 10.10 -test -r /usr/include/X11/keysymdef.h || \ 10.11 -test -r /usr/X11R6/include/X11/keysymdef.h || RC=1 10.12 +. funcs.sh 10.13 10.14 -if test ${RC} -ne 0; then 10.15 - echo 10.16 - echo " *** Check for x11 headers FAILED" 10.17 -fi 10.18 - 10.19 -exit ${RC} 10.20 +has_header X11/keysymdef.h || \ 10.21 +has_header /usr/X11R6/include/X11/keysymdef.h || \ 10.22 +fail "can't find X11 headers"
11.1 --- a/tools/check/check_xgettext Tue Jan 22 09:43:53 2008 +0000 11.2 +++ b/tools/check/check_xgettext Tue Jan 22 09:44:17 2008 +0000 11.3 @@ -1,14 +1,6 @@ 11.4 #!/bin/sh 11.5 # CHECK-BUILD 11.6 11.7 -RC=0 11.8 - 11.9 -TOOL="xgettext" 11.10 -which ${TOOL} 1>/dev/null 2>&1 || RC=1 11.11 +. funcs.sh 11.12 11.13 -if test ${RC} -ne 0; then 11.14 - echo 11.15 - echo " *** Check for the gettext utility (${TOOL}) FAILED" 11.16 -fi 11.17 - 11.18 -exit ${RC} 11.19 +has_or_fail xgettext
12.1 --- a/tools/check/check_xml2 Tue Jan 22 09:43:53 2008 +0000 12.2 +++ b/tools/check/check_xml2 Tue Jan 22 09:44:17 2008 +0000 12.3 @@ -1,38 +1,14 @@ 12.4 #!/bin/sh 12.5 # CHECK-BUILD CHECK-INSTALL 12.6 12.7 +. funcs.sh 12.8 + 12.9 if [ ! "$LIBXENAPI_BINDINGS" = "y" -a ! "$ACM_SECURITY" = "y" ] 12.10 then 12.11 echo -n "unused, " 12.12 exit 0 12.13 fi 12.14 12.15 -RC=0 12.16 - 12.17 -XML2_CONFIG="$(which xml2-config)" 12.18 -tmpfile=$(mktemp) 12.19 - 12.20 -if test -z ${XML2_CONFIG}; then 12.21 - RC=1 12.22 -else 12.23 - ${XML2_CONFIG} --libs 2>&1 > /dev/null 12.24 - RC=$? 12.25 -fi 12.26 - 12.27 -if test $RC -ne 0; then 12.28 - echo "FAILED" 12.29 - echo " *** xml2-config is missing. " 12.30 - echo " *** Please install libxml2-devel." 12.31 -elif ! ld $($XML2_CONFIG --libs) -o $tmpfile >/dev/null 2>&1; then 12.32 - echo "FAILED" 12.33 - echo " *** dependency libraries for xml2 are missing: " 12.34 - RC=1 12.35 - for i in $(ld $($XML2_CONFIG --libs) -o $tmpfile 2>&1 >/dev/null); do 12.36 - case $i in 12.37 - -l*) echo lib${i#-l} 12.38 - esac 12.39 - done 12.40 -fi 12.41 -rm -f $tmpfile 12.42 - 12.43 -exit $RC 12.44 +has_or_fail xml2-config 12.45 +xml2_libs=`xml2-config --libs` || fail "xml2-config --libs failed" 12.46 +test_link $xml2_libs || fail "dependency libraries for xml2 are missing"
13.1 --- a/tools/check/check_zlib_devel Tue Jan 22 09:43:53 2008 +0000 13.2 +++ b/tools/check/check_zlib_devel Tue Jan 22 09:44:17 2008 +0000 13.3 @@ -1,14 +1,6 @@ 13.4 #!/bin/sh 13.5 # CHECK-BUILD 13.6 13.7 -RC=0 13.8 - 13.9 -set -e 13.10 -test -r /usr/include/zlib.h || RC=1 13.11 +. funcs.sh 13.12 13.13 -if test ${RC} -ne 0; then 13.14 - echo 13.15 - echo " *** Check for zlib headers FAILED" 13.16 -fi 13.17 - 13.18 -exit ${RC} 13.19 +has_header zlib.h || fail "can't find zlib headers"
14.1 --- a/tools/check/check_zlib_lib Tue Jan 22 09:43:53 2008 +0000 14.2 +++ b/tools/check/check_zlib_lib Tue Jan 22 09:44:17 2008 +0000 14.3 @@ -1,24 +1,12 @@ 14.4 #!/bin/sh 14.5 # CHECK-BUILD CHECK-INSTALL 14.6 14.7 -RC=0 14.8 +. funcs.sh 14.9 14.10 -case $(uname -s) in 14.11 +case $OS in 14.12 FreeBSD|NetBSD|OpenBSD) 14.13 exit 0 14.14 ;; 14.15 -*) 14.16 - ;; 14.17 esac 14.18 14.19 -PATH=/sbin:$PATH 14.20 - 14.21 -set -e 14.22 -ldconfig -p 2>&1 | grep -q libz.so || RC=1 14.23 - 14.24 -if test ${RC} -ne 0; then 14.25 - echo 14.26 - echo " *** Check for zlib library FAILED" 14.27 -fi 14.28 - 14.29 -exit ${RC} 14.30 +has_lib libz.so || fail "can't find zlib"
15.1 --- a/tools/check/chk Tue Jan 22 09:43:53 2008 +0000 15.2 +++ b/tools/check/chk Tue Jan 22 09:44:17 2008 +0000 15.3 @@ -7,17 +7,16 @@ func_usage () 15.4 echo 15.5 echo "Check suitability for Xen build or install." 15.6 echo "Exit with 0 if OK, 1 if not." 15.7 - echo "Prints only failed tests." 15.8 echo 15.9 echo "Calling with 'clean' removes generated files." 15.10 exit 1 15.11 } 15.12 15.13 -PATH=${PATH}:/sbin:/usr/sbin 15.14 +PATH=$PATH:/sbin:/usr/sbin 15.15 OS=`uname -s` 15.16 export PATH OS 15.17 15.18 -if test "${OS}" = "SunOS"; then 15.19 +if [ "$OS" = "SunOS" ]; then 15.20 exit 0 15.21 fi 15.22 15.23 @@ -38,7 +37,7 @@ esac 15.24 15.25 failed=0 15.26 15.27 -echo "Xen ${check} " $(date) 15.28 +echo "Xen ${check} " `date` 15.29 for f in check_* ; do 15.30 case $f in 15.31 *~) 15.32 @@ -50,7 +49,7 @@ for f in check_* ; do 15.33 if ! [ -x $f ] ; then 15.34 continue 15.35 fi 15.36 - if ! grep -q ${check} $f ; then 15.37 + if ! grep -Fq "$check" $f ; then 15.38 continue 15.39 fi 15.40 echo -n "Checking $f: "
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/tools/check/funcs.sh Tue Jan 22 09:44:17 2008 +0000 16.3 @@ -0,0 +1,85 @@ 16.4 +# has is the same as which, except it handles cross environments 16.5 +has() { 16.6 + if [ -z "$CROSS_COMPILE" ]; then 16.7 + command which "$@" 16.8 + return $? 16.9 + fi 16.10 + 16.11 + check_sys_root || return 1 16.12 + 16.13 + # subshell to prevent pollution of caller's IFS 16.14 + ( 16.15 + IFS=: 16.16 + for p in $PATH; do 16.17 + if [ -x "$CROSS_SYS_ROOT/$p/$1" ]; then 16.18 + echo "$CROSS_SYS_ROOT/$p/$1" 16.19 + return 0 16.20 + fi 16.21 + done 16.22 + return 1 16.23 + ) 16.24 +} 16.25 + 16.26 +has_or_fail() { 16.27 + has "$1" >/dev/null || fail "can't find $1" 16.28 +} 16.29 + 16.30 +has_header() { 16.31 + case $1 in 16.32 + /*) ;; 16.33 + *) set -- "/usr/include/$1" ;; 16.34 + esac 16.35 + 16.36 + check_sys_root || return 1 16.37 + 16.38 + test -r "$CROSS_SYS_ROOT$1" 16.39 + return $? 16.40 +} 16.41 + 16.42 +has_lib() { 16.43 + check_sys_root || return 1 16.44 + 16.45 + # subshell to prevent pollution of caller's environment 16.46 + ( 16.47 + PATH=/sbin:$PATH # for ldconfig 16.48 + 16.49 + # This relatively common in a sys-root; libs are installed but 16.50 + # ldconfig hasn't run there, so ldconfig -p won't work. 16.51 + if [ "$OS" = Linux -a ! -f "$CROSS_SYS_ROOT/etc/ld.so.cache" ]; then 16.52 + echo "Please run ldconfig -r \"$CROSS_SYS_ROOT\" to generate ld.so.cache" 16.53 + # fall through; ldconfig test below should fail 16.54 + fi 16.55 + ldconfig -p ${CROSS_SYS_ROOT+-r "$CROSS_SYS_ROOT"} | grep -Fq "$1" 16.56 + return $? 16.57 + ) 16.58 +} 16.59 + 16.60 +test_link() { 16.61 + # subshell to trap removal of tmpfile 16.62 + ( 16.63 + unset tmpfile 16.64 + trap 'rm -f "$tmpfile"; exit' 0 1 2 15 16.65 + tmpfile=`mktemp` || return 1 16.66 + ld "$@" -o "$tmpfile" >/dev/null 2>&1 16.67 + return $? 16.68 + ) 16.69 +} 16.70 + 16.71 +# this function is used commonly above 16.72 +check_sys_root() { 16.73 + [ -z "$CROSS_COMPILE" ] && return 0 16.74 + if [ -z "$CROSS_SYS_ROOT" ]; then 16.75 + echo "please set CROSS_SYS_ROOT in the environment" 16.76 + return 1 16.77 + fi 16.78 + if [ ! -d "$CROSS_SYS_ROOT" ]; then 16.79 + echo "no sys-root found at $CROSS_SYS_ROOT" 16.80 + return 1 16.81 + fi 16.82 +} 16.83 + 16.84 +fail() { 16.85 + echo 16.86 + echo " *** `basename "$0"` FAILED${*+: $*}" 16.87 + exit 1 16.88 +}