From 4c6bb6654ac5a2b4d62bc2129e2d030663b76674 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 5 Mar 2014 10:15:22 -0500 Subject: dagpkg: use tab indent --- src/dagpkg | 202 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 101 insertions(+), 101 deletions(-) (limited to 'src/dagpkg') diff --git a/src/dagpkg b/src/dagpkg index 49d6ef1..090d45d 100755 --- a/src/dagpkg +++ b/src/dagpkg @@ -30,10 +30,10 @@ source $XDG_CONFIG_HOME/.makepkg.conf &>/dev/null || true # End inmediately but print an useful message trap_exit() { - term_title "error!" - error "(%s) %s (leftovers on %s)" \ - "${0##*/}" "$@" "${temp_dir}" - exit 1 + term_title "error!" + error "(%s) %s (leftovers on %s)" \ + "${0##*/}" "$@" "${temp_dir}" + exit 1 } # Trap signals from makepkg @@ -42,26 +42,26 @@ trap 'trap_exit "Aborted by user! Exiting..."' INT trap 'trap_exit "An unknown error has occurred. Exiting..."' ERR source_pkgbuild() { - # Source this PKGBUILD, if it doesn't exist, exit - unset pkgbase pkgname depends makedepends - unset pkgrel pkgver epoch - if ! source ./PKGBUILD &>/dev/null ; then - error "No PKGBUILD in %s" "$PWD" - exit 1 - fi - - # Save resources - unset pkgdesc license groups backup install md5sums sha1sums \ - sha256sums source options &>/dev/null - - unset build package &>/dev/null - - for _pkg in ${pkgname[@]}; do - unset package_${_pkg} &>/dev/null || true - done - - # This is the name of the package - name="${pkgbase:-${pkgname[0]}}" + # Source this PKGBUILD, if it doesn't exist, exit + unset pkgbase pkgname depends makedepends + unset pkgrel pkgver epoch + if ! source ./PKGBUILD &>/dev/null ; then + error "No PKGBUILD in %s" "$PWD" + exit 1 + fi + + # Save resources + unset pkgdesc license groups backup install md5sums sha1sums \ + sha256sums source options &>/dev/null + + unset build package &>/dev/null + + for _pkg in ${pkgname[@]}; do + unset package_${_pkg} &>/dev/null || true + done + + # This is the name of the package + name="${pkgbase:-${pkgname[0]}}" } source_pkgbuild @@ -72,12 +72,12 @@ 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 [ $1 -eq 0 ]; then + # zero epoch case, don't include it in version + echo $2-$3 + else + echo $1:$2-$3 + fi } @@ -89,112 +89,112 @@ declare -A marks # Visit a PKGBUILD for graph building. visit_pkgbuild() { - # The name of the previous package - prev="${1}" + # The name of the previous package + prev="${1}" - local name - source_pkgbuild + local name + source_pkgbuild - # If it's already built we don't bother - is_built ${pkgname[0]} $(get_fullver ${epoch:-0} ${pkgver} ${pkgrel}) && - return + # If it's already built we don't bother + is_built ${pkgname[0]} $(get_fullver ${epoch:-0} ${pkgver} ${pkgrel}) && + return - # Detect cycle or already visited package - case "${marks[$name]:-0}" in - 1) msg2 "cycle found with %s depending on %s" $prev $name - exit 1;; - 2) return;; - esac + # Detect cycle or already visited package + case "${marks[$name]:-0}" in + 1) msg2 "cycle found with %s depending on %s" $prev $name + exit 1;; + 2) return;; + esac - msg "%s (%s)" ${name} ${prev} + msg "%s (%s)" ${name} ${prev} - echo "${arch[@]}" | grep -qw "$CARCH" || - warning "%s isn't ported to %s yet" ${name} ${CARCH} + echo "${arch[@]}" | grep -qw "$CARCH" || + warning "%s isn't ported to %s yet" ${name} ${CARCH} - # If the envvar I contains this package, ignore it and exit - echo "$I" | grep -qw "$name" && - msg2 "%s ignored" ${name} && - return + # If the envvar I contains this package, ignore it and exit + echo "$I" | grep -qw "$name" && + msg2 "%s ignored" ${name} && + return - # Mark the package as being visited - marks[$name]=1 + # Mark the package as being visited + marks[$name]=1 - # Recurse into dependencies - for d in ${depends[@]} ${makedepends[@]}; do - # Cleanup dependency versions - d=$(echo $d | sed "s/[<>=].*//") + # 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) + # Where's the pkgbuild? + w=$(toru-where $d) - # Skip if not available - test -z "$w" && continue + # Skip if not available + test -z "$w" && continue - # Go to this dir - pushd $w &>/dev/null + # Go to this dir + pushd $w &>/dev/null - visit_pkgbuild "$name" + visit_pkgbuild "$name" - popd &>/dev/null - done + popd &>/dev/null + done - # Mark the package as finished - marks[$name]=2 - # Append it to the reversed list of packages to build. - echo "$name" >> "${log}" + # Mark the package as finished + marks[$name]=2 + # Append it to the reversed list of packages to build. + 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 "" + # Visit the root PKGBUILD to make the graph. + visit_pkgbuild "" else - msg "Resuming build..." + 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 - fi + # skip if already built + if test -f "${pkg}/built_ok"; then + warning "tried to build %s twice" "%{pkg}" + continue + fi - # where's this package? - w="$(toru-where "$pkg")" - test -z "$w" && continue + # where's this package? + 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 "$pkg($order)" + term_title "$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 - ${HOOKPREBUILD} + # run the pre build command from libretools.conf + ${HOOKPREBUILD} - # run the build command - ${FULLBUILDCMD} + # run the build command + ${FULLBUILDCMD} - # Run local release hook with $1 = $repo - ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")" + # Run local release hook with $1 = $repo + ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")" - # it's built! - touch built_ok + # it's built! + touch built_ok - popd &>/dev/null + popd &>/dev/null done popd &>/dev/null -- cgit v1.2.3-2-g168b From 19896860cab0ecee691bf336c98c2c2b18ea5e20 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 5 Mar 2014 11:20:14 -0500 Subject: dagpkg: Do a couple things the librelib way --- src/dagpkg | 71 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) (limited to 'src/dagpkg') diff --git a/src/dagpkg b/src/dagpkg index 090d45d..1e13114 100755 --- a/src/dagpkg +++ b/src/dagpkg @@ -3,8 +3,8 @@ # dagpkg - create a directed graph of package dependencies and build # them in topological order # -# (c) 2014 Nicolás Reynolds -# Michał Masłowski +# Copyright (C) 2014 Nicolás Reynolds +# Copyright (C) 2014 Michał Masłowski # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,37 +20,42 @@ # along with this program. If not, see . set -e +source $(librelib conf) + # Source variables from libretools -source /etc/libretools.conf -source $XDG_CONFIG_HOME/libretools/libretools.conf &>/dev/null || true +load_files libretools +check_vars libretools FULLBUILDCMD || exit 1 +#check_vars libretools HOOKPREBUILD HOOKLOCALRELEASE || exit 1 # optional # Source variables from makepkg -source /etc/makepkg.conf -source $XDG_CONFIG_HOME/.makepkg.conf &>/dev/null || true +load_files makepkg +check_vars makepkg CARCH || exit 1 + # End inmediately but print an useful message trap_exit() { + local signal=$1; shift + local msg=("$@") term_title "error!" + echo error "(%s) %s (leftovers on %s)" \ - "${0##*/}" "$@" "${temp_dir}" - exit 1 + "${0##*/}" "$(print "${msg[@]}")" "${temp_dir}" + trap -- "$signal" + kill "-$signal" "$$" } -# 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 +setup_traps trap_exit source_pkgbuild() { # Source this PKGBUILD, if it doesn't exist, exit - unset pkgbase pkgname depends makedepends - unset pkgrel pkgver epoch - if ! source ./PKGBUILD &>/dev/null ; then + if ! load_PKGBUILD &>/dev/null; then error "No PKGBUILD in %s" "$PWD" exit 1 fi # Save resources + # This is intentionally less exhaustive than unset_PKGBUILD() + # XXX: document which things we actually *want* to not be unset. unset pkgdesc license groups backup install md5sums sha1sums \ sha256sums source options &>/dev/null @@ -70,17 +75,6 @@ source_pkgbuild temp_dir="${1:-$(mktemp -dt ${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 - -} - # 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 @@ -96,8 +90,9 @@ visit_pkgbuild() { source_pkgbuild # If it's already built we don't bother - is_built ${pkgname[0]} $(get_fullver ${epoch:-0} ${pkgver} ${pkgrel}) && - return + if is_built "${pkgname[0]}" "$(get_full_version "${pkgname[0]}")"; then + return + fi # Detect cycle or already visited package case "${marks[$name]:-0}" in @@ -108,13 +103,15 @@ visit_pkgbuild() { msg "%s (%s)" ${name} ${prev} - echo "${arch[@]}" | grep -qw "$CARCH" || - warning "%s isn't ported to %s yet" ${name} ${CARCH} + if ! in_array "${CARCH}" "${arch[@]}"; then + warning "%s isn't ported to %s yet" ${name} ${CARCH} + fi # If the envvar I contains this package, ignore it and exit - echo "$I" | grep -qw "$name" && - msg2 "%s ignored" ${name} && - return + if in_array "$name" $I; then + msg2 "%s ignored" ${name} + return + fi # Mark the package as being visited marks[$name]=1 @@ -183,13 +180,17 @@ nl ${log} | while read order pkg; do sudo -E pacman -Syu --noconfirm # run the pre build command from libretools.conf - ${HOOKPREBUILD} + if [[ -n "$HOOKPREBUILD" ]]; then + ${HOOKPREBUILD} + fi # run the build command ${FULLBUILDCMD} # Run local release hook with $1 = $repo - ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")" + if [[ -n "$HOOKLOCALRELEASE" ]]; then + ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")" + fi # it's built! touch built_ok -- cgit v1.2.3-2-g168b From cb9e36694cb02b7190d806fc41e7e3927aabedbd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 5 Mar 2014 11:28:04 -0500 Subject: dagpkg: be more careful with variables --- src/dagpkg | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/dagpkg') diff --git a/src/dagpkg b/src/dagpkg index 1e13114..5c38495 100755 --- a/src/dagpkg +++ b/src/dagpkg @@ -31,6 +31,18 @@ check_vars libretools FULLBUILDCMD || exit 1 load_files makepkg check_vars makepkg CARCH || exit 1 +# Globals: +# - temp_dir +# - log +# - name (sort of, it's also local to visit_pkgbuild() ) +# - prev +# - I +# - marks +# - various PKGBUILD variables: +# - pkgbase/pkgname +# - epoch/pkgver/pkgrel +# - arch +# - {,make,check}depends # End inmediately but print an useful message trap_exit() { @@ -61,8 +73,9 @@ source_pkgbuild() { unset build package &>/dev/null - for _pkg in ${pkgname[@]}; do - unset package_${_pkg} &>/dev/null || true + local _pkg + for _pkg in "${pkgname[@]}"; do + unset "package_${_pkg}" &>/dev/null || true done # This is the name of the package @@ -117,12 +130,13 @@ visit_pkgbuild() { marks[$name]=1 # Recurse into dependencies - for d in ${depends[@]} ${makedepends[@]}; do + local d + for d in "${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}"; do # Cleanup dependency versions d=$(echo $d | sed "s/[<>=].*//") # Where's the pkgbuild? - w=$(toru-where $d) + local w=$(toru-where $d) # Skip if not available test -z "$w" && continue @@ -160,7 +174,7 @@ nl ${log} | while read order pkg; do fi # where's this package? - w="$(toru-where "$pkg")" + local w="$(toru-where "$pkg")" test -z "$w" && continue # copy to work dir if not already -- cgit v1.2.3-2-g168b From b799bc5422ae1bc411e1725b5bb081a21f7afaef Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 5 Mar 2014 11:51:50 -0500 Subject: dagpkg: load libremessages --- src/dagpkg | 1 + 1 file changed, 1 insertion(+) (limited to 'src/dagpkg') diff --git a/src/dagpkg b/src/dagpkg index 5c38495..8e997a6 100755 --- a/src/dagpkg +++ b/src/dagpkg @@ -20,6 +20,7 @@ # along with this program. If not, see . set -e +source libremessages source $(librelib conf) # Source variables from libretools -- cgit v1.2.3-2-g168b From d25f30f25ce61367c81133c9cd01fe3169d8f6c0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 21 Mar 2014 14:39:06 -0400 Subject: Do an audit of copyright and license claims --- src/dagpkg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/dagpkg') diff --git a/src/dagpkg b/src/dagpkg index 8e997a6..e1487d5 100755 --- a/src/dagpkg +++ b/src/dagpkg @@ -2,10 +2,12 @@ # # dagpkg - create a directed graph of package dependencies and build # them in topological order -# + # Copyright (C) 2014 Nicolás Reynolds # Copyright (C) 2014 Michał Masłowski # +# License: GNU GPLv3+ +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or -- cgit v1.2.3-2-g168b