xbps-src: refactor build logic into its own script (build.sh).

The build.sh script is now responsible to handle all the logic to build
a source package and its subpackages, as well as all its required
build dependencies. Thanks to this and subshells, dependencies are now
built into its own child process, creating a process tree that can go
nested as long as your system allows forking and has enough memory :-)

This fixes some issues that have been while building pkgs that have lots
of nested dependencies.
This commit is contained in:
Juan RP 2015-03-14 07:50:05 +01:00
parent 018e0086c4
commit 849d22e46d
10 changed files with 152 additions and 152 deletions

104
common/xbps-src/libexec/build.sh Executable file
View file

@ -0,0 +1,104 @@
#!/bin/bash
#
# vim: set ts=4 sw=4 et:
#
# Passed arguments:
# $1 - current pkgname to build [REQUIRED]
# $2 - target pkgname (origin) to build [REQUIRED]
# $3 - xbps target [REQUIRED]
# $4 - cross target [OPTIONAL]
if [ $# -lt 3 -o $# -gt 4 ]; then
echo "$(basename $0): invalid number of arguments: pkgname targetpkg target [cross-target]"
exit 1
fi
readonly PKGNAME="$1"
readonly TARGET_PKG="$2"
readonly TARGET="$3"
readonly XBPS_CROSS_BUILD="$4"
for f in $XBPS_SHUTILSDIR/*.sh; do
. $f
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
show_pkg_build_options
check_pkg_arch $XBPS_CROSS_BUILD
install_cross_pkg $XBPS_CROSS_BUILD
# Install dependencies from binary packages
if [ -z "$XBPS_SKIP_DEPS" ]; then
install_pkg_deps $PKGNAME $TARGET_PKG $TARGET $XBPS_CROSS_BUILD || exit 1
fi
# Fetch distfiles after installing required dependencies,
# because some of them might be required for do_fetch().
$XBPS_LIBEXECDIR/xbps-src-dofetch.sh $PKGNAME $XBPS_CROSS_BUILD || exit 1
[ "$TARGET" = "fetch" ] && exit 0
# Fetch, extract, build and install into the destination directory.
$XBPS_LIBEXECDIR/xbps-src-doextract.sh $PKGNAME $XBPS_CROSS_BUILD || exit 1
[ "$TARGET" = "extract" ] && exit 0
# Run configure phase
$XBPS_LIBEXECDIR/xbps-src-doconfigure.sh $PKGNAME $XBPS_CROSS_BUILD || exit 1
[ "$TARGET" = "configure" ] && exit 0
# Run build phase
$XBPS_LIBEXECDIR/xbps-src-dobuild.sh $PKGNAME $XBPS_CROSS_BUILD || exit 1
[ "$TARGET" = "build" ] && exit 0
# Install pkgs into destdir.
$XBPS_LIBEXECDIR/xbps-src-doinstall.sh $PKGNAME $XBPS_CROSS_BUILD || exit 1
for subpkg in ${subpackages} ${sourcepkg}; do
$XBPS_LIBEXECDIR/xbps-src-doinstall.sh $subpkg $XBPS_CROSS_BUILD || exit 1
done
for subpkg in ${subpackages} ${sourcepkg}; do
$XBPS_LIBEXECDIR/xbps-src-prepkg.sh $subpkg $XBPS_CROSS_BUILD || exit 1
done
for subpkg in ${subpackages} ${sourcepkg}; do
if [ "$PKGNAME" = "${subpkg}" -a "$TARGET" = "install" ]; then
exit 0
fi
done
# If install went ok generate the binpkgs.
for subpkg in ${subpackages} ${sourcepkg}; do
$XBPS_LIBEXECDIR/xbps-src-dopkg.sh $subpkg "$XBPS_REPOSITORY" "$XBPS_CROSS_BUILD" || exit 1
done
# pkg cleanup
if declare -f do_clean >/dev/null; then
run_func do_clean
fi
if [ -z "$XBPS_KEEP_ALL" ]; then
remove_pkg_autodeps
remove_pkg_wrksrc
remove_pkg $XBPS_CROSS_BUILD
remove_pkg_statedir
fi
# If base-chroot not installed, install "base-files" into masterdir
# from local repository; this is the only pkg required to be able to build
# the bootstrap pkgs from scratch.
if [ -z "$CHROOT_READY" -a "$PKGNAME" = "base-files" ]; then
msg_normal "Installing $PKGNAME into masterdir...\n"
_log=$(mktemp --tmpdir || exit 1)
if [ -n "$XBPS_BUILD_FORCEMODE" ]; then
_flags="-f"
fi
$XBPS_INSTALL_CMD ${_flags} -y $PKGNAME >${_log} 2>&1
if [ $? -ne 0 ]; then
msg_red "Failed to install $PKGNAME into masterdir, see below for errors:\n"
cat ${_log}
rm -f ${_log}
msg_error "Cannot continue!"
fi
rm -f ${_log}
fi
exit 0

View file

@ -24,11 +24,6 @@ for f in $XBPS_COMMONDIR/environment/build/*.sh; do
source_file "$f"
done
if [ -z $pkgname -o -z $version ]; then
msg_error "$1: pkgname/version not set in pkg template!\n"
exit 1
fi
XBPS_BUILD_DONE="${XBPS_STATEDIR}/${sourcepkg}_${XBPS_CROSS_BUILD}_build_done"
XBPS_PRE_BUILD_DONE="${XBPS_STATEDIR}/${sourcepkg}_${XBPS_CROSS_BUILD}_pre_build_done"
XBPS_POST_BUILD_DONE="${XBPS_STATEDIR}/${sourcepkg}_${XBPS_CROSS_BUILD}_post_build_done"
@ -68,7 +63,6 @@ else
fi
fi
touch -f $XBPS_BUILD_DONE
# Run post_build()
if [ ! -f $XBPS_POST_BUILD_DONE ]; then
@ -80,4 +74,6 @@ fi
run_pkg_hooks post-build
touch -f $XBPS_BUILD_DONE
exit 0

View file

@ -63,8 +63,6 @@ else
fi
fi
touch -f $XBPS_CONFIGURE_DONE
# Run post_configure()
if [ ! -f $XBPS_POSTCONFIGURE_DONE ]; then
if declare -f post_configure >/dev/null; then
@ -75,4 +73,6 @@ fi
run_pkg_hooks post-configure
touch -f $XBPS_CONFIGURE_DONE
exit 0

View file

@ -59,7 +59,6 @@ else
fi
fi
touch -f $XBPS_EXTRACT_DONE
[ -d $wrksrc ] && cd $wrksrc
@ -71,4 +70,6 @@ fi
# Run post-extract hooks
run_pkg_hooks post-extract
touch -f $XBPS_EXTRACT_DONE
exit 0

View file

@ -43,7 +43,6 @@ if declare -f do_fetch >/dev/null; then
cd ${XBPS_BUILDDIR}
[ -n "$build_wrksrc" ] && mkdir -p "$wrksrc"
run_func do_fetch
touch -f $XBPS_FETCH_DONE
else
# Run do-fetch hooks.
run_pkg_hooks "do-fetch"
@ -57,4 +56,6 @@ fi
# Run post-fetch hooks.
run_pkg_hooks post-fetch
touch -f $XBPS_FETCH_DONE
exit 0

View file

@ -45,6 +45,7 @@ fi
source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
setup_pkg_depends $pkgname
run_pkg_hooks pre-pkg
touch -f $XBPS_PREPKG_DONE
exit 0