"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
tweak got-build-regress.sh
To:
gameoftrees@openbsd.org
Date:
Sun, 08 Jan 2023 13:09:51 +0100

Download raw body.

Thread
landed here for curiosity.  diff below switches got-build-regress.sh
to use the builtin getopts instead of getopt(1) which is nicer for
scripting and runs the trap on EXIT too, so can avoid to remove
$lockfile at every exit point.

ok?

diff /home/op/w/got
commit - 1a99e0b4097b26cac736de07239a3be7589a48f7
path + /home/op/w/got
blob - 82afa2028dd0be74054dd2348115d8cc87611e14
file + util/got-build-regress.sh
--- util/got-build-regress.sh
+++ util/got-build-regress.sh
@@ -22,30 +22,24 @@ args=`getopt b:fR:r:w: $*`
 force=0
 testroot="/tmp"
 
-args=`getopt b:fR:r:w: $*`
-if [ $? -ne 0 ]
-then
-	echo "usage: $usage" >&2
-	exit 1
-fi
-set -- $args
-while [ $# -ne 0 ]; do
-	case "$1"
-	in
-		-b)
-			branch="$2"; shift; shift;;
-		-f)
-			force=1; shift;;
-		-w)
-			worktree="$2"; shift; shift;;
-		-r)
-			fromaddr_arg="-r $2"; shift; shift;;
-		-R)
-			testroot="$2"; shift; shift;;
-		--)
-			shift; break;;
+while getopts b:fR:r:w: arg; do
+	case $arg in
+		b)
+			branch="$OPTARG" ;;
+		f)
+			force=1 ;;
+		w)
+			worktree="$OPTARG" ;;
+		r)
+			fromaddr_arg="-r $OPTARG" ;;
+		R)
+			testroot="$OPTARG" ;;
+		?)
+			echo "usage: $usage" >&2
+			exit 1 ;;
 	esac
 done
+shift $(($OPTIND - 1))
 
 recipients="$@"
 if [ -z "$recipients" ]; then
@@ -63,13 +57,10 @@ cd "$worktree"
 ncpu=`sysctl -n hw.ncpuonline`
 lockfile=$worktree/.${prog}.lock
 
-cd "$worktree"
-if [ $? -ne 0 ]; then
-	exit 1
-fi
+cd "$worktree" || exit 1
 
 lockfile -r 3 "$lockfile" || exit 1
-trap "rm -f '$lockfile'" HUP INT QUIT KILL TERM
+trap "rm -f '$lockfile'" HUP INT QUIT KILL TERM EXIT
 
 rm -f regress.log failures.log
 echo -n "$prog for branch '$branch' on " > build.log
@@ -89,13 +80,11 @@ if [ "$update_status" != "0" ]; then
 update_status="$?"
 if [ "$update_status" != "0" ]; then
 	mail $fromaddr_arg -s "$prog update failure" $recipients < build.log
-	rm -rf "$lockfile"
 	exit 0
 fi
 new_basecommit=`cat .got/base-commit`
 
 if [ "$force" != "1" -a "$old_basecommit" == "$new_basecommit" ]; then
-	rm -rf "$lockfile"
 	exit 0
 fi
 
@@ -105,7 +94,6 @@ if [ "$build_status" != "0" ]; then
 build_status="$?"
 if [ "$build_status" != "0" ]; then
 	mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
-	rm -rf "$lockfile"
 	exit 0
 fi
 log_cmd build.log make install
@@ -113,7 +101,6 @@ if [ "$build_status" != "0" ]; then
 build_status="$?"
 if [ "$build_status" != "0" ]; then
 	mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
-	rm -rf "$lockfile"
 	exit 0
 fi
 
@@ -127,7 +114,6 @@ if [ "$regress_status" != "0" -o "$regress_failure_gre
 	printf "\n\n\t Test failures:\n\n" >> build.log
 	cat failures.log >> build.log
 	mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
-	rm -rf "$lockfile"
 	exit 0
 fi
 
@@ -141,7 +127,6 @@ if [ "$regress_status" != "0" -o "$regress_failure_gre
 	printf "\n\n\t Test failures:\n\n" >> build.log
 	cat failures.log >> build.log
 	mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
-	rm -rf "$lockfile"
 	exit 0
 fi
 
@@ -153,10 +138,7 @@ if [ "$build_status" != "0" ]; then
 build_status="$?"
 if [ "$build_status" != "0" ]; then
 	mail $fromaddr_arg -s "$prog release mode build failure" $recipients < build.log
-	rm -rf "$lockfile"
 	exit 0
 fi
 
-
-rm -f "$lockfile"
 exit 0