]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Clean up gdb/contrib/expect-read1.sh
authorTom de Vries <tdevries@suse.de>
Sat, 15 Jun 2024 06:10:44 +0000 (08:10 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 15 Jun 2024 06:10:44 +0000 (08:10 +0200)
Clean up script gdb/contrib/expect-read1.sh by:
- fixing shellcheck warnings,
- using mktemp (which takes TMPDIR into account) instead of a hardcoded
  "/tmp/expect-read1.$$.so",
- adding comments, and
- adding emacs / vi settings for local tab size 2 (copied from ./ltmain.sh).

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
gdb/contrib/expect-read1.sh

index 890a1cdbd07d527e3e40403190af2c1837447840..82c638c59d28a1e34f5a44a2a57687a771afa30d 100755 (executable)
 # or
 # bash$ EXPECT=../contrib/expect-read1.sh runtest
 
-C=`echo $0|sed 's/\.sh$/.c/'`
-if ! test -e $C; then
+# Find source file.
+C=$(echo "$0" | sed 's/\.sh$/.c/')
+if ! test -e "$C"; then
   echo >&2 "$0: Cannot find 'srcdir/gdb/contrib/expect-read1.c' at '$C'."
   exit 2
 fi
-SO=/tmp/expect-read1.$$.so
-rm -f $SO
+
+# Create temp directory.
+tmpdir=$(mktemp -d)
+
+# Schedule cleanup.
+trap 'rm -rf $tmpdir' EXIT
+
+# Compile shared library.
+SO=$tmpdir/expect-read1.so
 CMD="${CC_FOR_TARGET:-gcc} -o $SO -Wall -fPIC -shared $C"
 if ! $CMD; then
   echo >&2 "$0: Failed: $CMD"
   exit 2
 fi
-trap "rm -f $SO" EXIT
+
+# Call expect with the shared library preloaded.
 LD_PRELOAD=$SO expect "$@"
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
+# vi:sw=2