[arch-projects] [devtools] [PATCH 2/2] makechrootpkg: Allow setting pacman cache for arch-nspawn.

Maarten de Vries maarten at de-vri.es
Tue Jan 15 13:34:53 UTC 2019


Signed-off-by: Maarten de Vries <maarten at de-vri.es>
---
 makechrootpkg.in | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/makechrootpkg.in b/makechrootpkg.in
index d81be84..ad65de4 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -38,6 +38,7 @@ usage() {
 	echo 'Flags:'
 	echo '-h         This help'
 	echo '-c         Clean the chroot before building'
+	echo '-C <dir>   Use a folder on the host as pacman cache'
 	echo '-d <dir>   Bind directory into build chroot as read-write'
 	echo '-D <dir>   Bind directory into build chroot as read-only'
 	echo '-u         Update the working copy of the chroot before building'
@@ -147,7 +148,7 @@ install_packages() {
 	pkgnames=("${install_pkgs[@]##*/}")
 
 	cp -- "${install_pkgs[@]}" "$copydir/root/"
-	arch-nspawn "$copydir" "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
+	nspawn "$copydir" \
 		pacman -U --noconfirm -- "${pkgnames[@]/#//root/}"
 	ret=$?
 	rm -- "${pkgnames[@]/#/$copydir/root/}"
@@ -301,6 +302,22 @@ move_products() {
 		fi
 	done
 }
+
+# Usage: nspawn $copydir $nspawn-args ...
+# Globals:
+#  - pacman_cache
+#  - bindmounts_ro
+#  - bindmounts_rw
+nspawn() {
+	local copydir=$1
+	shift
+
+	if [[ -n $pacman_cache ]]; then
+		arch-nspawn -c "$pacman_cache" "$copydir" "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" "$@"
+	else
+		arch-nspawn "$copydir" "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" "$@"
+	fi
+}
 # }}}
 
 main() {
@@ -317,6 +334,7 @@ main() {
 	declare -a install_pkgs
 	declare -i ret=0
 
+	pacman_cache=
 	bindmounts_ro=()
 	bindmounts_rw=()
 
@@ -325,9 +343,10 @@ main() {
 	[[ -z "$copy" || $copy = root ]] && copy=copy
 	src_owner=${SUDO_USER:-$USER}
 
-	while getopts 'hcur:I:l:nTD:d:U:' arg; do
+	while getopts 'hcur:I:l:nTC:D:d:U:' arg; do
 		case "$arg" in
 			c) clean_first=true ;;
+			C) pacman_cache="$OPTARG" ;;
 			D) bindmounts_ro+=("--bind-ro=$OPTARG") ;;
 			d) bindmounts_rw+=("--bind=$OPTARG") ;;
 			u) update_first=true ;;
@@ -395,8 +414,7 @@ main() {
 		sync_chroot "$chrootdir/root" "$copydir" "$copy"
 	fi
 
-	$update_first && arch-nspawn "$copydir" \
-			"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
+	$update_first && nspawn "$copydir" \
 			pacman -Syu --noconfirm
 
 	if [[ -n ${install_pkgs[*]:-} ]]; then
@@ -415,10 +433,9 @@ main() {
 
 	prepare_chroot "$copydir" "$USER_HOME" "$keepbuilddir" "$run_namcap"
 
-	if arch-nspawn "$copydir" \
+	if nspawn "$copydir" \
 		--bind="$PWD:/startdir" \
 		--bind="$SRCDEST:/srcdest" \
-		"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
 		/chrootbuild "${makepkg_args[@]}"
 	then
 		move_products "$copydir" "$src_owner"
-- 
2.20.1


More information about the arch-projects mailing list