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

Message ID 20190115133450.9676-2-maarten@de-vri.es
State New
Headers show
Series
  • [devtools,1/2] arch-nspawn, mkarchroot: Allow not sharing the cache directories.
Related show

Commit Message

Eli Schwartz via arch-projects Jan. 15, 2019, 1:34 p.m. UTC
Signed-off-by: Maarten de Vries <maarten@de-vri.es>
---
 makechrootpkg.in | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

Patch

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"