summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@endefensadelsl.org>2014-01-07 10:13:49 -0300
committerNicolás Reynolds <fauno@endefensadelsl.org>2014-01-07 10:13:49 -0300
commit0d1aabe28efaabc910dcbca4508bb7bbc97b23df (patch)
tree80a88a49a51053efc865adba10756eac50fbf1c5
parent7f3926f2aab774eacc5fc5963725d44c70f50bdc (diff)
First test version of dagpkg, a topologically sorted recursive abs builder
-rwxr-xr-xdagpkg154
1 files changed, 154 insertions, 0 deletions
diff --git a/dagpkg b/dagpkg
new file mode 100755
index 0000000..d3fb723
--- /dev/null
+++ b/dagpkg
@@ -0,0 +1,154 @@
+#!/usr/bin/env bash
+set -e
+
+# Source variables from makepkg
+source /etc/makepkg.conf
+source $XDG_CONFIG_HOME/.makepkg.conf &>/dev/null || true
+
+# Source variables from libretools
+source /etc/libretools.conf
+source $XDG_CONFIG_HOME/libretools/libretools.conf &>/dev/null || true
+
+# End inmediately but print an useful message
+trap_exit() {
+ term_title "error!"
+ error "($(basename $0)) $@ (leftovers on ${temp_dir})"
+ exit 1
+}
+
+# Trap signals from makepkg
+trap 'trap_exit "TERM signal caught. Exiting..."' TERM HUP QUIT
+trap 'trap_exit "Aborted by user! Exiting..."' INT
+trap 'trap_exit "An unknown error has occurred. Exiting..."' ERR
+
+# Source this PKGBUILD, if it doesn't exist, exit
+if ! source PKGBUILD &>/dev/null ; then
+ error "No PKGBUILD in %s" "$PWD"
+ exit 1
+fi
+
+# This is the name of the package
+name="${pkgbase:-${pkgname[0]}}"
+
+# The name of the previous package
+prev="${3}"
+depth="${2:-0}"
+let next=${depth}+1 || true
+
+# A temporary work dir and log file
+temp_dir="${1:-$(mktemp -d /tmp/${name}-testpkg-XXXX)}"
+log="${temp_dir}/buildorder"
+
+# Generate the full version with epoch
+get_fullver() {
+ if [ $1 -eq 0 ]; then
+# zero epoch case, don't include it in version
+ echo $2-$3
+ else
+ echo $1:$2-$3
+ fi
+
+}
+
+# If it's already built we don't bother
+is_built ${pkgname[0]} $(get_fullver ${epoch:-0} ${pkgver} ${pkgrel}) &&
+exit
+
+# If the envvar I contains this package, ignore it and exit
+echo "$I" | grep -q "$name" && exit
+
+msg "%s(%d)" $name $depth
+
+build=false
+if [ ! -z "${1}" -a ${depth} -eq 0 ]; then
+ build=true
+fi
+
+ # If we specified a work dir on the cli it means we want to skip
+ # dependency graph creation and jump to build whatever is there
+ if ! ${build}; then
+
+ # Export a pair of current and previous package to get a list of graph
+ # edges
+ echo -e "${name}\t${prev:--}" | tee -a ${log}
+
+ # Recurse into dependencies
+ for d in ${depends[@]} ${makedepends[@]}; do
+ # Cleanup dependency versions
+ d=$(echo $d | sed "s/[<>=].*//")
+ # Where's the pkgbuild?
+ w=$(toru-where $d)
+
+ # Skip if not available
+ test -z "$w" && continue
+
+ # Go to this dir
+ pushd $w &>/dev/null
+
+ # Infinite loop detection, if the inverted pair current+prev was
+ # already seen, skip
+ if grep -q "${prev}[[:space:]]${d}" ${log} ; then
+ msg2 "infinite loop %s<->%s" $d $prev
+ continue
+ fi
+
+ # Edge detection
+ if grep -q "^${d}[[:space:]]" ${log} ; then
+ msg2 "edge %s already visited" ${d}
+ continue
+ fi
+
+ # Run this same command giving work dir, depth and previous package
+ $0 ${temp_dir} ${next} ${name}
+
+ popd &>/dev/null
+ done
+else
+ msg "Resuming build..."
+fi
+
+# end here if we're not the first package
+test ${depth} -ne 0 && exit
+
+
+# enter work dir
+pushd "${temp_dir}" &>/dev/null
+tsort ${log} | head -n-1 | tac | nl | tac | while read order pkg; do
+ # skip if already built
+ test -f "${pkg}/built_ok" && continue
+
+ # where's this package?
+ w="$(toru-where "$pkg")"
+ test -z "$w" && continue
+
+ # copy to work dir if not already
+ test -d "$pkg" || cp -r "$w" "$pkg"
+ pushd "$pkg" &>/dev/null
+
+ term_title "$pkg($order)"
+
+ msg "Building %s" ${pkg}
+
+ # upgrade the system
+ sudo -E pacman -Syu --noconfirm
+
+ # run the pre build command from libretools.conf
+ ${HOOKPREBUILD}
+
+ # run the build command
+ ${FULLBUILDCMD}
+
+ # Run local release hook with $1 = $repo
+ ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")"
+
+ # it's built!
+ touch built_ok
+
+ popd &>/dev/null
+done
+
+popd &>/dev/null
+# cleanup
+rm -rf ${log} "${temp_dir}"
+
+term_title "done"