[pbuilder] 01/03: Refactor control file parsing to be more generic, and add dsc_get_basename

James Clarke jrtc27 at moszumanska.debian.org
Fri Jan 13 18:09:54 UTC 2017


This is an automated email from the git hooks/post-receive script.

jrtc27 pushed a commit to branch wip/source-only-changes
in repository pbuilder.

commit 1b9d8c521d33a7043b4684615cd6ba950b9847e4
Author: James Clarke <jrtc27 at jrtc27.com>
Date:   Fri Jan 6 16:15:56 2017 +0000

    Refactor control file parsing to be more generic, and add dsc_get_basename
---
 pbuilder-buildpackage-funcs        | 40 +++++++++++++++++++++
 pbuilder-modules                   | 54 +++++++++++++++++++++++++++++
 pbuilder-satisfydepends-apt        |  1 -
 pbuilder-satisfydepends-funcs      | 71 ++++++++++++--------------------------
 t/data/dsc3_epoch                  | 54 +++++++++++++++++++++++++++++
 t/data/dsc4_native                 | 42 ++++++++++++++++++++++
 t/test_pbuilder-buildpackage-funcs | 31 +++++++++++++++++
 7 files changed, 243 insertions(+), 50 deletions(-)

diff --git a/pbuilder-buildpackage-funcs b/pbuilder-buildpackage-funcs
index 911f5e3..739f02d 100644
--- a/pbuilder-buildpackage-funcs
+++ b/pbuilder-buildpackage-funcs
@@ -54,6 +54,46 @@ function copydsc () {
     done
 }
 
+function dsc_get_basename() {
+    local dscfile="$1"
+    local with_revision="$2"
+
+    local src=$(get822field "Source" "$dscfile")
+    local source_version=$(get822field "Version" "$dscfile")
+
+    # Parse version string
+    local epoch
+    local version
+    local revision
+    case "$source_version" in
+        *:*)
+            epoch=${source_version%%:*}
+            source_version=${source_version#*:}
+            ;;
+        *)
+            ;;
+    esac
+    case "$source_version" in
+        *-*)
+            version=${source_version%-*}
+            revision=${source_version##*-}
+            ;;
+        *)
+            version=$source_version
+            ;;
+    esac
+
+    local vs
+    # Epoch always omitted
+    case "$with_revision" in
+        yes) vs="${version}-${revision}" ;;
+        no)  vs="${version}" ;;
+        *)   log.error "unexpected with_revision: $with_revision" ; exit 1 ;;
+    esac
+
+    echo "${src}_${vs}"
+}
+
 function checkbuilddep () {
     # call satisfydepends
     local BUILDOPT="--binary-all"
diff --git a/pbuilder-modules b/pbuilder-modules
index 98171ef..472a036 100644
--- a/pbuilder-modules
+++ b/pbuilder-modules
@@ -849,6 +849,60 @@ function install_packages_for_optional_features() {
     fi
 }
 
+function get822field() {
+    local field="$1"
+    local file="$2"
+
+    sed -n '
+# Skip PGP header
+/^-----BEGIN PGP SIGNED MESSAGE-----$/ {
+    : pgploop
+    n
+    /^$/ b leadloop
+    b pgploop
+}
+
+# Skip empty lines/comments
+: leadloop
+/^[ \t]*$/ {
+    n
+    b leadloop
+}
+/^#/ {
+    n
+    b leadloop
+}
+
+# First line of paragraph
+: paraloop
+# Strip field name from line if present
+s/^'"$field"': *//i
+# If field present, print contents
+# Note the h; t loop; here rather than t store; so that there is no leading
+# newline in the hold space. This will store unmatched lines in the hold space,
+# but that does not matter as the first matched line will overwrite it.
+h
+t loop
+# Otherwise, check for end of paragraph or ignore
+/^[ \t]*$/q
+n
+b paraloop
+
+: store
+H
+: loop
+$ b done
+n
+/^#/ b loop
+/^[ \t]/ b store
+: done
+x
+p
+n
+b paraloop' \
+    "$file"
+}
+
 #==========================================================================
 # hooks stuff
 
diff --git a/pbuilder-satisfydepends-apt b/pbuilder-satisfydepends-apt
index 21652b6..91c3ac7 100755
--- a/pbuilder-satisfydepends-apt
+++ b/pbuilder-satisfydepends-apt
@@ -23,7 +23,6 @@ set -e
 
 export PBUILDER_PKGLIBDIR="${PBUILDER_PKGLIBDIR:-$PBUILDER_ROOT/usr/lib/pbuilder}"
 
-. "$PBUILDER_PKGLIBDIR"/pbuilder-modules
 . "$PBUILDER_PKGLIBDIR"/pbuilder-satisfydepends-funcs
 
 function checkbuilddep_internal () {
diff --git a/pbuilder-satisfydepends-funcs b/pbuilder-satisfydepends-funcs
index de7233e..4095f09 100755
--- a/pbuilder-satisfydepends-funcs
+++ b/pbuilder-satisfydepends-funcs
@@ -21,6 +21,7 @@
 
 # module to satisfy build dependencies; common functions
 
+. "${BASH_SOURCE%/*}/pbuilder-modules"
 
 package_versions() {
     local PACKAGE="$1"
@@ -53,47 +54,22 @@ checkbuilddep_versiondeps() {
 }
 
 get_source_control_field() {
-    local field="$1"
-
-    sed -n '
-# Skip PGP header
-/^-----BEGIN PGP SIGNED MESSAGE-----$/ {
-    : pgploop
-    n
-    /^$/ b leadloop
-    b pgploop
-}
-
-# Skip empty lines/comments
-: leadloop
-/^[ \t]*$/ {
-    n
-    b leadloop
-}
-/^#/ {
-    n
-    b leadloop
+    get822field "$1" "$DEBIAN_CONTROL"
 }
 
-# First line of source paragraph
-: sourceloop
-# Strip field name from line if present
-s/^'"$field"'://i
-# If field present, print normalised contents
-t store
-# Otherwise, check for end of paragraph or ignore
-/^[ \t]*$/q
-n
-b sourceloop
-
+get_build_depends_field() {
+    get_source_control_field "$1" | sed -n '
+# Note the h; b loop; here so that there is no leading
+# newline in the hold space
+h
+b loop
 : store
 H
 : loop
-$ b skip
+$ b done
 n
-/^#/ b loop
-/^[ \t]/ b store
-: skip
+b store
+: done
 x
 # output on single line
 s/\n//g
@@ -116,30 +92,27 @@ s/(\(>>\|>=\|>\|==\|=\|<=\|<<\|<\|!=\) *\([^)]*\))/(\1 \2)/g
 # normalize space at beginning and end of line
 s/^ *//
 s/ *$//
-p
-n
-b sourceloop' \
-        "$DEBIAN_CONTROL"
+p'
 }
 
 get_build_deps() {
     local output
 
-    output="$(get_source_control_field "Build-Depends")"
+    output="$(get_build_depends_field "Build-Depends")"
     output="${output%, }"
     case "$BINARY_ARCH" in
         any)
-            output="${output:+$output, }$(get_source_control_field "Build-Depends-Indep")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Depends-Indep")"
             output="${output%, }"
-            output="${output:+$output, }$(get_source_control_field "Build-Depends-Arch")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Depends-Arch")"
             output="${output%, }"
             ;;
         binary)
-            output="${output:+$output, }$(get_source_control_field "Build-Depends-Arch")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Depends-Arch")"
             output="${output%, }"
             ;;
         all)
-            output="${output:+$output, }$(get_source_control_field "Build-Depends-Indep")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Depends-Indep")"
             output="${output%, }"
             ;;
     esac
@@ -149,21 +122,21 @@ get_build_deps() {
 get_build_conflicts() {
     local output
 
-    output="$(get_source_control_field "Build-Conflicts")"
+    output="$(get_build_depends_field "Build-Conflicts")"
     output="${output%, }"
      case "$BINARY_ARCH" in
         any)
-            output="${output:+$output, }$(get_source_control_field "Build-Conflicts-Indep")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Conflicts-Indep")"
             output="${output%, }"
-            output="${output:+$output, }$(get_source_control_field "Build-Conflicts-Arch")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Conflicts-Arch")"
             output="${output%, }"
             ;;
         binary)
-            output="${output:+$output, }$(get_source_control_field "Build-Conflicts-Arch")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Conflicts-Arch")"
             output="${output%, }"
             ;;
         all)
-            output="${output:+$output, }$(get_source_control_field "Build-Conflicts-Indep")"
+            output="${output:+$output, }$(get_build_depends_field "Build-Conflicts-Indep")"
             output="${output%, }"
             ;;
     esac
diff --git a/t/data/dsc3_epoch b/t/data/dsc3_epoch
new file mode 100644
index 0000000..d1d3af0
--- /dev/null
+++ b/t/data/dsc3_epoch
@@ -0,0 +1,54 @@
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA256
+
+Format: 3.0 (quilt)
+Source: openssh
+Binary: openssh-client, openssh-client-ssh1, openssh-server, openssh-sftp-server, ssh, ssh-krb5, ssh-askpass-gnome, openssh-client-udeb, openssh-server-udeb
+Architecture: any all
+Version: 1:7.4p1-5
+Maintainer: Debian OpenSSH Maintainers <debian-ssh at lists.debian.org>
+Uploaders: Colin Watson <cjwatson at debian.org>, Matthew Vernon <matthew at debian.org>,
+Homepage: http://www.openssh.com/
+Standards-Version: 3.9.8
+Vcs-Browser: https://anonscm.debian.org/cgit/pkg-ssh/openssh.git
+Vcs-Git: https://anonscm.debian.org/git/pkg-ssh/openssh.git
+Testsuite: autopkgtest
+Testsuite-Triggers: devscripts, openssl, putty-tools, python-twisted-conch, sudo
+Build-Depends: autotools-dev, debhelper (>= 9~), dh-autoreconf, dh-exec, dh-systemd (>= 1.4), dpkg-dev (>= 1.16.1~), libaudit-dev [linux-any], libedit-dev, libgtk-3-dev, libkrb5-dev | heimdal-dev, libpam0g-dev | libpam-dev, libselinux1-dev [linux-any], libssl1.0-dev | libssl-dev (<< 1.1.0~), libsystemd-dev [linux-any], libwrap0-dev | libwrap-dev, zlib1g-dev (>= 1:1.2.3)
+Package-List:
+ openssh-client deb net standard arch=any
+ openssh-client-ssh1 deb net extra arch=any
+ openssh-client-udeb udeb debian-installer optional arch=any
+ openssh-server deb net optional arch=any
+ openssh-server-udeb udeb debian-installer optional arch=any
+ openssh-sftp-server deb net optional arch=any
+ ssh deb net extra arch=all
+ ssh-askpass-gnome deb gnome optional arch=any
+ ssh-krb5 deb oldlibs extra arch=all
+Checksums-Sha1:
+ 2330bbf82ed08cf3ac70e0acf00186ef3eeb97e0 1511780 openssh_7.4p1.orig.tar.gz
+ 4b49d5343fbbca3e0268558c7827ac4e8157ff84 157404 openssh_7.4p1-5.debian.tar.xz
+Checksums-Sha256:
+ 1b1fc4a14e2024293181924ed24872e6f2e06293f3e8926a376b8aec481f19d1 1511780 openssh_7.4p1.orig.tar.gz
+ 7cd48ba265be55eac54956ee2cb94c265f1885c74af328e2eadd73ce44357955 157404 openssh_7.4p1-5.debian.tar.xz
+Files:
+ b2db2a83caf66a208bb78d6d287cdaa3 1511780 openssh_7.4p1.orig.tar.gz
+ 6f07a6e5c9db2c8115d81949936cc0df 157404 openssh_7.4p1-5.debian.tar.xz
+
+-----BEGIN PGP SIGNATURE-----
+Comment: Colin Watson <cjwatson at debian.org> -- Debian developer
+
+iQIzBAEBCAAdFiEErApP8SYRtvzPAcEROTWH2X2GUAsFAlhruL8ACgkQOTWH2X2G
+UAs0xg/9H0xati4RXChKEE9BC3EPJayCLFaZ474S6umPGHrs4DpURMVAwIc0HW6l
+jxEq6ulKBv4JdneKYOTJCHzo2HEr0sHSzUm7B+u2j9mvNk4Qv8zZ1cwxkn/CHK6E
+DwgKMNU7WwRsjV08leVKhb6Z7WLAxDJ//1h7QHSGRdmOuqB/nImqdZwDNADfrLBc
+m1JHOgLB1V4SStdP4byBnuszKVF5hOlWTgTEoiylxVIEuGIS+Eb1y/qbs1Aw6Eff
+A6vObfSef5m5Z/8RWwdxpBlKfQe8bbl5eiG3N2moMy4Xc2fAAGhs64QcFWO4HLhL
+iylzLmMa9Pp2mGhc67UsmEc3ZAQ/LPwjoOLMay+UAZ7x98EyCFCKHOHvk3dooawx
+PeUX7qjZGkgw901zM0DZv+a2Ti5AuAg40Kko7v0ZR+/+EC7aT6/TBDBS+6NvN/pk
+rMATZjyQ2Y08zbIAuAFZLwl350jSSixDNiyCEidIj1fc7Q6YPrxHDCHieI7iarA3
+T+n1RbFFkidInQgkZpbuKleD/Le2x8Wvb/1JG9gLzwo+qYJZoYwt1tAvyN6QEEji
+itnNWs0nalW11N9LSKfp/K3W4ojdC8hCeRdiPnF6Cjfewbra7LM1QnDrPXLbb9sF
+n+EDwGESOWc1EHuzrUpAWnGDf9tm3KQYh8WNdWVgZ+YWfoD08zk=
+=cWkx
+-----END PGP SIGNATURE-----
diff --git a/t/data/dsc4_native b/t/data/dsc4_native
new file mode 100644
index 0000000..8a015e7
--- /dev/null
+++ b/t/data/dsc4_native
@@ -0,0 +1,42 @@
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA512
+
+Format: 3.0 (native)
+Source: cowdancer
+Binary: cowdancer, cowbuilder, qemubuilder
+Architecture: any
+Version: 0.82
+Maintainer: Debian pbuilder maintenance team <pbuilder-maint at lists.alioth.debian.org>
+Uploaders: James Clarke <jrtc27 at jrtc27.com>, Mattia Rizzolo <mattia at debian.org>,
+Standards-Version: 3.9.8
+Vcs-Browser: https://anonscm.debian.org/git/pbuilder/cowdancer.git
+Vcs-Git: https://anonscm.debian.org/git/pbuilder/cowdancer.git
+Build-Depends: cpio, debhelper (>= 10), dh-exec, klibc-utils [linux-any], libklibc-dev [linux-any], libncurses-dev, pbuilder
+Package-List:
+ cowbuilder deb utils optional arch=any
+ cowdancer deb utils optional arch=any
+ qemubuilder deb utils optional arch=linux-any
+Checksums-Sha1:
+ 05438b1752994ac39a62491eb4ca7f10c6d3b13b 69428 cowdancer_0.82.tar.xz
+Checksums-Sha256:
+ 79614c398007b2934217a9547902b01c35d89cbf2639a518b6587d36c8c41cd3 69428 cowdancer_0.82.tar.xz
+Files:
+ efc191462239628c4e942886cd846ec3 69428 cowdancer_0.82.tar.xz
+
+-----BEGIN PGP SIGNATURE-----
+
+iQJGBAEBCgAwFiEEj1g0K+q+HvQ3lVH7sZN3DBhqHH0FAlhEuUwSHGpydGMyN0Bq
+cnRjMjcuY29tAAoJELGTdwwYahx9umsP/RMAJQLJNp+Q4i+CTIwsssIpOF4IuWQ9
+gn0ecHwKoW2etxO+dHGIfMFeWOa5HqazPIjJGLBq5vk0DgMm/XOi4/F4qeP9YDN/
+oTdNW26fKoU6NNSmoSUjXhupsIqsojcvNe17mQnWX9LLkyTvT0WvKp85ybBo2TCH
+VqtYlqV8L2Ozs1P+ZzNeoQPH7yTWx12RnIaOFjacBRLf78z8Jpzm45GA/7eQ/Zzk
+7YqJyr2DySGUBVvcRNijcjanKBLe1wqRcHDmLRaudvXuZGB6kvQ2PnKDt2btR0qw
+GK5PSvaiZVKhovp21+506KGGFx6Q5mfTQ2oFy32nQVuGPPoMcpPYqgJ1hOyfiPkK
+aXhSu4iyEzOcERESdRjt9A/enkRi6c42i776v2ANRW6I2GvB4bu0YMqgnPtoMwLC
+Jt7beTUpBbW4/F1O+VMgFrd0c7gCsH0IHZmpWbmByMUU/tiXUapN6FNHnDqS7OSq
+GXjUtupZvCZKRbTvQg9B4lO4JF8eBkOC5c1ZO5qvpLTtrjUIG7xx5E8gisNpgqkD
+gE1I+ZC1OF7bjgjnUyhHIWJPFTP0ae4yVGktAxH7h6BaUavzVStYjXc/+lXp+L3l
+daQ8UyWSp8nxd2PludeJ4yZcboxbHxuA4US6BpDtXr73ugepS0eWgYX72yHNIb96
+UfFacf2+7jwm
+=Y9MG
+-----END PGP SIGNATURE-----
diff --git a/t/test_pbuilder-buildpackage-funcs b/t/test_pbuilder-buildpackage-funcs
index 1160a10..46eaae6 100755
--- a/t/test_pbuilder-buildpackage-funcs
+++ b/t/test_pbuilder-buildpackage-funcs
@@ -54,6 +54,30 @@ test_getchangesfilesNormal () {
     get822files changes "$DEBIAN_CONTROL"
 }
 
+test_dsc_get_basename_normal_with_revision() {
+    dsc_get_basename "$TESTDATA_DIR/dsc1" yes
+}
+
+test_dsc_get_basename_normal_without_revision() {
+    dsc_get_basename "$TESTDATA_DIR/dsc1" no
+}
+
+test_dsc_get_basename_epoch_with_revision() {
+    dsc_get_basename "$TESTDATA_DIR/dsc3_epoch" yes
+}
+
+test_dsc_get_basename_epoch_without_revision() {
+    dsc_get_basename "$TESTDATA_DIR/dsc3_epoch" no
+}
+
+test_dsc_get_basename_native_with_revision() {
+    dsc_get_basename "$TESTDATA_DIR/dsc4_native" yes
+}
+
+test_dsc_get_basename_native_without_revision() {
+    dsc_get_basename "$TESTDATA_DIR/dsc4_native" no
+}
+
 setup_extraresults () {
     mkdir -p "$TEMP_DIR/fake-pkg/debian"
     touch "$TEMP_DIR/file_with_*_asterisk"
@@ -89,6 +113,13 @@ expect_output "$DEBIAN_CONTROL $TEMP_DIR/haskell-concrete-typerep_0.1.0.2.orig.t
 expect_output "$DEBIAN_CONTROL $TEMP_DIR/golang-xmpp-dev_0.0~git20140304.orig.tar.gz $TEMP_DIR/golang-xmpp-dev_0.0~git20140304-1.debian.tar.xz" test_getdscfilesWithoutNL
 expect_output "$DEBIAN_CONTROL $TEMP_DIR/pbuilder_0.225.2~bpo8+1.dsc $TEMP_DIR/pbuilder_0.225.2~bpo8+1.tar.xz $TEMP_DIR/pbuilder_0.225.2~bpo8+1_all.deb" test_getchangesfilesNormal
 
+expect_output "haskell-concrete-typerep_0.1.0.2-2" test_dsc_get_basename_normal_with_revision
+expect_output "haskell-concrete-typerep_0.1.0.2" test_dsc_get_basename_normal_without_revision
+expect_output "openssh_7.4p1-5" test_dsc_get_basename_epoch_with_revision
+expect_output "openssh_7.4p1" test_dsc_get_basename_epoch_without_revision
+expect_output "cowdancer_0.82" test_dsc_get_basename_native_with_revision
+expect_output "cowdancer_0.82" test_dsc_get_basename_native_without_revision
+
 setup_extraresults
 expect_output "$TEMP_DIR/fake-pkg/../file with spaces.changes
 $TEMP_DIR/fake-pkg/../file_with_a_normal_name.changes" test_extraresults1

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pbuilder/pbuilder.git



More information about the Pbuilder-maint mailing list