summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorXavier Chantry <shiningxc@gmail.com>2009-08-25 00:19:20 +0200
committerDan McGee <dan@archlinux.org>2009-09-06 22:57:14 +0200
commitcb07265851898ae352ef801ef99c98f26e28b03e (patch)
treea67f4a59d399da3d328c7215c52a34c5cdf5bc0d /scripts
parent545eac145d77c66714ec88a88056ac3827c9b240 (diff)
downloadpacman-cb07265851898ae352ef801ef99c98f26e28b03e.tar.gz
pacman-cb07265851898ae352ef801ef99c98f26e28b03e.tar.xz
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>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/makepkg.sh.in117
1 files changed, 39 insertions, 78 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index bfa1707a..fc30caea 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -694,94 +694,23 @@ extract_sources() {
fi
}
-error_build() {
- # 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() {
+error_function() {
if [ -p "$logpipe" ]; then
rm "$logpipe"
fi
# first exit all subshells, then print the error
if [ $BASH_SUBSHELL -eq 0 ]; then
- error "$(gettext "Packaging Failed.")"
plain "$(gettext "Aborting...")"
remove_deps
fi
exit 2 # $E_BUILD_FAILED
}
-run_package() {
+run_function() {
if [ -z "$1" ]; then
- pkgfunc="package"
- nameofpkg="$pkgname"
- else
- pkgfunc="package_$1"
- nameofpkg="$1"
+ return 1
fi
+ pkgfunc="$1"
# clear user-specified makeflags if requested
if [ "$(check_option makeflags)" = "n" ]; then
@@ -793,10 +722,12 @@ run_package() {
# ensure all necessary build variables are exported
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
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
local i=1
while true; do
@@ -816,7 +747,7 @@ run_package() {
tee "$BUILDLOG" < "$logpipe" &
exec 1>"$logpipe" 2>"$logpipe"
restoretrap=$(trap -p ERR)
- trap 'error_package' ERR
+ trap 'error_function' ERR
$pkgfunc 2>&1
eval $restoretrap
sync
@@ -824,10 +755,40 @@ run_package() {
rm "$logpipe"
else
restoretrap=$(trap -p ERR)
- trap 'error_package' ERR
+ trap 'error_function' ERR
$pkgfunc 2>&1
eval $restoretrap
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() {