FS#7803 - makepkg logging function limits use of bash functionality

Attached to Project: Pacman
Opened by Tobias Kieslich (tobias) - Sunday, 12 August 2007, 20:50 GMT
Last edited by Dan McGee (toofishes) - Sunday, 17 February 2008, 19:55 GMT
Task Type Bug Report
Category makepkg
Status Closed
Assigned To Aaron Griffin (phrakture)
Dan McGee (toofishes)
Andrew Fyfe (space-m0nkey)
Architecture All
Severity Medium
Priority Normal
Reported Version 3.0.5
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Summary and Info:
If you wanna test return values by evaluating $? in bash, makepkg --log stops executing because it evaluates that before a PKGBUILD function can catch it.

Steps to Reproduce:
the old vi fetch_runtime.sh used the following construction:
echo "${_md5} ${_file}" | md5sum -c - >/dev/null 2>&1
# MD5 fails ? ... we don't have the file
if [ ${?} -ne 0 ]; then
rm ${_file}
else
_havefile=1
fi
and which fails. It had to be rewritten to:
# MD5 fails ? ... we don't have the file
if [ $(echo "${_md5} ${_file}" | md5sum --status -c -) ]; then
rm ${_file}
else
_havefile=1
fi

It worked in this case, but there might be vases when a return value can be more than 0 or 1 and this can't be easily used at all.
This task depends upon

Closed by  Dan McGee (toofishes)
Sunday, 17 February 2008, 19:55 GMT
Reason for closing:  Fixed
Additional comments about closing:  Fixed WAY back when in commit 58fe79eef64fb87b2553e6514a47beaa6d0249c1
Comment by Aaron Griffin (phrakture) - Monday, 13 August 2007, 15:13 GMT
Certainly weird...
I could see two things to check up on:
the $? check
the ">/dev/null 2>&1" redirection

The second makes more sense, as I could see it somehow redirecting the rest of the output.... not really sure though.
Comment by Tobias Kieslich (tobias) - Monday, 13 August 2007, 16:02 GMT
I actually think it is on the first one, since the referring code in makepkg looks like that:
if [ "$LOGGING" = "1" ]; then
BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log"
if [ -f "$BUILDLOG" ]; then
i=1
while true; do
if [ -f "$BUILDLOG.$i" ]; then
i=$(($i +1))
else
break
fi
done
mv "$BUILDLOG" "$BUILDLOG.$i"
fi

#use 'errexit' to bail on syntax error
[ $set_e -eq 1 ] && set -e
build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
[ $set_e -eq 1 ] && set +e
else
#use 'errexit' to bail on syntax error
[ $set_e -eq 1 ] && set -e
build 2>&1 || ret=$?
[ $set_e -eq 1 ] && set +e
fi
if [ $ret -gt 0 ]; then
error "Build Failed. Aborting..."
removedeps
exit 2
fi
Comment by Andrew Fyfe (space-m0nkey) - Monday, 13 August 2007, 16:08 GMT
This was a makepkg bug (http://cvs.archlinux.org/cgi-bin/viewcvs.cgi/scripts/makepkg.diff?r1=1.64&r2=1.65&cvsroot=Pacman).

When using `makepkg -L` it didn't stop on build failures. You need to either do..

if CMD; then
....

or

ret=0
CMD | ret=$?
if [ $ret = 0 ] ; then
....
Comment by Dan McGee (toofishes) - Sunday, 17 February 2008, 01:27 GMT
Is this still valid? Or what is our status here?
Comment by Xavier (shining) - Sunday, 17 February 2008, 10:01 GMT

Loading...