summaryrefslogtreecommitdiff
path: root/src/makechrootpkg.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/makechrootpkg.in')
-rw-r--r--src/makechrootpkg.in38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/makechrootpkg.in b/src/makechrootpkg.in
index c2e3daa..70eba3c 100644
--- a/src/makechrootpkg.in
+++ b/src/makechrootpkg.in
@@ -8,9 +8,12 @@ _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
# shellcheck source=src/lib/archroot.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/archroot.sh
+# shellcheck source=src/lib/valid-inspect.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-inspect.sh
source /usr/share/makepkg/util/config.sh
+source /usr/share/makepkg/util/util.sh
shopt -s nullglob
@@ -31,6 +34,8 @@ run_checkpkg=0
temp_chroot=0
tmp_opts="nosuid,nodev,size=50%,nr_inodes=2m"
+inspect=never
+
bindmounts_ro=()
bindmounts_rw=()
@@ -76,6 +81,7 @@ usage() {
echo '-C Run checkpkg on the package'
echo '-T Build in a temporary directory'
echo '-U Run makepkg as a specified user'
+ echo '-x <when> Inspect chroot after build (never, always, failure)'
exit 1
}
@@ -289,7 +295,7 @@ move_products() {
}
# }}}
-while getopts 'hcur:I:l:nCTD:d:U:' arg; do
+while getopts 'hcur:I:l:nCTD:d:U:x:' arg; do
case "$arg" in
c) clean_first=1 ;;
D) bindmounts_ro+=("--bind-ro=$OPTARG") ;;
@@ -302,6 +308,7 @@ while getopts 'hcur:I:l:nCTD:d:U:' arg; do
C) run_checkpkg=1 ;;
T) temp_chroot=1; copy+="-$$" ;;
U) makepkg_user="$OPTARG" ;;
+ x) inspect="$OPTARG" ;;
h|*) usage ;;
esac
done
@@ -323,6 +330,10 @@ else
copydir="$chrootdir/$copy"
fi
+if ! in_array "${inspect}" "${DEVTOOLS_VALID_INSPECT_MODES[@]}"; then
+ die "Invalid inspect mode: %s" "${inspect}"
+fi
+
# Pass all arguments after -- right to makepkg
makepkg_args+=("${@:$OPTIND}")
@@ -378,11 +389,16 @@ download_sources
prepare_chroot
+nspawn_build_args=(
+ --bind="${PWD//:/\\:}:/startdir"
+ --bind="${SRCDEST//:/\\:}:/srcdest"
+ --tmpfs="/tmp:${tmp_opts}"
+ "${bindmounts_ro[@]}"
+ "${bindmounts_rw[@]}"
+)
+
if arch-nspawn "$copydir" \
- --bind="${PWD//:/\\:}:/startdir" \
- --bind="${SRCDEST//:/\\:}:/srcdest" \
- --tmpfs="/tmp:${tmp_opts}" \
- "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
+ "${nspawn_build_args[@]}" \
/chrootbuild "${makepkg_args[@]}"
then
mapfile -t pkgnames < <(sudo -u "$makepkg_user" bash -c 'source PKGBUILD; printf "%s\n" "${pkgname[@]}"')
@@ -392,6 +408,18 @@ else
move_logfiles
fi
+if [[ $inspect == always ]] || ( [[ $inspect == failure ]] && (( ret != 0 )) ); then
+ if (( ret == 0 )); then
+ msg "Build succeeded, inspecting %s" "$copydir"
+ else
+ error "Build failed, inspecting %s" "$copydir"
+ fi
+ arch-nspawn "$copydir" \
+ "${nspawn_build_args[@]}" \
+ --user=builduser \
+ --chdir=/build
+fi
+
(( temp_chroot )) && delete_chroot "$copydir" "$copy"
if (( ret != 0 )); then