xbps-src: improve run_func and always make a log in $wrksrc.
Also when or after the pkg is installed to destdir/stowned, and there was any error, always remove the files that were installed into destdir. With these changes there's no need to return any value in the do_foo() functions because they are caught automatically. Also any function is now logged into its own file to always log what happens.
This commit is contained in:
parent
4965921029
commit
08d47bc8b1
8 changed files with 158 additions and 151 deletions
|
@ -26,10 +26,6 @@ perl_module_build()
|
|||
cd $wrksrc && \
|
||||
PERL_MM_USE_DEFAULT=1 perl Makefile.PL \
|
||||
${make_build_args} INSTALLDIRS=vendor
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "*** ERROR building perl module for $pkgname ***"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
for i in "$perl_configure_dirs"; do
|
||||
|
@ -38,7 +34,6 @@ perl_module_build()
|
|||
cd $wrksrc/$i && PERL_MM_USE_DEFAULT=1 \
|
||||
perl Makefile.PL ${make_build_args} \
|
||||
INSTALLDIRS=vendor
|
||||
[ "$?" -ne 0 ] && exit 1
|
||||
else
|
||||
echo -n "*** ERROR: couldn't find $perlmkf"
|
||||
echo ", aborting ***"
|
||||
|
|
|
@ -42,7 +42,7 @@ set_defvars
|
|||
|
||||
install_src_phase()
|
||||
{
|
||||
local f i subpkg lver spkgrev saved_wrksrc
|
||||
local f i subpkg lver spkgrev
|
||||
|
||||
[ -z $pkgname ] && return 2
|
||||
|
||||
|
@ -61,7 +61,6 @@ install_src_phase()
|
|||
return 0
|
||||
fi
|
||||
|
||||
saved_wrksrc=$wrksrc
|
||||
cd $wrksrc || msg_error "can't change cwd to wrksrc!"
|
||||
if [ -n "$build_wrksrc" ]; then
|
||||
cd $build_wrksrc \
|
||||
|
@ -70,12 +69,8 @@ install_src_phase()
|
|||
|
||||
# Run pre_install func.
|
||||
if [ ! -f $XBPS_PRE_INSTALL_DONE ]; then
|
||||
run_func pre_install 2>${wrksrc}/.xbps_pre_install.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "Package '$pkgname': pre_install phase failed! errors below"
|
||||
cat $wrksrc/.xbps_pre_install.log
|
||||
exit 1
|
||||
elif [ $? -eq 0 ]; then
|
||||
run_func pre_install
|
||||
if [ $? -eq 0 ]; then
|
||||
msg_normal "Package '$pkgname': pre_install (destdir) phase done."
|
||||
touch -f $XBPS_PRE_INSTALL_DONE
|
||||
fi
|
||||
|
@ -85,26 +80,12 @@ install_src_phase()
|
|||
|
||||
# Type of installation: custom, make or python.
|
||||
case "$build_style" in
|
||||
custom-install)
|
||||
run_func do_install 2>${wrksrc}/.xbps_do_install.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "Package '$pkgname': do_install phase failed! errors below:"
|
||||
cat $wrksrc/.xbps_do_install.log
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
custom-install) run_func do_install;;
|
||||
python-module)
|
||||
. $XBPS_HELPERSDIR/python-module.sh
|
||||
run_func do_install 2>${wrksrc}/.xbps_do_install.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "Package '$pkgname': install phase failed! errors below:"
|
||||
cat $wrksrc/.xbps_do_install.log
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
make_install $lver 2>${wrksrc}/.xbps_make_install.log
|
||||
run_func do_install
|
||||
;;
|
||||
*) run_func make_install;;
|
||||
esac
|
||||
cd ${wrksrc} || msg_error "can't change cwd to wrksrc!"
|
||||
|
||||
|
@ -112,12 +93,8 @@ install_src_phase()
|
|||
|
||||
# Run post_install func.
|
||||
if [ ! -f $XBPS_POST_INSTALL_DONE ]; then
|
||||
run_func post_install 2>${wrksrc}/.xbps_post_install.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "Package '$pkgname': post_install phase failed! errors below:"
|
||||
cat ${wrksrc}/.xbps_post_install.log
|
||||
exit 1
|
||||
elif [ $? -eq 0 ]; then
|
||||
run_func post_install
|
||||
if [ $? -eq 0 ]; then
|
||||
msg_normal "Package '$pkgname': post_install (destdir) phase done."
|
||||
touch -f $XBPS_POST_INSTALL_DONE
|
||||
fi
|
||||
|
@ -164,26 +141,14 @@ install_src_phase()
|
|||
pkgname=${subpkg}
|
||||
set_tmpl_common_vars
|
||||
if [ ! -f ${wrksrc}/.xbps_do_install_${pkgname}_done ]; then
|
||||
run_func do_install \
|
||||
2>${wrksrc}/.xbps_do_install_${pkgname}.log
|
||||
if [ $? -ne 0 -a $? -eq 255 ]; then
|
||||
msg_red "Package '$pkgname': do_install phase failed! errors below:"
|
||||
cat ${wrksrc}/.xbps_do_install_${pkgname}.log
|
||||
exit 1
|
||||
elif [ $? -eq 0 ]; then
|
||||
run_func do_install
|
||||
if [ $? -eq 0 ]; then
|
||||
touch -f ${wrksrc}/.xbps_do_install_${pkgname}_done
|
||||
fi
|
||||
else
|
||||
msg_normal "Package '$sourcepkg ($lver)': skipping '$pkgname' subpkg, already installed into destdir."
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# Remove $wrksrc if -C not specified.
|
||||
#
|
||||
if [ -d "$saved_wrksrc" -a "$dontrm_builddir" = "no" ]; then
|
||||
remove_tmpl_wrksrc $saved_wrksrc
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -191,8 +156,6 @@ install_src_phase()
|
|||
#
|
||||
make_install()
|
||||
{
|
||||
local lver="$1"
|
||||
|
||||
if [ -z "$make_install_target" ]; then
|
||||
make_install_target="DESTDIR=${DESTDIR} install"
|
||||
fi
|
||||
|
@ -201,11 +164,6 @@ make_install()
|
|||
# Install package via make.
|
||||
#
|
||||
${make_cmd} ${make_install_target} ${make_install_args}
|
||||
if [ $? -ne 0 -a -f ${wrksrc}/.xbps_make_install.log ]; then
|
||||
msg_red "Package '$pkgname ($lver)': make install failed! full log below:"
|
||||
cat ${wrksrc}/.xbps_make_install.log
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
[ -z "$PKG_TMPLNAME" ] && exit 2
|
||||
|
|
|
@ -27,6 +27,20 @@
|
|||
# Runs the "build" phase for a pkg. This builds the binaries and other
|
||||
# related stuff.
|
||||
#
|
||||
do_make_build()
|
||||
{
|
||||
#
|
||||
# Build package via make.
|
||||
#
|
||||
if [ "$build_style" = "gnu_makefile" ]; then
|
||||
if [ -n "$XBPS_LDFLAGS" ]; then
|
||||
mkldfags="$LDFLAGS $XBPS_LDFLAGS"
|
||||
fi
|
||||
fi
|
||||
env LDFLAGS="$mkldflags" ${make_cmd} ${makejobs} ${make_build_args} \
|
||||
${make_build_target}
|
||||
}
|
||||
|
||||
build_src_phase()
|
||||
{
|
||||
local pkg="$pkgname-$version" pkgparam="$1" f lver
|
||||
|
@ -64,12 +78,8 @@ build_src_phase()
|
|||
fi
|
||||
# Run pre_build func.
|
||||
if [ ! -f $XBPS_PRE_BUILD_DONE ]; then
|
||||
run_func pre_build 2>${wrksrc}/.xbps_pre_build.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "$pkgname: pre_build phase failed! errors below:"
|
||||
cat $wrksrc/.xbps_pre_build.log
|
||||
exit 1
|
||||
elif [ $? -eq 0 ]; then
|
||||
run_func pre_build
|
||||
if [ $? -eq 0 ]; then
|
||||
msg_normal "$pkgname: pre_build phase done."
|
||||
touch -f $XBPS_PRE_BUILD_DONE
|
||||
fi
|
||||
|
@ -79,34 +89,17 @@ build_src_phase()
|
|||
|
||||
if [ "$build_style" = "custom-install" ]; then
|
||||
[ -n "$XBPS_LDFLAGS" ] && export LDFLAGS="$XBPS_LDFLAGS"
|
||||
run_func do_build 2>${wrksrc}/.xbps_do_build.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_error "Package '$pkgname': do_build phase failed!"
|
||||
fi
|
||||
run_func do_build
|
||||
else
|
||||
#
|
||||
# Build package via make.
|
||||
#
|
||||
if [ "$build_style" = "gnu_makefile" ]; then
|
||||
if [ -n "$XBPS_LDFLAGS" ]; then
|
||||
mkldfags="$LDFLAGS $XBPS_LDFLAGS"
|
||||
fi
|
||||
fi
|
||||
env LDFLAGS="$mkldflags" ${make_cmd} ${makejobs} ${make_build_args} \
|
||||
${make_build_target} ||
|
||||
msg_error "Package '$pkgname': build phase failed!"
|
||||
run_func do_make_build
|
||||
fi
|
||||
|
||||
msg_normal "Package '$pkgname ($lver)': build phase done."
|
||||
|
||||
# Run post_build func.
|
||||
if [ ! -f $XBPS_POST_BUILD_DONE ]; then
|
||||
run_func post_build 2>${wrksrc}/.xbps_post_build.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "Package '$pkgname': post_build phase failed! errors below:"
|
||||
cat $wrksrc/.xbps_post_build.log
|
||||
exit 1
|
||||
elif [ $? -eq 0 ]; then
|
||||
run_func post_build
|
||||
if [ $? -eq 0 ]; then
|
||||
msg_normal "Package '$pkgname': post_build phase done."
|
||||
touch -f $XBPS_POST_BUILD_DONE
|
||||
fi
|
||||
|
|
|
@ -26,15 +26,83 @@
|
|||
#
|
||||
# Common functions for xbps.
|
||||
#
|
||||
run_func_error()
|
||||
{
|
||||
local func="$1"
|
||||
|
||||
remove_pkgdestdir_sighandler ${pkgname}
|
||||
msg_error "${pkgname}-${version}: the $func function didn't complete due to errors or SIGINT!"
|
||||
|
||||
}
|
||||
|
||||
remove_pkgdestdir_sighandler()
|
||||
{
|
||||
local subpkg _pkgname="$1"
|
||||
|
||||
setup_tmpl ${_pkgname}
|
||||
[ -z "$sourcepkg" ] && return 0
|
||||
|
||||
# If there is any problem in the middle of writting the metadata,
|
||||
# just remove all files from destdir of pkg.
|
||||
|
||||
for subpkg in ${subpackages}; do
|
||||
if [ -d "$XBPS_DESTDIR/${subpkg}-${version%_*}" ]; then
|
||||
rm -rf "$XBPS_DESTDIR/${subpkg}-${version%_*}"
|
||||
fi
|
||||
if [ -f ${wrksrc}/.xbps_do_install_${subpkg}_done ]; then
|
||||
rm -f ${wrksrc}/.xbps_do_install_${subpkg}_done
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -d "$XBPS_DESTDIR/${sourcepkg}-${version%_*}" ]; then
|
||||
rm -rf "$XBPS_DESTDIR/${sourcepkg}-${version%_*}"
|
||||
fi
|
||||
msg_red "Removed '${sourcepkg}-${version}' files from DESTDIR..."
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
func="$1"
|
||||
local func="$1"
|
||||
local rval logpipe logfile
|
||||
|
||||
[ -z "$func" ] && return 1
|
||||
|
||||
if $(type $func | grep -q 'function'); then
|
||||
$func
|
||||
return $?
|
||||
var_is_a_function $func
|
||||
if [ $? -eq 1 ]; then
|
||||
logpipe=/tmp/logpipe.$$
|
||||
if [ -d "${wrksrc}" ]; then
|
||||
logfile=${wrksrc}/.xbps_${func}.log
|
||||
else
|
||||
logfile=$(mktemp -t xbps_${func}_${pkgname}.log.XXXXXXXX)
|
||||
fi
|
||||
mkfifo "$logpipe"
|
||||
exec 3>&1
|
||||
tee "$logfile" < "$logpipe" &
|
||||
exec 1>"$logpipe" 2>"$logpipe"
|
||||
set -e
|
||||
trap "run_func_error $func" 0
|
||||
$func 2>&1
|
||||
set +e
|
||||
trap '' 0
|
||||
exec 1>&3 2>&3 3>&-
|
||||
rm -f "$logpipe"
|
||||
return 0
|
||||
fi
|
||||
return 255 # function not found.
|
||||
}
|
||||
|
|
|
@ -27,6 +27,36 @@
|
|||
# Runs the "configure" phase for a pkg. This setups the Makefiles or any
|
||||
# other stuff required to be able to build binaries or such.
|
||||
#
|
||||
do_gnu_configure()
|
||||
{
|
||||
#
|
||||
# Packages using GNU autoconf
|
||||
#
|
||||
env LDFLAGS="$LDFLAGS $conf_ldflags" \
|
||||
${configure_script} --prefix=/usr --sysconfdir=/etc \
|
||||
--infodir=/usr/share/info --mandir=/usr/share/man \
|
||||
${configure_args}
|
||||
}
|
||||
|
||||
do_configure()
|
||||
{
|
||||
#
|
||||
# Packages using custom configure scripts.
|
||||
#
|
||||
env LDFLAGS="$LDFLAGS $conf_ldflags" ${configure_script} \
|
||||
${configure_args}
|
||||
}
|
||||
|
||||
do_perl_configure()
|
||||
{
|
||||
#
|
||||
# Packages that are perl modules and use Makefile.PL files.
|
||||
# They are all handled by the helper perl-module.sh.
|
||||
#
|
||||
. $XBPS_HELPERSDIR/perl-module.sh
|
||||
perl_module_build $pkgname
|
||||
}
|
||||
|
||||
configure_src_phase()
|
||||
{
|
||||
local f lver error=0
|
||||
|
@ -60,12 +90,8 @@ configure_src_phase()
|
|||
|
||||
# Run pre_configure func.
|
||||
if [ ! -f $XBPS_PRECONFIGURE_DONE ]; then
|
||||
run_func pre_configure 2>${wrksrc}/.xbps_pre_configure.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "Package '$pkgname': pre_configure phase failed! errors below:"
|
||||
cat $wrksrc/.xbps_pre_configure.log
|
||||
exit 1
|
||||
elif [ $? -eq 0 ]; then
|
||||
run_func pre_configure
|
||||
if [ $? -eq 0 ]; then
|
||||
msg_normal "Package '$pkgname': pre_configure phase done."
|
||||
touch -f $XBPS_PRECONFIGURE_DONE
|
||||
fi
|
||||
|
@ -90,52 +116,23 @@ configure_src_phase()
|
|||
fi
|
||||
|
||||
case "$build_style" in
|
||||
gnu_configure|gnu-configure)
|
||||
#
|
||||
# Packages using GNU autoconf
|
||||
#
|
||||
env LDFLAGS="$LDFLAGS $conf_ldflags" \
|
||||
${configure_script} --prefix=/usr --sysconfdir=/etc \
|
||||
--infodir=/usr/share/info --mandir=/usr/share/man \
|
||||
${configure_args} || error=$?
|
||||
;;
|
||||
configure)
|
||||
#
|
||||
# Packages using custom configure scripts.
|
||||
#
|
||||
env LDFLAGS="$LDFLAGS $conf_ldflags" ${configure_script} \
|
||||
${configure_args} || error=$?
|
||||
;;
|
||||
perl-module|perl_module)
|
||||
#
|
||||
# Packages that are perl modules and use Makefile.PL files.
|
||||
# They are all handled by the helper perl-module.sh.
|
||||
#
|
||||
. $XBPS_HELPERSDIR/perl-module.sh
|
||||
perl_module_build $pkgname || error=$?
|
||||
;;
|
||||
gnu_configure|gnu-configure) run_func do_gnu_configure ;;
|
||||
configure) run_func do_configure ;;
|
||||
perl-module|perl_module) run_func do_perl_configure ;;
|
||||
*)
|
||||
#
|
||||
# Unknown build_style type won't work :-)
|
||||
#
|
||||
msg_error "package '$pkgname': unknown build_style [$build_style]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$build_style" != "perl_module" -a "$error" -ne 0 ]; then
|
||||
msg_error "package '$pkgname': configure stage failed!"
|
||||
fi
|
||||
msg_normal "Package '$pkgname ($lver)': configure phase done."
|
||||
|
||||
# Run post_configure func.
|
||||
if [ ! -f $XBPS_POSTCONFIGURE_DONE ]; then
|
||||
run_func post_configure 2>${wrksrc}/.xbps_post_configure.log
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_red "Package '$pkgname': post_configure phase failed! errors below:"
|
||||
cat $wrksrc/.xbps_post_configure.log
|
||||
exit 1
|
||||
elif [ $? -eq 0 ]; then
|
||||
run_func post_configure
|
||||
if [ $? -eq 0 ]; then
|
||||
msg_normal "Package '$pkgname': post_configure phase done."
|
||||
touch -f $XBPS_POSTCONFIGURE_DONE
|
||||
fi
|
||||
|
|
|
@ -70,7 +70,7 @@ fetch_distfiles()
|
|||
|
||||
if [ -n "$nofetch" ]; then
|
||||
msg_normal "Package '$pkgname ($lver)': running do_fetch phase."
|
||||
cd ${XBPS_BUILDDIR} && run_func do_fetch 2>/dev/null && return $?
|
||||
cd ${XBPS_BUILDDIR} && run_func do_fetch && return $?
|
||||
fi
|
||||
|
||||
cd $XBPS_SRCDISTDIR || return 1
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#-
|
||||
|
||||
. ${XBPS_SHUTILSDIR}/tmpl_funcs.sh
|
||||
. ${XBPS_SHUTILSDIR}/common_funcs.sh
|
||||
|
||||
#
|
||||
# Installs a pkg by reading its build template file.
|
||||
|
@ -62,10 +63,7 @@ install_pkg()
|
|||
#
|
||||
if [ -z "$doing_deps" ]; then
|
||||
install_dependencies_pkg $pkg
|
||||
if [ $? -eq 1 ]; then
|
||||
msg_red "cannot install pkgdeps for '$pkg'!"
|
||||
return 1
|
||||
fi
|
||||
[ $? -eq 1 ] && return 1
|
||||
#
|
||||
# At this point all required deps are installed, and
|
||||
# only remaining is the origin package; install it.
|
||||
|
@ -110,10 +108,9 @@ install_pkg()
|
|||
|
||||
# Install pkg into destdir.
|
||||
env xbps_machine=${xbps_machine} MASTERDIR=${_MASTERDIR} \
|
||||
dontrm_builddir=${dontrm_builddir} wrksrc=${wrksrc} \
|
||||
wrksrc=${wrksrc} \
|
||||
${fakeroot_cmd} ${fakeroot_cmd_args} \
|
||||
@@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-doinst-helper \
|
||||
${curpkgn}
|
||||
@@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-doinst-helper ${curpkgn}
|
||||
if [ $? -ne 0 ]; then
|
||||
msg_red "xbps-src-doinst-helper failed for '$pkgname'!"
|
||||
return 1
|
||||
|
@ -127,11 +124,14 @@ install_pkg()
|
|||
|
||||
# Always write metadata to package's destdir.
|
||||
. $XBPS_SHUTILSDIR/metadata.sh
|
||||
trap 'remove_pkgdestdir_sighandler ${pkgname}' 0 INT
|
||||
xbps_write_metadata_pkg
|
||||
if [ $? -ne 0 ]; then
|
||||
msg_red "cannot write package metadata for '$pkgname'!"
|
||||
trap '' 0 INT
|
||||
return 1
|
||||
fi
|
||||
trap '' 0 INT
|
||||
|
||||
[ "$install_destdir_target" = "yes" ] && return 0
|
||||
|
||||
|
@ -142,6 +142,13 @@ install_pkg()
|
|||
msg_red "cannot stow '$pkgname'!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Remove $wrksrc if -C not specified.
|
||||
#
|
||||
if [ -d "$wrksrc" -a "$dontrm_builddir" = "no" ]; then
|
||||
remove_tmpl_wrksrc $wrksrc
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
|
|
|
@ -151,11 +151,8 @@ stow_pkg_real()
|
|||
# Register pkg in plist file.
|
||||
#
|
||||
$XBPS_PKGDB_CMD register $pkgname $lver "$short_desc" || return $?
|
||||
|
||||
run_func post_stow 2>/dev/null
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_error "Package '$pkgname': post_stow phase failed!"
|
||||
fi
|
||||
run_func post_stow
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -191,11 +188,7 @@ unstow_pkg_real()
|
|||
elif [ ! -w ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
|
||||
msg_error "$pkgname cannot be removed (permission denied)."
|
||||
elif [ -s ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
|
||||
run_func pre_remove 2>/dev/null
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_error "Package '$pkgname': pre_remove stage failed!"
|
||||
fi
|
||||
|
||||
run_func pre_remove
|
||||
# Remove installed files.
|
||||
for f in $(cat ${XBPS_PKGMETADIR}/${pkgname}/flist); do
|
||||
if [ -f $XBPS_MASTERDIR/$f -o -h $XBPS_MASTERDIR/$f ]; then
|
||||
|
@ -216,11 +209,7 @@ unstow_pkg_real()
|
|||
done
|
||||
fi
|
||||
|
||||
run_func post_remove 2>/dev/null
|
||||
if [ $? -ne 0 -a $? -ne 255 ]; then
|
||||
msg_error "Package '$pkgname': post_remove phase failed!"
|
||||
fi
|
||||
|
||||
run_func post_remove
|
||||
# Remove metadata dir.
|
||||
rm -rf $XBPS_PKGMETADIR/$pkgname
|
||||
|
||||
|
|
Loading…
Reference in a new issue