Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2023-03-23 23:38:29 +0100
committerLevente Polyak <anthraxx@archlinux.org>2023-11-26 01:28:20 +0100
commitcc369e86d2e060d8b65c7dbbb0c933d18f8aa6b0 (patch)
treea0ac6d2621eed26122bbead3c38da84e9484d95e /src
parentc9de6a18b9fffa8904e191cb184c2b4d083d8dc3 (diff)
feat(makechrootpkg): add option to interactively inspect the chroot
Implement the -x option for makechrootpkg which allows to get an interactive shell in the chroot after building the package. Useful to ease the debugging of a package build. Depending on the argument, the interactive shell is either always spawned or only when an error occurred during build. This option is also forwarded from `pkgctl build` via the `--inspect` flag. Component: pkgctl build Component: makechrootpkg Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/lib/build/build.sh11
-rw-r--r--src/lib/valid-inspect.sh10
-rw-r--r--src/makechrootpkg.in38
3 files changed, 54 insertions, 5 deletions
diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh
index 8d58b63..2b9d4cf 100644
--- a/src/lib/build/build.sh
+++ b/src/lib/build/build.sh
@@ -20,6 +20,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pacman.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh
# shellcheck source=src/lib/valid-tags.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-tags.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/message.sh
@@ -48,6 +50,7 @@ pkgctl_build_usage() {
-o, --offload Build on a remote server and transfer artifacts afterwards
-c, --clean Recreate the chroot before building
-I, --install FILE Install a package into the working copy of the chroot
+ --inspect WHEN Spawn an interactive shell to inspect the chroot (never, always, failure)
-w, --worker SLOT Name of the worker slot, useful for concurrent builds (disables automatic names)
--nocheck Do not run the check() function in the PKGBUILD
@@ -218,6 +221,14 @@ pkgctl_build() {
warning 'not running checks is disallowed for official packages, except for bootstrapping. Please rebuild after bootstrapping is completed!'
shift
;;
+ --inspect)
+ (( $# <= 1 )) && die "missing argument for %s" "$1"
+ if ! in_array "${2}" "${DEVTOOLS_VALID_INSPECT_MODES[@]}"; then
+ die "Invalid inspect mode: %s" "${2}"
+ fi
+ MAKECHROOT_OPTIONS+=("-x" "${2}")
+ shift 2
+ ;;
-r|--release)
# shellcheck source=src/lib/release.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/release.sh
diff --git a/src/lib/valid-inspect.sh b/src/lib/valid-inspect.sh
new file mode 100644
index 0000000..3b5dcad
--- /dev/null
+++ b/src/lib/valid-inspect.sh
@@ -0,0 +1,10 @@
+#!/hint/bash
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# shellcheck disable=2034
+DEVTOOLS_VALID_INSPECT_MODES=(
+ never
+ always
+ failure
+)
diff --git a/src/makechrootpkg.in b/src/makechrootpkg.in
index 2cfd849..14b8f11 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
}
@@ -280,7 +286,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") ;;
@@ -293,6 +299,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
@@ -314,6 +321,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}")
@@ -368,11 +379,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[@]}"')
@@ -382,6 +398,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