void-packages/xbps-src/shutils/pkgtarget_funcs.sh.in
Juan RP 5d7873a5b2 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.
2011-07-01 17:48:29 +02:00

230 lines
6 KiB
Bash

#-
# Copyright (c) 2008-2011 Juan Romero Pardines.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-
. ${XBPS_SHUTILSDIR}/tmpl_funcs.sh
. ${XBPS_SHUTILSDIR}/common_funcs.sh
#
# Installs a pkg by reading its build template file.
#
install_pkg()
{
local curpkgn="$1" fullpkg pkg cdestdir
#
# If we are being invoked through the chroot, re-read config file
# to get correct stuff.
#
if [ -n "$in_chroot" ]; then
check_config_vars
set_defvars
fi
pkg="$curpkgn-$version"
[ -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.
#
. $XBPS_SHUTILSDIR/builddep_funcs.sh
check_installed_pkg "$pkg"
if [ $? -eq 1 -o $? -eq 0 ]; then
instver="$($XBPS_PKGDB_CMD version $pkgname)"
if [ -n "$instver" ]; then
echo "=> $pkgname-$instver already installed."
return 0
fi
fi
#
# Install dependencies required by this package.
#
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 INSTALLING_DEPS
setup_tmpl $curpkgn
msg_normal "Installing '$pkgname'...\n"
fi
#
# Fetch, extract, build and install into the destination directory.
#
if [ ! -f "$XBPS_EXTRACT_DONE" ]; then
. $XBPS_SHUTILSDIR/extract_funcs.sh
extract_distfiles
if [ $? -ne 0 ]; then
msg_red "cannot extract distfiles for '$pkgname'!\n"
return 1
fi
fi
if [ ! -f "$XBPS_CONFIGURE_DONE" ]; then
. $XBPS_SHUTILSDIR/configure_funcs.sh
configure_src_phase
if [ $? -ne 0 ]; then
msg_red "cannot configure '$pkgname'!\n"
return 1
fi
fi
if [ ! -f "$XBPS_BUILD_DONE" ]; then
. $XBPS_SHUTILSDIR/build_funcs.sh
build_src_phase
if [ $? -ne 0 ]; then
msg_red "cannot build '$pkgname'!\n"
return 1
fi
fi
# Install pkg into destdir.
env xbps_machine=${xbps_machine} MASTERDIR=${_MASTERDIR} \
wrksrc=${wrksrc} \
${fakeroot_cmd} ${fakeroot_cmd_args} \
@@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-doinst-helper ${curpkgn}
if [ $? -ne 0 ]; then
return 1
fi
# Strip binaries/libraries.
if [ -z "$noarch" ]; then
. $XBPS_SHUTILSDIR/strip_files.sh
strip_files
fi
# Always write metadata to package's destdir.
. $XBPS_SHUTILSDIR/metadata.sh
trap 'remove_pkgdestdir_sighandler ${pkgname}' INT
xbps_write_metadata_pkg
if [ $? -ne 0 ]; then
msg_red "cannot write package metadata for '$pkgname'!\n"
trap - INT
return 1
fi
trap - INT
[ "$install_destdir_target" = "yes" ] && return 0
# Stow package into masterdir.
. $XBPS_SHUTILSDIR/stow_funcs.sh
stow_pkg_handler stow
if [ $? -ne 0 ]; then
msg_red "cannot stow '$pkgname'!\n"
return 1
fi
# Copy generated pkg metadata files into its metadata dir.
if [ ! -f ${DESTDIR}/files.plist ]; then
msg_error "${pkgname}: missing metadata files.plist!"
fi
cp -f ${DESTDIR}/files.plist ${XBPS_PKGMETADIR}/${pkgname}
if [ ! -f ${DESTDIR}/props.plist ]; then
msg_error "${pkgname}: missing metadata props.plist!"
fi
cp -f ${DESTDIR}/props.plist ${XBPS_PKGMETADIR}/${pkgname}
if [ -f ${DESTDIR}/INSTALL ]; then
install -m750 ${DESTDIR}/INSTALL \
${XBPS_PKGMETADIR}/${pkgname}
fi
if [ -f ${DESTDIR}/REMOVE ]; then
install -m750 ${DESTDIR}/REMOVE \
${XBPS_PKGMETADIR}/${pkgname}
fi
#
# Remove $wrksrc if -C not specified.
#
if [ -d "$wrksrc" -a "$dontrm_builddir" = "no" ]; then
remove_tmpl_wrksrc $wrksrc
fi
#
# Autoremove packages installed as dependencies if
# XBPS_PREFER_BINPKG_DEPS is set.
#
. ${XBPS_SHUTILSDIR}/builddep_funcs.sh
autoremove_pkg_dependencies
return $?
}
#
# Lists files installed by a package.
#
list_pkg_files()
{
local pkg="$1" ver=
[ -z $pkg ] && msg_error "unexistent package, aborting.\n"
ver=$($XBPS_PKGDB_CMD version $pkg)
[ -z "$ver" ] && msg_error "$pkg is not installed.\n"
cat $XBPS_PKGMETADIR/$pkg/flist
}
#
# Removes a currently installed package (unstow + removed from destdir).
#
remove_pkg()
{
local subpkg ver
[ -z $pkgname ] && msg_error "unexistent package, aborting.\n"
ver=$($XBPS_PKGDB_CMD version $pkgname)
. $XBPS_SHUTILSDIR/stow_funcs.sh
stow_pkg_handler unstow || return $?
for subpkg in ${subpackages}; do
if [ -d "$XBPS_DESTDIR/${subpkg}-${ver%_*}" ]; then
rm -rf "$XBPS_DESTDIR/${subpkg}-${ver%_*}"
fi
# Remove leftover files in $wrksrc.
if [ -f "${wrksrc}/.xbps_do_install_${subpkg}_done" ]; then
rm -f ${wrksrc}/.xbps_do_install_${subpkg}_done
fi
done
if [ -d "$XBPS_DESTDIR/${pkgname}-${ver%_*}" ]; then
rm -rf "$XBPS_DESTDIR/${pkgname}-${ver%_*}"
fi
[ -f $XBPS_PRE_INSTALL_DONE ] && rm -f $XBPS_PRE_INSTALL_DONE
[ -f $XBPS_POST_INSTALL_DONE ] && rm -f $XBPS_POST_INSTALL_DONE
[ -f $XBPS_INSTALL_DONE ] && rm -f $XBPS_INSTALL_DONE
return $?
}