From cc6cf65ef9dae217a7476bc0ef3333157f5dea6e Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 11 Nov 2021 23:39:29 +0100 Subject: makerepropkg: support parallel runs in dedicated namespaces This adds proper namespace locking as well to fix screwing up the running makerepropkg process. --- makerepropkg.in | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'makerepropkg.in') diff --git a/makerepropkg.in b/makerepropkg.in index 70abcbe..b271f25 100755 --- a/makerepropkg.in +++ b/makerepropkg.in @@ -17,9 +17,12 @@ declare -a buildenv buildopts installed installpkgs archiveurl='https://archive.archlinux.org/packages' buildroot=/var/lib/archbuild/reproducible -chroot=testenv diffoscope=0 +chroot=$USER +[[ -n ${SUDO_USER:-} ]] && chroot=$SUDO_USER +[[ -z "$chroot" || $chroot = root ]] && chroot=copy + parse_buildinfo() { local line var val @@ -108,15 +111,19 @@ OPTIONS -d Run diffoscope if the package is unreproducible -c Set pacman cache -M Location of a makepkg config file + -l The directory name to use as the chroot namespace + Useful for maintaining multiple copies + Default: $chroot -h Show this usage message __EOF__ } -while getopts 'dM:c:h' arg; do +while getopts 'dM:c:l:h' arg; do case "$arg" in d) diffoscope=1 ;; M) archroot_args+=(-M "$OPTARG") ;; c) cache_dirs+=("$OPTARG") ;; + l) chroot="$OPTARG" ;; h) usage; exit 0 ;; *|?) usage; exit 1 ;; esac @@ -184,12 +191,14 @@ BUILDTOOLVER="${buildinfo[buildtoolver]}" PKGEXT=${splitpkgs[0]#${splitpkgs[0]%.pkg.tar*}} # nuke and restore reproducible testenv -for copy in "${buildroot}"/*/; do +namespace="$buildroot/$chroot" +lock 9 "${namespace}.lock" "Locking chroot namespace '%s'" "${namespace}" +for copy in "${namespace}"/*/; do [[ -d ${copy} ]] || continue subvolume_delete_recursive "${copy}" done -rm -rf --one-file-system "${buildroot}" -(umask 0022; mkdir -p "${buildroot}") +rm -rf --one-file-system "${namespace}" +(umask 0022; mkdir -p "${namespace}") for fname in "${installed[@]}"; do if ! allpkgfiles+=("$(get_pkgfile "${fname}")"); then @@ -216,10 +225,10 @@ else warning "Unknown buildtool (${BUILDTOOL}-${BUILDTOOLVER}), using fallback" makepkg_conf=@pkgdatadir@/makepkg-x86_64.conf fi -printf '%s\n' "${allpkgfiles[@]}" | mkarchroot -M "${makepkg_conf}" -U "${archroot_args[@]}" "${buildroot}"/root - || exit 1 +printf '%s\n' "${allpkgfiles[@]}" | mkarchroot -M "${makepkg_conf}" -U "${archroot_args[@]}" "${namespace}/root" - || exit 1 # use makechrootpkg to prep the build directory -makechrootpkg -r "${buildroot}" -l "${chroot}" -- --packagelist || exit 1 +makechrootpkg -r "${namespace}" -l build -- --packagelist || exit 1 # set detected makepkg.conf options { @@ -228,22 +237,22 @@ makechrootpkg -r "${buildroot}" -l "${chroot}" -- --packagelist || exit 1 done printf 'OPTIONS=(%s)\n' "${buildopts[*]@Q}" printf 'BUILDENV=(%s)\n' "${buildenv[*]@Q}" -} >> "${buildroot}/${chroot}"/etc/makepkg.conf -install -d -o "${SUDO_UID:-$UID}" -g "$(id -g "${SUDO_UID:-$UID}")" "${buildroot}/${chroot}/${BUILDDIR}" +} >> "${namespace}/build"/etc/makepkg.conf +install -d -o "${SUDO_UID:-$UID}" -g "$(id -g "${SUDO_UID:-$UID}")" "${namespace}/build/${BUILDDIR}" # kick off the build -arch-nspawn "${buildroot}/${chroot}" \ +arch-nspawn "${namespace}/build" \ --bind="${PWD}:/startdir" \ --bind="${SRCDEST}:/srcdest" \ /chrootbuild -C --noconfirm --log --holdver --skipinteg ret=$? if (( ${ret} == 0 )); then - msg2 "built succeeded! built packages can be found in ${buildroot}/${chroot}/pkgdest" + msg2 "built succeeded! built packages can be found in ${namespace}/build/pkgdest" msg "comparing artifacts..." for pkgfile in "${splitpkgs[@]}"; do - comparefiles=("${pkgfile}" "${buildroot}/${chroot}/pkgdest/${pkgfile##*/}") + comparefiles=("${pkgfile}" "${namespace}/build/pkgdest/${pkgfile##*/}") if cmp -s "${comparefiles[@]}"; then msg2 "Package '%s' successfully reproduced!" "${pkgfile}" else -- cgit v1.2.3-70-g09d2