xbps-src: massive rewrite of builddeps resolving code.

This speeds up the process of resolving builddeps with
XBPS_PREFER_BINPKG_DEPS enabled and disabled by ~15% aproximately.

This fixes also some bugs I've found while building a massive rebuild
of all packages with XBPS_PREFER_BINPKG_DEPS enabled.
This commit is contained in:
Juan RP 2011-07-01 17:48:29 +02:00
parent a09089a9b0
commit 5d7873a5b2
5 changed files with 99 additions and 82 deletions

View file

@ -1,5 +1,5 @@
#- #-
# Copyright (c) 2008-2010 Juan Romero Pardines. # Copyright (c) 2008-2011 Juan Romero Pardines.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -54,18 +54,49 @@ install_pkg_from_repos()
return $rval return $rval
} }
autoremove_binpkgs() autoremove_pkg_dependencies()
{ {
local cmd local cmd saved_pkgname x f found
cmd="${fakeroot_cmd} ${fakeroot_cmd_args} ${XBPS_BIN_CMD}" cmd="${fakeroot_cmd} ${fakeroot_cmd_args} ${XBPS_BIN_CMD}"
# If XBPS_PREFER_BINPKG_DEPS is set, we should remove those # If XBPS_PREFER_BINPKG_DEPS is set, we should remove those
# package dependencies installed by the target package, do it. # package dependencies installed by the target package, do it.
# #
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$doing_deps" ]; then if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$base_chroot" \
-a -z "$INSTALLING_DEPS" ]; then
msg_normal "'$pkgname': removing automatically installed dependencies ...\n" msg_normal "'$pkgname': removing automatically installed dependencies ...\n"
# Autoremove installed binary packages.
${cmd} -y reconfigure all && ${cmd} -Rpyf autoremove 2>&1 >/dev/null ${cmd} -y reconfigure all && ${cmd} -Rpyf autoremove 2>&1 >/dev/null
if [ $? -ne 0 ]; then
msg_error "'$pkgname': failed to remove automatic dependencies!\n"
fi
# Maybe some dependency wasn't available in repositories and it had
# to be built from source, remove them too.
saved_pkgname=$pkgname
for f in $($XBPS_BIN_CMD list|awk '{print $1}'); do
pkgname=$($XBPS_PKGDB_CMD getpkgname $f)
[ "$pkgname" = "$saved_pkgname" ] && continue
if [ -f $XBPS_PKGMETADIR/$pkgname/flist ]; then
setup_tmpl $pkgname
for x in ${subpackages}; do
if [ "$pkgname" = "$x" ]; then
found=1
break;
fi
done
if [ -n "$found" ]; then
# ignore subpkgs.
unset found
continue
fi
# remove pkg.
. ${XBPS_SHUTILSDIR}/pkgtarget_funcs.sh
msg_warn "removing package $pkgname installed from source...\n"
remove_pkg
fi
done
setup_tmpl $saved_pkgname
fi fi
} }
@ -87,6 +118,9 @@ install_pkg_deps()
curpkgname="$(${XBPS_PKGDB_CMD} getpkgdepname ${curpkg})" curpkgname="$(${XBPS_PKGDB_CMD} getpkgdepname ${curpkg})"
fi fi
check_pkgdep_matched "$curpkg"
[ $? -eq 0 ] && return 0
if [ -z "$saved_prevpkg" -a -n "${_ORIGINPKG}" ]; then if [ -z "$saved_prevpkg" -a -n "${_ORIGINPKG}" ]; then
msg_normal "Installing '${_ORIGINPKG}' dependency: '$curpkg'.\n" msg_normal "Installing '${_ORIGINPKG}' dependency: '$curpkg'.\n"
else else
@ -116,14 +150,29 @@ install_pkg_deps()
check_pkgdep_matched "${j}" check_pkgdep_matched "${j}"
[ $? -eq 0 ] && continue [ $? -eq 0 ] && continue
prev_pkg="$j"
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$base_chroot" ]; then
install_pkg_from_repos ${j}
if [ $? -eq 255 ]; then
# xbps-bin returned unexpected error
msg_red "$saved_prevpkg: failed to install dependency '$j'\n"
elif [ $? -eq 0 ]; then
# package installed successfully.
:
continue
fi
fi
# #
# Iterate again, this will check if there are more # Iterate again, this will check if there are more
# required deps for current pkg. # required deps for current pkg.
# #
prev_pkg="$j"
install_pkg_deps "${j}" "${curpkg}" install_pkg_deps "${j}" "${curpkg}"
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
msg_red "install_pkg_deps: cannot install '$curpkg' ($j).\n" if [ -n "$saved_prevpkg" ]; then
msg_red "'$saved_prevpkg': failed to install dependency '$curpkg'\n"
else
msg_red "'${_ORIGINPKG}': failed to install dependency '$curpkg'\n"
fi
return 1 return 1
fi fi
done done
@ -137,19 +186,19 @@ install_pkg_deps()
# Package not found, build from source. # Package not found, build from source.
install_pkg "${curpkgname}" install_pkg "${curpkgname}"
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
msg_red "cannot install '$curpkgname'!\n" msg_red "'$saved_prevpkg': failed to install dependency '$curpkg'\n"
return 1 return 1
fi fi
fi fi
else else
if [ -n "$saved_prevpkg" ]; then if [ -n "$saved_prevpkg" ]; then
msg_normal "Installing package '${curpkgname}' required by '${saved_prevpkg}'.\n" msg_normal "'$saved_prevpkg': installing dependency '$curpkg'...\n"
else else
msg_normal "Installing package: '${curpkg}'.\n" msg_normal "'${_ORIGINPKG}': installing dependency '$curpkg'...\n"
fi fi
install_pkg "${curpkgname}" install_pkg "${curpkgname}"
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
msg_red "install_pkg_deps: cannot install '$curpkgname'!\n" msg_red "'$saved_prevpkg': failed to install dependency '$curpkg'\n"
return 1 return 1
fi fi
fi fi
@ -166,8 +215,9 @@ install_dependencies_pkg()
local i j pkgn iver reqver notinstalled_deps lver local i j pkgn iver reqver notinstalled_deps lver
[ -z "$pkg" ] && return 2 [ -z "$pkg" ] && return 2
[ -z "$build_depends" ] && return 0
doing_deps=true INSTALLING_DEPS=1
if [ -n "$revision" ]; then if [ -n "$revision" ]; then
lver="${version}_${revision}" lver="${version}_${revision}"
@ -175,9 +225,8 @@ install_dependencies_pkg()
lver="${version}" lver="${version}"
fi fi
if [ -n "$build_depends" ]; then msg_normal "'$pkgname-$lver': required build dependencies...\n"
msg_normal "'$pkgname-$lver': required package build dependencies...\n"
fi
for i in ${build_depends}; do for i in ${build_depends}; do
pkgn="$($XBPS_PKGDB_CMD getpkgdepname ${i})" pkgn="$($XBPS_PKGDB_CMD getpkgdepname ${i})"
iver="$($XBPS_PKGDB_CMD version $pkgn)" iver="$($XBPS_PKGDB_CMD version $pkgn)"
@ -190,8 +239,7 @@ install_dependencies_pkg()
fi fi
done done
[ -z "$notinstalled_deps" ] && return 0 # Install direct build dependencies from binary packages.
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$base_chroot" ]; then if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$base_chroot" ]; then
msg_normal "'$pkg': installing dependencies from repositories ...\n" msg_normal "'$pkg': installing dependencies from repositories ...\n"
for i in ${notinstalled_deps}; do for i in ${notinstalled_deps}; do
@ -199,7 +247,7 @@ install_dependencies_pkg()
rval=$? rval=$?
if [ $rval -eq 255 ]; then if [ $rval -eq 255 ]; then
# xbps-bin returned unexpected error (-1) # xbps-bin returned unexpected error (-1)
msg_error "'${pkg}': failed to install required dependencies!\n" msg_error "'${lpkgname}': failed to install dependency: '$i'.\n"
elif [ $rval -eq 0 ]; then elif [ $rval -eq 0 ]; then
# Install successfully # Install successfully
continue continue
@ -207,51 +255,18 @@ install_dependencies_pkg()
done done
fi fi
# Install direct and indirect build dependencies from source.
for j in ${notinstalled_deps}; do for j in ${notinstalled_deps}; do
pkgn=$($XBPS_PKGDB_CMD getpkgdepname ${j}) install_pkg_deps "${j}" "${pkg}"
check_pkgdep_matched "${j}"
[ $? -eq 0 ] && continue
setup_tmpl "$pkgn"
check_build_depends_pkg
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
msg_normal "Installing '$lpkgname' dependency: '$pkgn'.\n" return 1
if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$base_chroot" ]; then
install_pkg_from_repos ${j}
rval=$?
if [ $rval -eq 255 ]; then
# xbps-bin returned unexpected error
return $?
elif [ $rval -eq 0 ]; then
# installed successfully
continue
else
# package not found, build source.
install_pkg "${pkgn}"
if [ $? -eq 1 ]; then
msg_red "cannot install '$pkgn'!\n"
return 1
fi
fi
else
install_pkg "${pkgn}"
if [ $? -eq 1 ]; then
msg_red "cannot install '$pkgn'!\n"
return 1
fi
fi
else
install_pkg_deps "${j}" "${pkg}"
if [ $? -eq 1 ]; then
msg_red "cannot install pkgdeps required by $pkg ($j).\n"
return 1
fi
fi fi
done done
} }
# #
# Checks if installed pkg dependency is matched against pattern. # Returns 0 if pkgpattern in $1 is matched against current installed
# package, 1 otherwise.
# #
check_pkgdep_matched() check_pkgdep_matched()
{ {
@ -272,7 +287,8 @@ check_pkgdep_matched()
} }
# #
# Check if installed package is installed. # Returns 0 if pkgpattern in $1 is installed and greater than current
# installed package, otherwise 1.
# #
check_installed_pkg() check_installed_pkg()
{ {
@ -293,8 +309,7 @@ check_installed_pkg()
} }
# #
# Checks the build depends db file and returns 0 if pkg has dependencies, # Returns 0 if pkg has build deps, 1 otherwise.
# otherwise returns 1.
# #
check_build_depends_pkg() check_build_depends_pkg()
{ {

View file

@ -212,12 +212,10 @@ prepare_binpkg_repos()
done done
# XBPS utils >= 0.9.0. # XBPS utils >= 0.9.0.
msg_normal "Synchronizing index for remote repositories...\n" msg_normal "Synchronizing index for remote repositories...\n"
${chroot_cmd} ${XBPS_MASTERDIR} sh -c \ ${XBPS_REPO_CMD} sync
"${XBPS_REPO_CMD} -C /usr/local/etc/xbps-conf.plist sync"
else else
for repo in ${XBPS_REPO_LIST}; do for repo in ${XBPS_REPO_LIST}; do
${chroot_cmd} ${XBPS_MASTERDIR} sh -c \ ${XBPS_REPO_CMD} add ${repo} 2>/dev/null
"${XBPS_REPO_CMD} add ${repo}" 2>/dev/null
[ $? -ne 0 ] && \ [ $? -ne 0 ] && \
msg_warn "Failed to sync pkg-index from ${repo}\n" msg_warn "Failed to sync pkg-index from ${repo}\n"
done done

View file

@ -1,5 +1,5 @@
#- #-
# Copyright (c) 2008-2010 Juan Romero Pardines. # Copyright (c) 2008-2011 Juan Romero Pardines.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -68,11 +68,8 @@ remove_pkgdestdir_sighandler()
if [ -d "$XBPS_DESTDIR/${sourcepkg}-${version%_*}" ]; then if [ -d "$XBPS_DESTDIR/${sourcepkg}-${version%_*}" ]; then
rm -rf "$XBPS_DESTDIR/${sourcepkg}-${version%_*}" rm -rf "$XBPS_DESTDIR/${sourcepkg}-${version%_*}"
msg_red "'${sourcepkg}-${lver}': removed files from DESTDIR...\n"
fi fi
msg_red "'${sourcepkg}-${lver}': removed files from DESTDIR...\n"
. ${XBPS_SHUTILSDIR}/builddep_funcs.sh
autoremove_binpkgs
} }
var_is_a_function() var_is_a_function()
@ -144,6 +141,9 @@ msg_red()
msg_error() msg_error()
{ {
msg_red "$@" msg_red "$@"
. $XBPS_SHUTILSDIR/builddep_funcs.sh
autoremove_pkg_dependencies
exit 1 exit 1
} }

View file

@ -1,5 +1,5 @@
#- #-
# Copyright (c) 2008-2010 Juan Romero Pardines. # Copyright (c) 2008-2011 Juan Romero Pardines.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -43,7 +43,13 @@ install_pkg()
fi fi
pkg="$curpkgn-$version" pkg="$curpkgn-$version"
[ -n "$doing_deps" ] && setup_tmpl $curpkgn [ -n "$INSTALLING_DEPS" ] && setup_tmpl $curpkgn
#
# Fetch distfiles before checking its dependencies.
#
. $XBPS_SHUTILSDIR/fetch_funcs.sh
fetch_distfiles
# #
# Refuse to install the same package that is already installed. # Refuse to install the same package that is already installed.
@ -61,14 +67,14 @@ install_pkg()
# #
# Install dependencies required by this package. # Install dependencies required by this package.
# #
if [ -z "$doing_deps" ]; then if [ -z "$INSTALLING_DEPS" ]; then
install_dependencies_pkg $pkg install_dependencies_pkg $pkg
[ $? -eq 1 ] && return 1 [ $? -eq 1 ] && return 1
# #
# At this point all required deps are installed, and # At this point all required deps are installed, and
# only remaining is the origin package; install it. # only remaining is the origin package; install it.
# #
unset doing_deps unset INSTALLING_DEPS
setup_tmpl $curpkgn setup_tmpl $curpkgn
msg_normal "Installing '$pkgname'...\n" msg_normal "Installing '$pkgname'...\n"
fi fi
@ -76,8 +82,6 @@ install_pkg()
# #
# Fetch, extract, build and install into the destination directory. # Fetch, extract, build and install into the destination directory.
# #
. $XBPS_SHUTILSDIR/fetch_funcs.sh
fetch_distfiles
if [ ! -f "$XBPS_EXTRACT_DONE" ]; then if [ ! -f "$XBPS_EXTRACT_DONE" ]; then
. $XBPS_SHUTILSDIR/extract_funcs.sh . $XBPS_SHUTILSDIR/extract_funcs.sh
@ -112,7 +116,6 @@ install_pkg()
${fakeroot_cmd} ${fakeroot_cmd_args} \ ${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 if [ $? -ne 0 ]; then
msg_red "xbps-src-doinst-helper failed for '$pkgname'!\n"
return 1 return 1
fi fi
@ -167,8 +170,12 @@ install_pkg()
remove_tmpl_wrksrc $wrksrc remove_tmpl_wrksrc $wrksrc
fi fi
#
# Autoremove packages installed as dependencies if
# XBPS_PREFER_BINPKG_DEPS is set.
#
. ${XBPS_SHUTILSDIR}/builddep_funcs.sh . ${XBPS_SHUTILSDIR}/builddep_funcs.sh
autoremove_binpkgs autoremove_pkg_dependencies
return $? return $?
} }

View file

@ -1,5 +1,5 @@
#- #-
# Copyright (c) 2008-2010 Juan Romero Pardines. # Copyright (c) 2008-2011 Juan Romero Pardines.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -183,11 +183,8 @@ unstow_pkg_real()
# If it's a metapkg, do nothing. # If it's a metapkg, do nothing.
: :
elif [ ! -f ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then elif [ ! -f ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
# If flist not found, perhaps the pkg has been installed via msg_warn "$pkgname wasn't installed from source!\n"
# xbps-bin, so try to remove it. return 0
${XBPS_BIN_CMD} -pyf remove ${pkgname} || \
msg_error "${pkgname}: failed to remove!\n"
return $?
elif [ ! -w ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then elif [ ! -w ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
msg_error "$pkgname cannot be removed (permission denied).\n" msg_error "$pkgname cannot be removed (permission denied).\n"
elif [ -s ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then elif [ -s ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then
@ -214,7 +211,7 @@ unstow_pkg_real()
run_func post_remove run_func post_remove
# Remove metadata dir. # Remove metadata dir.
rm -rf $XBPS_PKGMETADIR/$pkgname [ -d $XBPS_PKGMETADIR/$pkgname ] && rm -rf $XBPS_PKGMETADIR/$pkgname
# Unregister pkg from plist file. # Unregister pkg from plist file.
$XBPS_PKGDB_CMD unregister $pkgname $ver $XBPS_PKGDB_CMD unregister $pkgname $ver