diff --git a/.gitignore b/.gitignore index 4a33d50..0d58392 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ Makefile tobuild built pkgs.txt +pkgs-removed.txt repo-checkvers.txt +repo-checkvers-remove.txt +repo-checkvers-pkgver.txt diff --git a/README b/README index 65ba3b0..8de9ac0 100644 --- a/README +++ b/README @@ -23,6 +23,9 @@ 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. +Packages listed by xbps-checkvers as removed are removed them from stagedata +index. + Every time you run './configure', those two 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 diff --git a/configure b/configure index df641d4..c9db198 100755 --- a/configure +++ b/configure @@ -1,10 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash VERSION=0.0.0 CFG_CMDLINE= CFG_CROSS= CFG_REPO= CROSS_ARCH= +PKG_ARCH= DISTDIR= MASTERDIR= HOSTDIR= @@ -13,9 +14,11 @@ 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]" +declare -A PKGVER_ASSOC [ -f $RCV ] || { printf "ERROR: The 'xbps-checkvers' was not found in the PATH.\n" @@ -75,7 +78,7 @@ while getopts a:Cc:d:Nm:th:vR: OPT; do HOSTDIR="$OPTARG" ;; R) - CFG_REPO="-R $OPTARG" + CFG_REPO+="-R $OPTARG " ;; \?) printf "%s\n" "$USAGE" @@ -90,6 +93,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 @@ -99,41 +103,80 @@ 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 + shift 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 0) # version < 0.54 grep pkgname "$RCV_F" | awk '{ print $2 }' >pkgs.txt ;; 1) # version >= 0.54 - cut -d' ' -f1 "$RCV_F" >pkgs.txt ;; + cut -d' ' -f1 "$RCV_F" >pkgs.txt + while read -r pkgname version remainder; do + PKGVER_ASSOC[$pkgname]=$version + done < "$RCV_F" + ;; *) echo "ERROR: couldn't determine xbps-checkvers version" exit 1 ;; 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" +TOREMOVE= +TOREMOVE32BIT= rm -rf tobuild built mkdir -p tobuild built for p in `cat pkgs.txt`; do if [ -f "$SRCPKGS/$p/template" ]; then $XSC show-avail $p 2>/dev/null - if [ $? -eq 0 ]; then - touch tobuild/$p - fi + case $? in + 0) + touch tobuild/$p + ;; + 2) + version=${PKGVER_ASSOC[$p]} + TOREMOVE+="$p-$version " + TOREMOVE+="$p-dbg-$version " + [ "$XBPS_ARCH" = i686 ] && TOREMOVE32BIT+="$p-32bit-$version " + while read -r sub; do + TOREMOVE+="$sub-$version " + TOREMOVE+="$sub-dbg-$version " + [ "$XBPS_ARCH" = i686 ] && TOREMOVE32BIT+="$sub-32bit-$version " + done < <($XSC show $p 2>/dev/null | grep '^subpackages:' | cut -d: -f2-) + ;; + esac fi done +if [ -f pkgs-removed.txt ] ; then + while read p old; do + if ! [ -f "$SRCPKGS/$p/template" ]; then + TOREMOVE+="$p-$old " + fi + done < pkgs-removed.txt +fi _TOBUILD="`find tobuild -type f`" @@ -192,17 +235,35 @@ 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 "PKGS_REMOVED_32BIT = $TOREMOVE32BIT\n" >> Makefile +printf "all: allbuilt allremoved\n" >> Makefile printf "\t@echo \"[Done]\"\n\n" >> Makefile +printf "allbuilt: \$(BUILT)\n\n" >> Makefile +printf "allremoved:\n" >> Makefile +printf "\t@echo \"[xbps-rindex --remove --stage]\t\"\n" >> Makefile +# TODO: xbps-query --stage -s +for subrepo in "" /debug /nonfree; do + printf "\t@( in_repo=\$\$(env XBPS_TARGET_ARCH=$PKG_ARCH xbps-query -i -R --repository=\"$HOSTDIR/binpkgs$subrepo\" -s '' | cut -d' ' -f2 | while read -r indexed; do for removed in \$(PKGS_REMOVED); do [ \"\$\$indexed\" = \"\$\$removed\" ] && echo \"$HOSTDIR/binpkgs$subrepo\"/\$\$removed.$PKG_ARCH.xbps; done; done ); [ \"\$\$in_repo\" ] && env XBPS_TARGET_ARCH=$PKG_ARCH xbps-rindex --remove --stage \$\$in_repo )\n" >> Makefile +done +if [ "$XBPS_ARCH" = i686 ]; then + printf "\t@echo \"[xbps-rindex --remove --stage # multilib]\t\"\n" >> Makefile + for subrepo in /multilib /multilib/nonfree; do + printf "\t@( in_repo=\$\$(env XBPS_TARGET_ARCH=x86_64 xbps-query -i -R --repository=\"$HOSTDIR/binpkgs$subrepo\" -s '' | cut -d' ' -f2 | while read -r indexed; do for removed in \$(PKGS_REMOVED_32BIT); do [ \"\$\$indexed\" = \"\$\$removed\" ] && echo \"$HOSTDIR/binpkgs$subrepo\"/\$\$removed.x86_64.xbps; done; done ); [ \"\$\$in_repo\" ] && env XBPS_TARGET_ARCH=x86_64 xbps-rindex --remove --stage \$\$in_repo )\n" >> Makefile + done +fi +printf "\n" >> Makefile printf "print_pkgs:\n" >> Makefile printf "\t@echo \$(PKGS)\n\n" >> Makefile +printf "print_pkgs_removed:\n" >> Makefile +printf "\t@echo \$(PKGS_REMOVED)\n\n" >> Makefile + printf "built/%%: tobuild/%%\n" >> Makefile 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 "INFO: Finding and adding dependencies...\n" printf "# Dependencies\n" >> Makefile for p in $TOBUILD; do @@ -228,11 +289,19 @@ for p in $TOBUILD; do printf "built/$p: $deps\n" >> Makefile done +printf "\n" >> Makefile +printf "# Remove targets\n" >> Makefile +printf "removed/$p:\n" >> Makefile +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 +printf ".PHONY: all print_pkgs clean allbuilt allremoved\n" >> Makefile printf "INFO: 'Makefile' generated.\n" printf "INFO: Type 'make'\n"