[PATCH build 03/10] Print error message with location.
Trevor Woerner
twoerner at gmail.com
Sat Sep 18 13:11:21 PDT 2010
From: Trevor Woerner <twoerner at gmail.com>
Add a function to generate error messages which indicates where in the script
the error message is being generated. This helps to track down how and where
and error is being detected while the script runs.
Signed-off-by: Trevor Woerner <twoerner at gmail.com>
---
build.sh | 33 ++++++++++++++++++++++++++++-----
1 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/build.sh b/build.sh
index 14219ad..c2f83a5 100755
--- a/build.sh
+++ b/build.sh
@@ -65,9 +65,32 @@ failed_components=""
nonexistent_components=""
clonefailed_components=""
+# print an error message indicating source function and line number
+# arguments:
+# $1 - message to display
+# returns:
+# (not significant)
+errout() {
+ local _linenum=0
+ local _funcnum=1
+
+ # preconds
+ if [ -z "$1" ]; then
+ return
+ fi
+
+ # if this is called from failed() we want its ancestors
+ if [ "${FUNCNAME[1]}" = "failed" ]; then
+ _linenum=1
+ _funcnum=2
+ fi
+
+ echo "[${FUNCNAME[$_funcnum]}():${BASH_LINENO[$_linenum]}] $1" > /dev/stderr
+}
+
failed() {
if [ -n "${NOQUIT}" ]; then
- echo "***** $1 failed on $2/$3"
+ errout "***** $1 failed on $2/$3"
failed_components+="$2/$3 "
else
exit 1
@@ -216,7 +239,7 @@ build() {
elif [ -n "$CLONE" ]; then
clone $1 $2
if [ $? -ne 0 ]; then
- echo "Failed to clone $1 module component $2. Ignoring."
+ errout "Failed to clone $1 module component $2. Ignoring."
clonefailed_components+="$1/$2 "
if [ -n "$BUILD_ONE" ]; then
exit 1
@@ -231,7 +254,7 @@ build() {
fi
if [ -z "$SRCDIR" ]; then
- echo "$1 module component $2 does not exist, skipping."
+ errout "$1 module component $2 does not exist, skipping."
nonexistent_components+="$1/$2 "
return
fi
@@ -770,7 +793,7 @@ LIB_ONLY=0
# Process command line args
CMDLINE=`getopt -o abcdDf:ghlno:pr:s:L --long check,clone,help,autoresume: -n $0 -- "$@"`
if [ $? != 0 ]; then
- echo "getopt(1) invocation error"
+ errout "getopt(1) invocation error"
exit 1
fi
eval set -- "$CMDLINE"
@@ -846,7 +869,7 @@ while [ 1 ]; do
break
;;
*)
- echo "internal getopt(1) error!"
+ errout "internal getopt(1) error!"
exit 1
;;
esac
--
1.7.3.rc2
More information about the xorg-devel
mailing list