summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-02-19 03:06:16 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-04-11 13:02:27 -0400
commitd71dbf8ee17fa8def38ed027fe8cd851fee701f1 (patch)
tree539ff5994ef62c2eeee36cac430882e2eea69d89
parent7f6e7623c68113ee0fea05c0bdeb548de6a82e09 (diff)
libremakepkg: correctly exit if a hook fails
-rwxr-xr-xsrc/chroot-tools/libremakepkg11
-rw-r--r--test/libremakepkg-test.sh17
2 files changed, 23 insertions, 5 deletions
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index a226e38..7f0acfd 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -5,7 +5,7 @@ set -euE
# Copyright (C) 2010-2012 Nicolás Reynolds <fauno@parabola.nu>
# Copyright (C) 2010-2012 Joshua Ismael Haase Hernández (xihh) <hahj87@gmail.com>
# Copyright (C) 2012 Michał Masłowski <mtjm@mtjm.eu>
-# Copyright (C) 2012-2015 Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2012-2015, 2017 Luke Shumaker <lukeshu@sbcglobal.net>
#
# License: GNU GPLv2+
#
@@ -69,14 +69,15 @@ exit_copy() {
}
# Usage; run_hook $hookname $args...
-run_hook() {
+run_hook() (
local hookname=$1; shift
local hookvar="hook_${hookname}[@]"
local fails=()
+ set -o pipefail
for hook in "${!hookvar}"; do
- "$hook" "$@" || fails+=("$hook")
- done |& indent
+ { "$hook" "$@" |& indent; } || fails+=("$hook")
+ done
if [[ ${#fails[@]} -gt 0 ]]; then
error "Failure(s) in %s: %s" "$hookname" "${fails[*]}"
@@ -84,7 +85,7 @@ run_hook() {
else
return 0
fi
-}
+)
# Usage: add_to_local_repo $copydir $pkgfiles...
add_to_local_repo() {
diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh
index ddccab0..50d43f6 100644
--- a/test/libremakepkg-test.sh
+++ b/test/libremakepkg-test.sh
@@ -125,6 +125,7 @@ it_otherwise_fails_as_normal_user() {
# I do this to give it a chance of passing
cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD"
cd "$tmpdir"
+ local stat=0
libremakepkg >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
@@ -132,3 +133,19 @@ it_otherwise_fails_as_normal_user() {
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
+
+it_fails_if_a_hook_fails() {
+ require network sudo || return 0
+ cp libremakepkg.d/PKGBUILD-hello "$tmpdir/PKGBUILD"
+ cd "$tmpdir"
+ local stat=0
+
+ sed -i 's/^BLACKLIST=.*/&-bogus/' "$XDG_CONFIG_HOME"/libretools/libretools.conf
+ trap 'sed -i s/-bogus// "$XDG_CONFIG_HOME"/libretools/libretools.conf' RETURN
+
+ libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
+ testsudo libremakepkg -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ tail -n1 $tmpdir/stderr | grep -qF '==> ERROR: Failure(s) in check_pkgbuild: check_pkgbuild_nonfree'
+}