Control: tags -1 + patch

The attached patches should now make pbuilder accept the current restriction
formula syntax which was introduced during the bootstrap sprint in paris,
August 2014.

cheers, josch
From 78e19cc47f5d768da0efd6d4c4d47ebe2b9226b2 Mon Sep 17 00:00:00 2001
From: Johannes Schauer <jo...@debian.org>
Date: Thu, 28 May 2015 12:25:06 +0200
Subject: [PATCH 1/2] move filter_arch_deps from
 pbuilder-satisfydepends-aptitude to pbuilder-satisfydepends-funcs and add
 tests

---
 pbuilder-satisfydepends-aptitude   | 32 --------------------------------
 pbuilder-satisfydepends-funcs      | 31 +++++++++++++++++++++++++++++++
 test_pbuilder-satisfydepends-funcs | 16 ++++++++++++++++
 3 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/pbuilder-satisfydepends-aptitude b/pbuilder-satisfydepends-aptitude
index 97c58e5..31f5353 100755
--- a/pbuilder-satisfydepends-aptitude
+++ b/pbuilder-satisfydepends-aptitude
@@ -25,38 +25,6 @@ export PBUILDER_PKGLIBDIR="${PBUILDER_PKGLIBDIR:-$PBUILDER_ROOT/usr/lib/pbuilder
 
 . "$PBUILDER_PKGLIBDIR"/pbuilder-satisfydepends-funcs
 
-
-# filter out dependencies sent on input not for this arch; deps can have
-# multiple lines; output is on a single line or "" if empty
-function filter_arch_deps() {
-    local arch="$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_archdeps "$INSTALLPKG" "$ARCH"; then
-                        continue
-                    fi
-                fi
-                # output the selected package
-                echo "$INSTALLPKG"
-            done |
-            # remove the arch list and add " | " between entries
-            sed 's/\[.*\]//; $,$! s/$/ |/' |
-            xargs --no-run-if-empty
-    done |
-    # add ", " between entries
-    sed '$,$! s/$/,/' |
-    xargs --no-run-if-empty
-}
-
 function checkbuilddep_internal () {
 # Use this function to fulfill the dependency (almost)
     local ARCH=$($CHROOTEXEC dpkg-architecture -qDEB_HOST_ARCH)
diff --git a/pbuilder-satisfydepends-funcs b/pbuilder-satisfydepends-funcs
index 6c8dc28..e028fa2 100755
--- a/pbuilder-satisfydepends-funcs
+++ b/pbuilder-satisfydepends-funcs
@@ -117,6 +117,37 @@ get_build_conflicts() {
     echo "$output"
 }
 
+# filter out dependencies sent on input not for this arch; deps can have
+# multiple lines; output is on a single line or "" if empty
+filter_arch_deps() {
+    local arch="$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_archdeps "$INSTALLPKG" "$arch"; then
+                        continue
+                    fi
+                fi
+                # output the selected package
+                echo "$INSTALLPKG"
+            done |
+            # remove the arch 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"
diff --git a/test_pbuilder-satisfydepends-funcs b/test_pbuilder-satisfydepends-funcs
index 4eaa665..aafef2b 100755
--- a/test_pbuilder-satisfydepends-funcs
+++ b/test_pbuilder-satisfydepends-funcs
@@ -84,6 +84,22 @@ expect_output "autotools-dev (>= 1.2), debhelper, quilt (<< 12:0), libwxgtk2.8-d
 expect_output "autotools-dev (>= 1.2), debhelper, quilt (<< 12:0), libwxgtk2.8-dev" \
     test_get_build_deps "yes"
 
+expect_fail checkbuilddep_archdeps "foo [amd64]" "amd64"
+expect_success checkbuilddep_archdeps "foo [i386]" "amd64"
+expect_fail checkbuilddep_archdeps "foo [i386 amd64]" "amd64"
+expect_success checkbuilddep_archdeps "foo [!amd64]" "amd64"
+expect_success checkbuilddep_archdeps "foo [!i386 !amd64]" "amd64"
+
+test_filter_arch_deps() {
+    echo "$1" | filter_arch_deps "$2"
+}
+
+expect_output "foo" test_filter_arch_deps "foo" "amd64"
+expect_output "foo" test_filter_arch_deps "foo [amd64]" "amd64"
+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_output "debhelper (>= 7)" test_get_build_deps_dsc
 
 testlib_summary
-- 
2.1.4

From bb053e90f10e21a7872fde0b18ba781c88d85cd2 Mon Sep 17 00:00:00 2001
From: Johannes Schauer <jo...@debian.org>
Date: Thu, 28 May 2015 12:29:25 +0200
Subject: [PATCH 2/2] build profile parsing support

---
 pbuilder-satisfydepends-aptitude   |  6 ++--
 pbuilder-satisfydepends-funcs      | 73 ++++++++++++++++++++++++++++++++++++++
 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
-- 
2.1.4

Attachment: signature.asc
Description: signature

Reply via email to