From 5d7873a5b24aab96c6147570b9be1aa59e8937d1 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 1 Jul 2011 17:48:29 +0200 Subject: [PATCH] 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. --- xbps-src/shutils/builddep_funcs.sh | 131 ++++++++++++++----------- xbps-src/shutils/chroot.sh.in | 6 +- xbps-src/shutils/common_funcs.sh | 10 +- xbps-src/shutils/pkgtarget_funcs.sh.in | 23 +++-- xbps-src/shutils/stow_funcs.sh | 11 +-- 5 files changed, 99 insertions(+), 82 deletions(-) diff --git a/xbps-src/shutils/builddep_funcs.sh b/xbps-src/shutils/builddep_funcs.sh index 88b88bfaf2..c23a6030a8 100644 --- a/xbps-src/shutils/builddep_funcs.sh +++ b/xbps-src/shutils/builddep_funcs.sh @@ -1,5 +1,5 @@ #- -# Copyright (c) 2008-2010 Juan Romero Pardines. +# Copyright (c) 2008-2011 Juan Romero Pardines. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -54,18 +54,49 @@ install_pkg_from_repos() 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}" # If XBPS_PREFER_BINPKG_DEPS is set, we should remove those # 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" + # Autoremove installed binary packages. ${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 } @@ -87,6 +118,9 @@ install_pkg_deps() curpkgname="$(${XBPS_PKGDB_CMD} getpkgdepname ${curpkg})" fi + check_pkgdep_matched "$curpkg" + [ $? -eq 0 ] && return 0 + if [ -z "$saved_prevpkg" -a -n "${_ORIGINPKG}" ]; then msg_normal "Installing '${_ORIGINPKG}' dependency: '$curpkg'.\n" else @@ -116,14 +150,29 @@ install_pkg_deps() check_pkgdep_matched "${j}" [ $? -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 # required deps for current pkg. # - prev_pkg="$j" install_pkg_deps "${j}" "${curpkg}" 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 fi done @@ -137,19 +186,19 @@ install_pkg_deps() # Package not found, build from source. install_pkg "${curpkgname}" if [ $? -eq 1 ]; then - msg_red "cannot install '$curpkgname'!\n" + msg_red "'$saved_prevpkg': failed to install dependency '$curpkg'\n" return 1 fi fi else if [ -n "$saved_prevpkg" ]; then - msg_normal "Installing package '${curpkgname}' required by '${saved_prevpkg}'.\n" + msg_normal "'$saved_prevpkg': installing dependency '$curpkg'...\n" else - msg_normal "Installing package: '${curpkg}'.\n" + msg_normal "'${_ORIGINPKG}': installing dependency '$curpkg'...\n" fi install_pkg "${curpkgname}" 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 fi fi @@ -166,8 +215,9 @@ install_dependencies_pkg() local i j pkgn iver reqver notinstalled_deps lver [ -z "$pkg" ] && return 2 + [ -z "$build_depends" ] && return 0 - doing_deps=true + INSTALLING_DEPS=1 if [ -n "$revision" ]; then lver="${version}_${revision}" @@ -175,9 +225,8 @@ install_dependencies_pkg() lver="${version}" fi - if [ -n "$build_depends" ]; then - msg_normal "'$pkgname-$lver': required package build dependencies...\n" - fi + msg_normal "'$pkgname-$lver': required build dependencies...\n" + for i in ${build_depends}; do pkgn="$($XBPS_PKGDB_CMD getpkgdepname ${i})" iver="$($XBPS_PKGDB_CMD version $pkgn)" @@ -190,8 +239,7 @@ install_dependencies_pkg() fi done - [ -z "$notinstalled_deps" ] && return 0 - + # Install direct build dependencies from binary packages. if [ -n "$XBPS_PREFER_BINPKG_DEPS" -a -z "$base_chroot" ]; then msg_normal "'$pkg': installing dependencies from repositories ...\n" for i in ${notinstalled_deps}; do @@ -199,7 +247,7 @@ install_dependencies_pkg() rval=$? if [ $rval -eq 255 ]; then # 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 # Install successfully continue @@ -207,51 +255,18 @@ install_dependencies_pkg() done fi + # Install direct and indirect build dependencies from source. for j in ${notinstalled_deps}; do - pkgn=$($XBPS_PKGDB_CMD getpkgdepname ${j}) - check_pkgdep_matched "${j}" - [ $? -eq 0 ] && continue - - setup_tmpl "$pkgn" - check_build_depends_pkg + install_pkg_deps "${j}" "${pkg}" if [ $? -eq 1 ]; then - msg_normal "Installing '$lpkgname' dependency: '$pkgn'.\n" - 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 + return 1 fi 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() { @@ -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() { @@ -293,8 +309,7 @@ check_installed_pkg() } # -# Checks the build depends db file and returns 0 if pkg has dependencies, -# otherwise returns 1. +# Returns 0 if pkg has build deps, 1 otherwise. # check_build_depends_pkg() { diff --git a/xbps-src/shutils/chroot.sh.in b/xbps-src/shutils/chroot.sh.in index e8d6aa1d27..21554100cc 100644 --- a/xbps-src/shutils/chroot.sh.in +++ b/xbps-src/shutils/chroot.sh.in @@ -212,12 +212,10 @@ prepare_binpkg_repos() done # XBPS utils >= 0.9.0. msg_normal "Synchronizing index for remote repositories...\n" - ${chroot_cmd} ${XBPS_MASTERDIR} sh -c \ - "${XBPS_REPO_CMD} -C /usr/local/etc/xbps-conf.plist sync" + ${XBPS_REPO_CMD} sync else 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 ] && \ msg_warn "Failed to sync pkg-index from ${repo}\n" done diff --git a/xbps-src/shutils/common_funcs.sh b/xbps-src/shutils/common_funcs.sh index c8af9e9538..770ce22cbd 100644 --- a/xbps-src/shutils/common_funcs.sh +++ b/xbps-src/shutils/common_funcs.sh @@ -1,5 +1,5 @@ #- -# Copyright (c) 2008-2010 Juan Romero Pardines. +# Copyright (c) 2008-2011 Juan Romero Pardines. # All rights reserved. # # 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 rm -rf "$XBPS_DESTDIR/${sourcepkg}-${version%_*}" + msg_red "'${sourcepkg}-${lver}': removed files from DESTDIR...\n" fi - msg_red "'${sourcepkg}-${lver}': removed files from DESTDIR...\n" - - . ${XBPS_SHUTILSDIR}/builddep_funcs.sh - autoremove_binpkgs } var_is_a_function() @@ -144,6 +141,9 @@ msg_red() msg_error() { msg_red "$@" + . $XBPS_SHUTILSDIR/builddep_funcs.sh + autoremove_pkg_dependencies + exit 1 } diff --git a/xbps-src/shutils/pkgtarget_funcs.sh.in b/xbps-src/shutils/pkgtarget_funcs.sh.in index 3211469d26..9d8b7da8d5 100644 --- a/xbps-src/shutils/pkgtarget_funcs.sh.in +++ b/xbps-src/shutils/pkgtarget_funcs.sh.in @@ -1,5 +1,5 @@ #- -# Copyright (c) 2008-2010 Juan Romero Pardines. +# Copyright (c) 2008-2011 Juan Romero Pardines. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -43,7 +43,13 @@ install_pkg() fi 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. @@ -61,14 +67,14 @@ install_pkg() # # Install dependencies required by this package. # - if [ -z "$doing_deps" ]; then + if [ -z "$INSTALLING_DEPS" ]; then install_dependencies_pkg $pkg [ $? -eq 1 ] && return 1 # # At this point all required deps are installed, and # only remaining is the origin package; install it. # - unset doing_deps + unset INSTALLING_DEPS setup_tmpl $curpkgn msg_normal "Installing '$pkgname'...\n" fi @@ -76,8 +82,6 @@ install_pkg() # # Fetch, extract, build and install into the destination directory. # - . $XBPS_SHUTILSDIR/fetch_funcs.sh - fetch_distfiles if [ ! -f "$XBPS_EXTRACT_DONE" ]; then . $XBPS_SHUTILSDIR/extract_funcs.sh @@ -112,7 +116,6 @@ install_pkg() ${fakeroot_cmd} ${fakeroot_cmd_args} \ @@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-doinst-helper ${curpkgn} if [ $? -ne 0 ]; then - msg_red "xbps-src-doinst-helper failed for '$pkgname'!\n" return 1 fi @@ -167,8 +170,12 @@ install_pkg() remove_tmpl_wrksrc $wrksrc fi + # + # Autoremove packages installed as dependencies if + # XBPS_PREFER_BINPKG_DEPS is set. + # . ${XBPS_SHUTILSDIR}/builddep_funcs.sh - autoremove_binpkgs + autoremove_pkg_dependencies return $? } diff --git a/xbps-src/shutils/stow_funcs.sh b/xbps-src/shutils/stow_funcs.sh index 1426b9d9bb..c3952ad2d6 100644 --- a/xbps-src/shutils/stow_funcs.sh +++ b/xbps-src/shutils/stow_funcs.sh @@ -1,5 +1,5 @@ #- -# Copyright (c) 2008-2010 Juan Romero Pardines. +# Copyright (c) 2008-2011 Juan Romero Pardines. # All rights reserved. # # 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. : elif [ ! -f ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then - # If flist not found, perhaps the pkg has been installed via - # xbps-bin, so try to remove it. - ${XBPS_BIN_CMD} -pyf remove ${pkgname} || \ - msg_error "${pkgname}: failed to remove!\n" - return $? + msg_warn "$pkgname wasn't installed from source!\n" + return 0 elif [ ! -w ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then msg_error "$pkgname cannot be removed (permission denied).\n" elif [ -s ${XBPS_PKGMETADIR}/${pkgname}/flist ]; then @@ -214,7 +211,7 @@ unstow_pkg_real() run_func post_remove # Remove metadata dir. - rm -rf $XBPS_PKGMETADIR/$pkgname + [ -d $XBPS_PKGMETADIR/$pkgname ] && rm -rf $XBPS_PKGMETADIR/$pkgname # Unregister pkg from plist file. $XBPS_PKGDB_CMD unregister $pkgname $ver