4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-15 05:29:10 +08:00

Cygwin: Have cygmagic not create output if an error occurs

Improve the 'cygmagic' script, so it doesn't create the output file if
an error occurs, even in one of the backtick-enclosed pipelines it runs.
This commit is contained in:
Jon Turney 2020-11-12 17:58:58 +00:00 committed by Ken Brown
parent 4d8bc5e889
commit e496754853

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# cygmagic - Generate "magic numbers" from a structure. # cygmagic - Generate "magic numbers" from a structure.
# #
# This file is part of Cygwin. # This file is part of Cygwin.
@ -7,14 +7,22 @@
# Cygwin license. Please consult the file "CYGWIN_LICENSE" for # Cygwin license. Please consult the file "CYGWIN_LICENSE" for
# details. # details.
set -e
shopt -s -o pipefail
shopt -s inherit_errexit
file_magic=$1; shift file_magic=$1; shift
gcc=$1; shift gcc=$1; shift
file=$1; shift file=$1; shift
tmpfile=/tmp/$$.magic
trap "rm -f /tmp/$$.magic" 0 1 2 15 trap "rm -f /tmp/$$.magic" 0 1 2 15
cat <<EOF > $file_magic
cat <<EOF > $tmpfile
/* autogenerated - do not edit */ /* autogenerated - do not edit */
#include "$file" #include "$file"
EOF EOF
sumit() { sumit() {
cksum $* cksum $*
} }
@ -28,5 +36,8 @@ while [ -n "$1" ]; do
[ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING *** [ "$curr" != "$sum" ] && echo "*** WARNING WARNING WARNING WARNING WARNING ***
*** $file: magic number for $define changed old $curr != new $sum *** $file: magic number for $define changed old $curr != new $sum
*** WARNING WARNING WARNING WARNING WARNING ***" 1>&2 *** WARNING WARNING WARNING WARNING WARNING ***" 1>&2
done >> $file_magic done >> $tmpfile
mv $tmpfile $file_magic
exit 0 exit 0