diff options
-rwxr-xr-x | pbuilder-satisfydepends-aptitude | 6 | ||||
-rwxr-xr-x | pbuilder-satisfydepends-funcs | 73 | ||||
-rwxr-xr-x | test_pbuilder-satisfydepends-funcs | 50 |
3 files changed, 127 insertions, 2 deletions
diff --git a/pbuilder-satisfydepends-aptitude b/pbuilder-satisfydepends-aptitude index 31f5353..f96486e 100755 --- a/pbuilder-satisfydepends-aptitude +++ b/pbuilder-satisfydepends-aptitude @@ -33,8 +33,10 @@ function checkbuilddep_internal () { local DEPENDS local CONFLICTS echo " -> Attempting to satisfy build-dependencies" - DEPENDS="$(get_build_deps | filter_arch_deps "$ARCH")" - CONFLICTS="$(get_build_conflicts | filter_arch_deps "$ARCH")" + DEPENDS="$(get_build_deps | filter_arch_deps "$ARCH" | + filter_restriction_deps \"$DEB_BUILD_PROFILES\" )" + CONFLICTS="$(get_build_conflicts | filter_arch_deps "$ARCH" | + filter_restriction_deps \"$DEB_BUILD_PROFILES\" )" echo " -> Creating pbuilder-satisfydepends-dummy package" BUILD_DEP_DEB_DIR="/tmp/satisfydepends-aptitude" BUILD_DEP_DEB_CONTROL="$BUILD_DEP_DEB_DIR/pbuilder-satisfydepends-dummy/DEBIAN/control" diff --git a/pbuilder-satisfydepends-funcs b/pbuilder-satisfydepends-funcs index e028fa2..30d487b 100755 --- a/pbuilder-satisfydepends-funcs +++ b/pbuilder-satisfydepends-funcs @@ -148,6 +148,37 @@ filter_arch_deps() { xargs --no-run-if-empty } +# filter out dependencies sent on input not for selected build profiles; deps +# can have multiple lines; output is on a single line or "" if empty +filter_restriction_deps() { + local profiles="$1" + local INSTALLPKGMULTI + local INSTALLPKG + + # split on "," + sed 's/[[:space:]]*,[[:space:]]*/\n/g' | + while read INSTALLPKGMULTI; do + echo "$INSTALLPKGMULTI" | + # split on "|" + sed 's/[[:space:]]*|[[:space:]]*/\n/g' | + while read INSTALLPKG; do + if echo "$INSTALLPKG" | grep -q '<'; then + if checkbuilddep_restrictiondeps "$INSTALLPKG" "$profiles"; then + continue + fi + fi + # output the selected package + echo "$INSTALLPKG" + done | + # remove the restriction list and add " | " between entries + sed 's/<.*>//; $,$! s/$/ |/' | + xargs --no-run-if-empty + done | + # add ", " between entries + sed '$,$! s/$/,/' | + xargs --no-run-if-empty +} + checkbuilddep_archdeps() { # returns FALSE on INSTALL local INSTALLPKG="$1" @@ -182,6 +213,48 @@ checkbuilddep_archdeps() { return 1 } +checkbuilddep_restrictiondeps() { + # returns FALSE on INSTALL + local INSTALLPKG="$1" + local PROFILES="$2" + # restrictions listed between < and > for this dep + local DEP_RESTRICTIONS="$(echo "$INSTALLPKG" | sed -e 's/[^<]*<\(.*\)>.*/\1/' -e 's/>\s\+</;/g')" + local PKG="$(echo "$INSTALLPKG" | cut -d ' ' -f 1)" + local SEEN_PROFILE + local PROFILE + local NEGATED + local FOUND + IFS=';' read -ra RESTRLISTS <<< "$DEP_RESTRICTIONS" + for restrlist in "${RESTRLISTS[@]}"; do + SEEN_PROFILE="yes" + for restr in $restrlist; do + if [[ "$restr" == '!'* ]]; then + NEGATED="yes" + PROFILE=${restr#!} + else + NEGATED="no" + PROFILE=${restr} + fi + FOUND="no" + for p in $PROFILES; do + if [ "$p" = "$PROFILE" ]; then + FOUND="yes" + break + fi + done + if [ "$FOUND" = "$NEGATED" ]; then + SEEN_PROFILE="no" + break + fi + done + + if [ "$SEEN_PROFILE" = "yes" ]; then + return 1 + fi + done + return 0 +} + checkbuilddep_provides() { local PACKAGENAME="$1" # PROVIDED needs to be used outside of this function. diff --git a/test_pbuilder-satisfydepends-funcs b/test_pbuilder-satisfydepends-funcs index aafef2b..61a446f 100755 --- a/test_pbuilder-satisfydepends-funcs +++ b/test_pbuilder-satisfydepends-funcs @@ -100,6 +100,56 @@ expect_output "bar, foo" test_filter_arch_deps "bar, foo [amd64]" "amd64" expect_output "bar | foo" test_filter_arch_deps "bar | foo [amd64]" "amd64" expect_output "bar" test_filter_arch_deps "bar | foo [amd64]" "i386" +expect_fail checkbuilddep_restrictiondeps "foo <!stage1>" "" +expect_success checkbuilddep_restrictiondeps "foo <!stage1>" "stage1" +expect_fail checkbuilddep_restrictiondeps "foo <!stage1>" "notest" +expect_success checkbuilddep_restrictiondeps "foo <!stage1>" "stage1 notest" + +expect_success checkbuilddep_restrictiondeps "foo <stage1>" "" +expect_fail checkbuilddep_restrictiondeps "foo <stage1>" "stage1" +expect_success checkbuilddep_restrictiondeps "foo <stage1>" "notest" +expect_fail checkbuilddep_restrictiondeps "foo <stage1>" "stage1 notest" + +expect_fail checkbuilddep_restrictiondeps "foo <!stage1 !notest>" "" +expect_success checkbuilddep_restrictiondeps "foo <!stage1 !notest>" "stage1" +expect_success checkbuilddep_restrictiondeps "foo <!stage1 !notest>" "notest" +expect_success checkbuilddep_restrictiondeps "foo <!stage1 !notest>" "stage1 notest" + +expect_success checkbuilddep_restrictiondeps "foo <stage1 notest>" "" +expect_success checkbuilddep_restrictiondeps "foo <stage1 notest>" "stage1" +expect_success checkbuilddep_restrictiondeps "foo <stage1 notest>" "notest" +expect_fail checkbuilddep_restrictiondeps "foo <stage1 notest>" "stage1 notest" + +expect_success checkbuilddep_restrictiondeps "foo <!stage1 notest>" "" +expect_success checkbuilddep_restrictiondeps "foo <!stage1 notest>" "stage1" +expect_fail checkbuilddep_restrictiondeps "foo <!stage1 notest>" "notest" +expect_success checkbuilddep_restrictiondeps "foo <!stage1 notest>" "stage1 notest" + +expect_success checkbuilddep_restrictiondeps "foo <stage1 !notest>" "" +expect_fail checkbuilddep_restrictiondeps "foo <stage1 !notest>" "stage1" +expect_success checkbuilddep_restrictiondeps "foo <stage1 !notest>" "notest" +expect_success checkbuilddep_restrictiondeps "foo <stage1 !notest>" "stage1 notest" + +test_filter_restriction_deps() { + echo "$1" | filter_restriction_deps "$2" +} + +expect_output "foo" test_filter_restriction_deps "foo <!stage1>" "" +expect_output "" test_filter_restriction_deps "foo <!stage1>" "stage1" +expect_output "foo" test_filter_restriction_deps "foo <stage1>" "stage1" +expect_output "bar, foo" test_filter_restriction_deps "bar, foo <stage1>" "stage1" +expect_output "bar | foo" test_filter_restriction_deps "bar | foo <stage1>" "stage1" +expect_output "bar" test_filter_restriction_deps "bar | foo <!stage1>" "stage1" + +test_filter_arch_restriction_deps() { + echo "$1" | filter_arch_deps "$2" | filter_restriction_deps "$3" +} + +expect_output "foo" test_filter_arch_restriction_deps "foo [amd64] <!stage1>" "amd64" "" +expect_output "" test_filter_arch_restriction_deps "foo [amd64] <stage1>" "amd64" "" +expect_output "foo" test_filter_arch_restriction_deps "foo [amd64] <!stage1>" "amd64" "" +expect_output "" test_filter_arch_restriction_deps "foo [i386] <stage1>" "amd64" "stage1" + expect_output "debhelper (>= 7)" test_get_build_deps_dsc testlib_summary |