summaryrefslogtreecommitdiff
path: root/src/dagpkg
diff options
context:
space:
mode:
Diffstat (limited to 'src/dagpkg')
-rwxr-xr-xsrc/dagpkg146
1 files changed, 75 insertions, 71 deletions
diff --git a/src/dagpkg b/src/dagpkg
index 3856e0b..c7fbb49 100755
--- a/src/dagpkg
+++ b/src/dagpkg
@@ -26,15 +26,6 @@ set -e
. "$(librelib messages)"
. "$(librelib conf)"
-# Source variables from libretools
-load_files libretools
-check_vars libretools FULLBUILDCMD || exit 1
-#check_vars libretools HOOKPREBUILD HOOKLOCALRELEASE || exit 1 # optional
-
-# Source variables from makepkg
-load_files makepkg
-check_vars makepkg CARCH || exit 1
-
# Globals:
# - temp_dir
# - log
@@ -60,8 +51,6 @@ trap_exit() {
kill "-$signal" "$$"
}
-setup_traps trap_exit
-
source_pkgbuild() {
# Source this PKGBUILD, if it doesn't exist, exit
if ! load_PKGBUILD &>/dev/null; then
@@ -86,18 +75,6 @@ source_pkgbuild() {
name="${pkgbase:-${pkgname[0]}}"
}
-source_pkgbuild
-
-# A temporary work dir and log file
-temp_dir="${1:-$(mktemp -dt ${name}-testpkg-XXXX)}"
-log="${temp_dir}/buildorder"
-
-# Mark array for DFS-based topological sort. See
-# https://en.wikipedia.org/wiki/Topological_sort for an explanation of
-# the algorithm. Key: package name, value: 0 for unvisited package, 1
-# during visit, 2 after visit.
-declare -A marks
-
# Visit a PKGBUILD for graph building.
visit_pkgbuild() {
# The name of the previous package
@@ -159,65 +136,92 @@ visit_pkgbuild() {
echo "$name" >> "${log}"
}
-# 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 [ -z "${1}" ]; then
- # Visit the root PKGBUILD to make the graph.
- visit_pkgbuild ""
-else
- msg "Resuming build..."
-fi
-
-# enter work dir
-pushd "${temp_dir}" &>/dev/null
-nl ${log} | while read order pkg; do
- # skip if already built
- if test -f "${pkg}/built_ok"; then
- warning "tried to build %s twice" "%{pkg}"
- continue
+main() {
+ # Source variables from libretools
+ load_files libretools
+ check_vars libretools FULLBUILDCMD || exit 1
+ #check_vars libretools HOOKPREBUILD HOOKLOCALRELEASE || exit 1 # optional
+
+ # Source variables from makepkg
+ load_files makepkg
+ check_vars makepkg CARCH || exit 1
+
+ setup_traps trap_exit
+
+ source_pkgbuild
+
+ # A temporary work dir and log file
+ temp_dir="${1:-$(mktemp -dt ${name}-testpkg-XXXX)}"
+ log="${temp_dir}/buildorder"
+
+ # Mark array for DFS-based topological sort. See
+ # https://en.wikipedia.org/wiki/Topological_sort for an explanation of
+ # the algorithm. Key: package name, value: 0 for unvisited package, 1
+ # during visit, 2 after visit.
+ declare -A marks
+
+ # 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 [ -z "${1}" ]; then
+ # Visit the root PKGBUILD to make the graph.
+ visit_pkgbuild ""
+ else
+ msg "Resuming build..."
fi
- # where's this package?
- local w="$(toru-where "$pkg")"
- test -z "$w" && continue
+ # enter work dir
+ pushd "${temp_dir}" &>/dev/null
+ nl ${log} | while read order pkg; do
+ # skip if already built
+ if test -f "${pkg}/built_ok"; then
+ warning "tried to build %s twice" "%{pkg}"
+ continue
+ fi
+
+ # where's this package?
+ local w="$(toru-where "$pkg")"
+ test -z "$w" && continue
- # copy to work dir if not already
- # this means you can make modifications to the pkgbuild during the
- # graph build or remove the dir after a build failure and let dagpkg
- # copy a new version
- test -d "$pkg" || cp -r "$w" "$pkg"
- pushd "$pkg" &>/dev/null
+ # copy to work dir if not already
+ # this means you can make modifications to the pkgbuild during the
+ # graph build or remove the dir after a build failure and let dagpkg
+ # copy a new version
+ test -d "$pkg" || cp -r "$w" "$pkg"
+ pushd "$pkg" &>/dev/null
- term_title "%s(%s)" "$pkg" "$order"
+ term_title "%s(%s)" "$pkg" "$order"
- msg "Building %s" ${pkg}
+ msg "Building %s" ${pkg}
- # upgrade the system
- # this would probably have to go on HOOKPREBUILD if you're working
- # outside chroots
- sudo -E pacman -Syu --noconfirm
+ # upgrade the system
+ # this would probably have to go on HOOKPREBUILD if you're working
+ # outside chroots
+ sudo -E pacman -Syu --noconfirm
- # run the pre build command from libretools.conf
- if [[ -n "$HOOKPREBUILD" ]]; then
- ${HOOKPREBUILD}
- fi
+ # run the pre build command from libretools.conf
+ if [[ -n "$HOOKPREBUILD" ]]; then
+ ${HOOKPREBUILD}
+ fi
- # run the build command
- ${FULLBUILDCMD}
+ # run the build command
+ ${FULLBUILDCMD}
- # Run local release hook with $1 = $repo
- if [[ -n "$HOOKLOCALRELEASE" ]]; then
- ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")"
- fi
+ # Run local release hook with $1 = $repo
+ if [[ -n "$HOOKLOCALRELEASE" ]]; then
+ ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")"
+ fi
- # it's built!
- touch built_ok
+ # it's built!
+ touch built_ok
+
+ popd &>/dev/null
+ done
popd &>/dev/null
-done
+ # cleanup
+ rm -rf ${log} "${temp_dir}"
-popd &>/dev/null
-# cleanup
-rm -rf ${log} "${temp_dir}"
+ term_title "done"
+}
-term_title "done"
+main "$@"