Skip to content

Commit

Permalink
configure: unindex removed packages
Browse files Browse the repository at this point in the history
For packages reported by xbps-checkvers as removed, generated makefile
finds files matching <pkgversion>.<arch>.xbps or
<pkgversion>.noarch.xbps. This is needed to know where is repodata in
which package is indexed (path may contain multilib, aarch64, nonfree
subdirectories). Then, xbps-rindex is called to remove package from
stage index. Then, xbps-repodb needs to remove package from public
index when no other package depend on it. Finally, xbps-rindex -r will
remove package file.
  • Loading branch information
Chocimier committed Sep 27, 2021
1 parent 4a82276 commit e1903ad
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ targets in the generated "tobuild" subdirectory. Once a package has been built,
a small file is created into the "built" subdirectory in order to tell Make not
to build it again.

Every time you run './configure', those two subdirectories are reset, so you
For packages listed by xbps-checkvers as removed, Make removes binary packages
and unindexes them. Directiories "toremove" and "removed" are used analogically
to "tobuild" and "built".

Every time you run './configure', those four subdirectories are reset, so you
cannot interrupt a build, run './configure', and resume properly. In order to
resume a build in these kinds of circumstances, you must completely remove
'repo-checkvers.txt', so that ./configure can detect what has already been
Expand Down
63 changes: 49 additions & 14 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CFG_CMDLINE=
CFG_CROSS=
CFG_REPO=
CROSS_ARCH=
PKG_ARCH=
DISTDIR=
MASTERDIR=
HOSTDIR=
Expand All @@ -13,6 +14,7 @@ XSC=
_append=""
RCV=`command -v xbps-checkvers 2>/dev/null`
RCV_F="repo-checkvers.txt"
RCV_FR="repo-checkvers-remove.txt"
TOBUILD=
_TOBUILD=
USAGE="Usage: $0 [-a cross-arch] [-CN] [-R repo] [-d|-m|-h dir]"
Expand Down Expand Up @@ -44,7 +46,7 @@ while getopts a:Cc:d:Nm:th:vR: OPT; do
exit 0
;;
C)
rm -rf tobuild built
rm -rf tobuild built toremove removed
rm -f *.txt Makefile
exit 0
;;
Expand Down Expand Up @@ -90,6 +92,7 @@ shift $(($OPTIND - 1))
: ${MASTERDIR:=$DISTDIR/masterdir}
: ${HOSTDIR:=$DISTDIR/hostdir}

PKG_ARCH=${CROSS_ARCH:-$(xbps-uhelper -r "$MASTERDIR" arch)}
SRCPKGS=$DISTDIR/srcpkgs
XBPS_SRCPKGDIR=$SRCPKGS

Expand All @@ -99,17 +102,23 @@ if [ -n "$CFG_CROSS" ]; then
export XBPS_TARGET_ARCH=$CROSS_ARCH
fi

RCV_CMD_LINE="$RCV $CFG_REPO --distdir=${DISTDIR} ${*}"
printf "INFO: Getting list of updates, please wait...\n"
printf "INFO: Running '$RCV_CMD_LINE' (${CROSS_ARCH:-native}) ...\n"
run_rcv() {
local file=$1 flags=$2
RCV_CMD_LINE="$RCV $flags $CFG_REPO --distdir=${DISTDIR} ${*}"
printf "INFO: Getting list of updates, please wait...\n"
printf "INFO: Running '$RCV_CMD_LINE' (${CROSS_ARCH:-native}) ...\n"

[ -f $RCV_F ] && _append="-a"
$RCV_CMD_LINE | tee ${_append} $RCV_F
rval=${PIPESTATUS[0]}
if [ $rval -ne 0 ]; then
echo "ERROR: xbps-checkvers exited with an error: $rval"
exit 1
fi
_append=""
[ -f $file ] && _append="-a"
$RCV_CMD_LINE | tee ${_append} $file
rval=${PIPESTATUS[0]}
if [ $rval -ne 0 ]; then
echo "ERROR: xbps-checkvers exited with an error: $rval"
exit 1
fi
}

run_rcv $RCV_F

xbps-uhelper pkgmatch "xbps-$($RCV -V | cut -d' ' -f2)_1" 'xbps>=0.54_1'
case "$?" in
Expand All @@ -123,9 +132,16 @@ case "$?" in
;;
esac

RCV_REMOVED=--removed
if $RCV -h 2>&1 | grep -q -e $RCV_REMOVED; then
run_rcv $RCV_FR $RCV_REMOVED

cut -d' ' -f1-2 "$RCV_FR" >pkgs-removed.txt
fi

printf "INFO: Creating source targets...\n"
rm -rf tobuild built
mkdir -p tobuild built
rm -rf tobuild built toremove removed
mkdir -p tobuild built toremove removed
for p in `cat pkgs.txt`; do
if [ -f "$SRCPKGS/$p/template" ]; then
$XSC show-avail $p 2>/dev/null
Expand All @@ -134,8 +150,14 @@ for p in `cat pkgs.txt`; do
fi
fi
done
[ -f pkgs-removed.txt ] && cat pkgs-removed.txt | while read p old; do
if ! [ -f "$SRCPKGS/$p/template" ]; then
touch toremove/$p-$old
fi
done

_TOBUILD="`find tobuild -type f`"
TOREMOVE="`find toremove -type f -printf '%f '`"

concat() {
local found=0
Expand Down Expand Up @@ -192,7 +214,10 @@ printf "# Generated by configure, do not modify.\n\n" >> Makefile
printf "PKGS = $TOBUILD\n" >> Makefile
printf "TOBUILD = \$(patsubst %%,tobuild/%%,\$(PKGS))\n" >> Makefile
printf "BUILT = \$(patsubst tobuild/%%,built/%%,\$(TOBUILD))\n\n" >> Makefile
printf "all: \$(BUILT)\n" >> Makefile
printf "PKGS_REMOVED = $TOREMOVE\n" >> Makefile
printf "TOREMOVE = \$(patsubst %%,toremove/%%,\$(PKGS_REMOVED))\n" >> Makefile
printf "REMOVED = \$(patsubst toremove/%%,removed/%%,\$(TOREMOVE))\n\n" >> Makefile
printf "all: \$(BUILT) \$(REMOVED)\n" >> Makefile
printf "\t@echo \"[Done]\"\n\n" >> Makefile
printf "print_pkgs:\n" >> Makefile
printf "\t@echo \$(PKGS)\n\n" >> Makefile
Expand All @@ -201,6 +226,11 @@ printf "\t@echo \"[xbps-src]\t\${@F}\"\n" >> Makefile
printf "\t@( $XSC pkg \${@F}; rval=\$\$?; [ \$\$rval -eq 2 ] && exit 0 || exit \$\$rval )\n" >> Makefile
printf "\t@touch \$@\n" >> Makefile
printf "\t@rm tobuild/\${@F}\n\n" >> Makefile
printf "removed/%%: toremove/%%\n" >> Makefile
printf "\t@echo \"[xbps-rindex -R]\t\${@F}\"\n" >> Makefile
printf "\t@find \"$HOSTDIR/binpkgs\" '(' -name \${@F}.$PKG_ARCH.xbps -o -name \${@F}.noarch.xbps ')' -exec env ${CROSS_ARCH:+XBPS_TARGET_ARCH=$CROSS_ARCH} xbps-rindex --remove --stage '{}' ';'\n" >> Makefile
printf "\t@touch \$@\n" >> Makefile
printf "\t@rm toremove/\${@F}\n\n" >> Makefile


printf "INFO: Finding and adding dependencies...\n"
Expand Down Expand Up @@ -228,9 +258,14 @@ for p in $TOBUILD; do
printf "built/$p: $deps\n" >> Makefile
done

for p in $TOREMOVE; do
printf "removed/$p:\n" >> Makefile
done

printf "\n" >> Makefile
printf "clean:\n" >> Makefile
printf "\t@rm -f built/*\n" >> Makefile
printf "\t@rm -f removed/*\n" >> Makefile
printf "\t@echo \"[Clean]\"\n\n" >> Makefile
printf ".PHONY: all print_pkgs clean\n" >> Makefile

Expand Down

0 comments on commit e1903ad

Please sign in to comment.