makepkg : refactor run_build and run_package
These two functions were very similar. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
545eac145d
commit
cb07265851
1 changed files with 39 additions and 78 deletions
|
@ -694,94 +694,23 @@ extract_sources() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
error_build() {
|
error_function() {
|
||||||
# first exit all subshells, then print the error
|
|
||||||
if [ $BASH_SUBSHELL -eq 0 ]; then
|
|
||||||
error "$(gettext "Build Failed.")"
|
|
||||||
plain "$(gettext "Aborting...")"
|
|
||||||
remove_deps
|
|
||||||
fi
|
|
||||||
exit 2 # $E_BUILD_FAILED
|
|
||||||
}
|
|
||||||
|
|
||||||
run_build() {
|
|
||||||
# use distcc if it is requested (check buildenv and PKGBUILD opts)
|
|
||||||
if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
|
|
||||||
[ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH"
|
|
||||||
export DISTCC_HOSTS
|
|
||||||
elif [ "$(check_option distcc)" = "n" ]; then
|
|
||||||
# if it is not wanted, clear the makeflags too
|
|
||||||
MAKEFLAGS=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# use ccache if it is requested (check buildenv and PKGBUILD opts)
|
|
||||||
if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
|
|
||||||
[ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# clear user-specified makeflags if requested
|
|
||||||
if [ "$(check_option makeflags)" = "n" ]; then
|
|
||||||
MAKEFLAGS=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
msg "$(gettext "Starting build()...")"
|
|
||||||
cd "$srcdir"
|
|
||||||
|
|
||||||
# ensure all necessary build variables are exported
|
|
||||||
export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST
|
|
||||||
# save our shell options so build() can't override what we need
|
|
||||||
local shellopts=$(shopt -p)
|
|
||||||
|
|
||||||
local ret=0
|
|
||||||
if [ "$LOGGING" -eq 1 ]; then
|
|
||||||
BUILDLOG="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"
|
|
||||||
if [ -f "$BUILDLOG" ]; then
|
|
||||||
local i=1
|
|
||||||
while true; do
|
|
||||||
if [ -f "$BUILDLOG.$i" ]; then
|
|
||||||
i=$(($i +1))
|
|
||||||
else
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
mv "$BUILDLOG" "$BUILDLOG.$i"
|
|
||||||
fi
|
|
||||||
|
|
||||||
set +E
|
|
||||||
build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
|
|
||||||
set -E
|
|
||||||
if [ $ret -gt 0 ]; then error_build; fi
|
|
||||||
else
|
|
||||||
restoretrap=$(trap -p ERR)
|
|
||||||
trap 'error_build' ERR
|
|
||||||
build 2>&1
|
|
||||||
eval $restoretrap
|
|
||||||
fi
|
|
||||||
# reset our shell options
|
|
||||||
eval "$shellopts"
|
|
||||||
}
|
|
||||||
|
|
||||||
error_package() {
|
|
||||||
if [ -p "$logpipe" ]; then
|
if [ -p "$logpipe" ]; then
|
||||||
rm "$logpipe"
|
rm "$logpipe"
|
||||||
fi
|
fi
|
||||||
# first exit all subshells, then print the error
|
# first exit all subshells, then print the error
|
||||||
if [ $BASH_SUBSHELL -eq 0 ]; then
|
if [ $BASH_SUBSHELL -eq 0 ]; then
|
||||||
error "$(gettext "Packaging Failed.")"
|
|
||||||
plain "$(gettext "Aborting...")"
|
plain "$(gettext "Aborting...")"
|
||||||
remove_deps
|
remove_deps
|
||||||
fi
|
fi
|
||||||
exit 2 # $E_BUILD_FAILED
|
exit 2 # $E_BUILD_FAILED
|
||||||
}
|
}
|
||||||
|
|
||||||
run_package() {
|
run_function() {
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
pkgfunc="package"
|
return 1
|
||||||
nameofpkg="$pkgname"
|
|
||||||
else
|
|
||||||
pkgfunc="package_$1"
|
|
||||||
nameofpkg="$1"
|
|
||||||
fi
|
fi
|
||||||
|
pkgfunc="$1"
|
||||||
|
|
||||||
# clear user-specified makeflags if requested
|
# clear user-specified makeflags if requested
|
||||||
if [ "$(check_option makeflags)" = "n" ]; then
|
if [ "$(check_option makeflags)" = "n" ]; then
|
||||||
|
@ -793,10 +722,12 @@ run_package() {
|
||||||
|
|
||||||
# ensure all necessary build variables are exported
|
# ensure all necessary build variables are exported
|
||||||
export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
|
export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
|
||||||
|
# save our shell options so pkgfunc() can't override what we need
|
||||||
|
local shellopts=$(shopt -p)
|
||||||
|
|
||||||
local ret=0
|
local ret=0
|
||||||
if [ "$LOGGING" -eq 1 ]; then
|
if [ "$LOGGING" -eq 1 ]; then
|
||||||
BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"
|
BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log"
|
||||||
if [ -f "$BUILDLOG" ]; then
|
if [ -f "$BUILDLOG" ]; then
|
||||||
local i=1
|
local i=1
|
||||||
while true; do
|
while true; do
|
||||||
|
@ -816,7 +747,7 @@ run_package() {
|
||||||
tee "$BUILDLOG" < "$logpipe" &
|
tee "$BUILDLOG" < "$logpipe" &
|
||||||
exec 1>"$logpipe" 2>"$logpipe"
|
exec 1>"$logpipe" 2>"$logpipe"
|
||||||
restoretrap=$(trap -p ERR)
|
restoretrap=$(trap -p ERR)
|
||||||
trap 'error_package' ERR
|
trap 'error_function' ERR
|
||||||
$pkgfunc 2>&1
|
$pkgfunc 2>&1
|
||||||
eval $restoretrap
|
eval $restoretrap
|
||||||
sync
|
sync
|
||||||
|
@ -824,10 +755,40 @@ run_package() {
|
||||||
rm "$logpipe"
|
rm "$logpipe"
|
||||||
else
|
else
|
||||||
restoretrap=$(trap -p ERR)
|
restoretrap=$(trap -p ERR)
|
||||||
trap 'error_package' ERR
|
trap 'error_function' ERR
|
||||||
$pkgfunc 2>&1
|
$pkgfunc 2>&1
|
||||||
eval $restoretrap
|
eval $restoretrap
|
||||||
fi
|
fi
|
||||||
|
# reset our shell options
|
||||||
|
eval "$shellopts"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_build() {
|
||||||
|
# use distcc if it is requested (check buildenv and PKGBUILD opts)
|
||||||
|
if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
|
||||||
|
[ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH"
|
||||||
|
export DISTCC_HOSTS
|
||||||
|
elif [ "$(check_option distcc)" = "n" ]; then
|
||||||
|
# if it is not wanted, clear the makeflags too
|
||||||
|
MAKEFLAGS=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# use ccache if it is requested (check buildenv and PKGBUILD opts)
|
||||||
|
if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
|
||||||
|
[ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
run_function "build"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_package() {
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
pkgfunc="package"
|
||||||
|
else
|
||||||
|
pkgfunc="package_$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
run_function "$pkgfunc"
|
||||||
}
|
}
|
||||||
|
|
||||||
tidy_install() {
|
tidy_install() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue