xbps-src: simplify run_func().

This commit is contained in:
Juan RP 2011-10-24 21:21:01 +02:00
parent cf60e64209
commit 1dd1ec981c
1 changed files with 10 additions and 28 deletions

View File

@ -62,54 +62,36 @@ remove_pkgdestdir_sighandler()
autoremove_pkg_dependencies ${_kwrksrc} autoremove_pkg_dependencies ${_kwrksrc}
} }
var_is_a_function()
{
local func="$1"
local func_result
func_result=$(mktemp -t xbps_src_run_func.XXXXXX)
type $func > $func_result 2>&1
if $(grep -q 'function' $func_result); then
rm -f $func_result
return 1
fi
rm -f $func_result
return 0
}
run_func() run_func()
{ {
local func="$1"
local rval logpipe logfile local rval logpipe logfile
[ -z "$func" ] && return 1 [ -z "$1" ] && return 1
var_is_a_function $func if type ${1} >/dev/null 2>&1; then
if [ $? -eq 1 ]; then logpipe=$(mktemp -u -t xbps_${1}_${pkgname}_logpipe.XXXXXXXXXX)
logpipe=/tmp/logpipe.$$
if [ -d "${wrksrc}" ]; then if [ -d "${wrksrc}" ]; then
logfile=${wrksrc}/.xbps_${func}.log logfile=${wrksrc}/.xbps_${1}.log
else else
logfile=$(mktemp -t xbps_${func}_${pkgname}.log.XXXXXXXX) logfile=$(mktemp -t xbps_${1}_${pkgname}.log.XXXXXXXX)
fi fi
mkfifo "$logpipe" mkfifo "$logpipe"
exec 3>&1 exec 3>&1
tee "$logfile" < "$logpipe" & tee "$logfile" < "$logpipe" &
exec 1>"$logpipe" 2>"$logpipe" exec 1>"$logpipe" 2>"$logpipe"
set -e set -e
trap "run_func_error $func && return $?" INT trap "run_func_error $1 && return $?" INT
msg_normal "$pkgver: running $func phase...\n" msg_normal "$pkgver: running $1 phase...\n"
$func 2>&1 $1 2>&1
rval=$? rval=$?
set +e set +e
trap - INT trap - INT
exec 1>&3 2>&3 3>&- exec 1>&3 2>&3 3>&-
rm -f "$logpipe" rm -f "$logpipe"
if [ $rval -ne 0 ]; then if [ $rval -ne 0 ]; then
msg_error "$pkgver: $func failed!\n" msg_error "$pkgver: $1 failed!\n"
else else
msg_normal "$pkgver: $func phase done.\n" msg_normal "$pkgver: $1 phase done.\n"
return 0 return 0
fi fi
fi fi