diff -pruN 0.80.0/bin/sbuild 0.80.0ubuntu1/bin/sbuild
--- 0.80.0/bin/sbuild	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/bin/sbuild	2020-08-04 14:28:23.000000000 +0000
@@ -84,10 +84,6 @@ sub main () {
 	my $jobname = $ARGV[0];
 	my $source_dir = 0;
 
-	if (-e $jobname) {
-	    $jobname = abs_path($jobname);
-	}
-
 	if (-d $jobname) {
 	    $jobname = create_source_package($jobname);
 	    if ($jobname eq '.') {
@@ -171,6 +167,7 @@ sub main () {
 
 sub create_source_package ($) {
     my $dsc = shift;
+    $dsc = abs_path($dsc);
 
     open(my $pipe, '-|', 'dpkg-parsechangelog',
 	 '-l' . $dsc . '/debian/changelog')
diff -pruN 0.80.0/db/.gitignore 0.80.0ubuntu1/db/.gitignore
--- 0.80.0/db/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/db/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1 +0,0 @@
-db.sql
diff -pruN 0.80.0/debian/changelog 0.80.0ubuntu1/debian/changelog
--- 0.80.0/debian/changelog	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/debian/changelog	2020-08-04 14:28:23.000000000 +0000
@@ -1,3 +1,15 @@
+sbuild (0.80.0ubuntu1) groovy; urgency=medium
+
+  * Resynchronize on Debian, remaining changes
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+    - d/t/control: add isolation-machine to the test flags
+
+ -- Sebastien Bacher <seb128@ubuntu.com>  Tue, 04 Aug 2020 16:28:23 +0200
+
 sbuild (0.80.0) unstable; urgency=medium
 
   [ Johannes 'josch' Schauer ]
@@ -25,6 +37,24 @@ sbuild (0.80.0) unstable; urgency=medium
 
  -- Johannes 'josch' Schauer <josch@debian.org>  Sat, 01 Aug 2020 14:07:53 +0200
 
+sbuild (0.79.1-1ubuntu3) groovy; urgency=medium
+
+  * Fix autopkg test with dpkg 1.20.x.
+
+ -- Matthias Klose <doko@ubuntu.com>  Tue, 28 Jul 2020 14:51:53 +0200
+
+sbuild (0.79.1-1ubuntu1) groovy; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+    - d/t/control: add isolation-machine to the test flags
+
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Fri, 01 May 2020 15:32:56 -0700
+
 sbuild (0.79.1-1) unstable; urgency=medium
 
   * Team upload.
@@ -37,6 +67,21 @@ sbuild (0.79.1-1) unstable; urgency=medi
 
  -- Ivo De Decker <ivodd@debian.org>  Wed, 22 Apr 2020 22:35:33 +0000
 
+sbuild (0.79.0-1ubuntu1) focal; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+    - d/t/control: add isolation-machine to the test flags
+   * Dropped changes, included in Debian:
+    - d/t/build-procenv: only install the built package if the chroot it was
+      built in matches the release of the host system
+
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Thu, 13 Feb 2020 12:26:35 -0800
+
 sbuild (0.79.0-1) unstable; urgency=medium
 
   * Team upload.
@@ -54,6 +99,22 @@ sbuild (0.79.0-1) unstable; urgency=medi
 
  -- Ivo De Decker <ivodd@debian.org>  Wed, 05 Feb 2020 17:41:38 +0100
 
+sbuild (0.78.1-2ubuntu1) eoan; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+    - d/t/control: add isolation-machine to the test flags
+    - d/t/build-procenv: only install the built package if the chroot it was
+      built in matches the release of the host system
+  * Dropped changes, included upstream:
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Thu, 02 May 2019 16:24:29 -0700
+
 sbuild (0.78.1-2) unstable; urgency=medium
 
   [ Mike Gabriel ]
@@ -112,12 +173,44 @@ sbuild (0.78.0-1) unstable; urgency=medi
 
  -- Johannes 'josch' Schauer <josch@debian.org>  Wed, 09 Jan 2019 05:53:49 +0100
 
+sbuild (0.77.1-2ubuntu2) disco; urgency=medium
+
+  * d/t/control: add isolation-machine to the test flags (LP: #1806389)
+  * d/t/build-procenv: only install the built package if the chroot it was
+    built in matches the release of the host system (LP: #1806388)
+
+ -- Andreas Hasenack <andreas@canonical.com>  Mon, 03 Dec 2018 11:47:38 -0200
+
+sbuild (0.77.1-2ubuntu1) disco; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Mon, 26 Nov 2018 06:23:57 +0100
+
 sbuild (0.77.1-2) unstable; urgency=medium
 
   * Add patch allowing to control merged /usr (closes: #913228)
 
  -- Johannes 'josch' Schauer <josch@debian.org>  Tue, 13 Nov 2018 16:07:19 +0100
 
+sbuild (0.77.1-1ubuntu1) cosmic; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Wed, 12 Sep 2018 11:47:20 +0200
+
 sbuild (0.77.1-1) unstable; urgency=medium
 
   * New upstream release.
@@ -127,6 +220,18 @@ sbuild (0.77.1-1) unstable; urgency=medi
 
  -- Johannes 'josch' Schauer <josch@debian.org>  Tue, 11 Sep 2018 00:08:08 +0200
 
+sbuild (0.77.0-4ubuntu1) cosmic; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Mon, 30 Jul 2018 10:11:49 +0200
+
 sbuild (0.77.0-4) unstable; urgency=medium
 
   * Add patch to fix the empty directory check of sbuild-create-chroot
@@ -134,12 +239,36 @@ sbuild (0.77.0-4) unstable; urgency=medi
 
  -- Johannes 'josch' Schauer <josch@debian.org>  Fri, 27 Jul 2018 14:03:10 +0200
 
+sbuild (0.77.0-3ubuntu1) cosmic; urgency=medium
+
+  * Merge from Debian Sid. Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Simon Quigley <tsimonq2@ubuntu.com>  Thu, 12 Jul 2018 22:36:11 -0500
+
 sbuild (0.77.0-3) unstable; urgency=medium
 
   * Patch sbuild-destroychroot with an import of SchrootInfo (closes: #903513)
 
  -- Johannes 'josch' Schauer <josch@debian.org>  Wed, 11 Jul 2018 21:32:04 +0200
 
+sbuild (0.77.0-2ubuntu1) cosmic; urgency=medium
+
+  * Merge from Debian Sid. Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Simon Quigley <tsimonq2@ubuntu.com>  Mon, 09 Jul 2018 17:13:42 -0500
+
 sbuild (0.77.0-2) unstable; urgency=medium
 
   * Install /usr/sbin/sbuild-adduser and /usr/sbin/sbuild-destroychroot again
@@ -209,12 +338,36 @@ sbuild (0.77.0-1) unstable; urgency=medi
 
  -- Johannes 'josch' Schauer <josch@debian.org>  Fri, 06 Jul 2018 23:11:45 +0200
 
+sbuild (0.76.0-1ubuntu1) cosmic; urgency=low
+
+  * Merge from Debian Sid (LP: #1770317). Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Simon Quigley <tsimonq2@ubuntu.com>  Thu, 10 May 2018 00:13:10 -0500
+
 sbuild (0.76.0-1) unstable; urgency=medium
 
   * Install sbuild-debian-developer-setup-update-all cronjob (closes: #893577)
 
  -- Michael Stapelberg <stapelberg@debian.org>  Mon, 09 Apr 2018 18:58:38 +0200
 
+sbuild (0.75.0-1ubuntu1) bionic; urgency=low
+
+  * Merge from Debian Sid (LP: #1756195). Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Simon Quigley <tsimonq2@ubuntu.com>  Fri, 23 Mar 2018 00:15:11 -0500
+
 sbuild (0.75.0-1) unstable; urgency=medium
 
   * New upstream release.
@@ -224,6 +377,18 @@ sbuild (0.75.0-1) unstable; urgency=medi
 
  -- Michael Stapelberg <stapelberg@debian.org>  Wed, 21 Mar 2018 22:24:01 +0100
 
+sbuild (0.74.0-1ubuntu1) bionic; urgency=medium
+
+  * Merge from Debian Sid (LP: #1756195). Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default.
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Simon Quigley <tsimonq2@ubuntu.com>  Sat, 17 Mar 2018 00:56:58 -0500
+
 sbuild (0.74.0-1) unstable; urgency=medium
 
   * New upstream release
@@ -243,6 +408,18 @@ sbuild (0.74.0-1) unstable; urgency=medi
 
  -- Michael Stapelberg <stapelberg@debian.org>  Wed, 14 Mar 2018 21:55:42 +0100
 
+sbuild (0.73.0-4ubuntu1) zesty; urgency=medium
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Wed, 01 Feb 2017 16:04:29 +0100
+
 sbuild (0.73.0-4) unstable; urgency=medium
 
   * Retroactively add two entries into debian/NEWS for the Stretch release.
@@ -256,6 +433,23 @@ sbuild (0.73.0-3) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Sun, 22 Jan 2017 15:03:49 +0100
 
+sbuild (0.73.0-2ubuntu1) zesty; urgency=medium
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+  * Drop changes merged in Debian
+    - Set APT::Sandbox::User=root when running apt-get source in the
+      build-procenv autopkgtest, to avoid stderr noise from current apt.
+    - Silence a couple of warnings from sbuild-createchroot which caused some
+      autopkgtest runs to fail.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Thu, 19 Jan 2017 09:27:07 +0100
+
 sbuild (0.73.0-2) unstable; urgency=medium
 
   * Bump build-depends on libdpkg-perl to 1.18.14 as sbuild is using
@@ -336,6 +530,22 @@ sbuild (0.73.0-1) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Sat, 24 Dec 2016 02:28:48 +0100
 
+sbuild (0.72.0-2ubuntu1) zesty; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - Set APT::Sandbox::User=root when running apt-get source in the
+      build-procenv autopkgtest, to avoid stderr noise from current apt.
+    - Silence a couple of warnings from sbuild-createchroot which caused some
+      autopkgtest runs to fail.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Tue, 22 Nov 2016 10:02:25 +0100
+
 sbuild (0.72.0-2) unstable; urgency=medium
 
   * Fix regression from 0.72.0 upload: install forward file as .forward and
@@ -378,6 +588,22 @@ sbuild (0.72.0-1) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Tue, 25 Oct 2016 07:43:07 +0200
 
+sbuild (0.71.0-2ubuntu1) yakkety; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - Set APT::Sandbox::User=root when running apt-get source in the
+      build-procenv autopkgtest, to avoid stderr noise from current apt.
+    - Silence a couple of warnings from sbuild-createchroot which caused some
+      autopkgtest runs to fail.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Mon, 29 Aug 2016 08:22:14 +0200
+
 sbuild (0.71.0-2) unstable; urgency=medium
 
   * add patch to not check for the fakeroot binary on the host. Thanks
@@ -387,6 +613,32 @@ sbuild (0.71.0-2) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Sat, 27 Aug 2016 11:20:06 +0200
 
+sbuild (0.71.0-1ubuntu2) yakkety; urgency=medium
+
+  * cherry-pick from Debian:
+    - add patch to not check for the fakeroot binary on the host. Thanks
+      Gianfranco Costamagna
+    - Do not recommend fakeroot anymore. It is not needed on the host but only
+      inside the chroot.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Fri, 26 Aug 2016 12:38:10 +0200
+
+sbuild (0.71.0-1ubuntu1) yakkety; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - Set APT::Sandbox::User=root when running apt-get source in the
+      build-procenv autopkgtest, to avoid stderr noise from current apt.
+    - Silence a couple of warnings from sbuild-createchroot which caused some
+      autopkgtest runs to fail.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Fri, 26 Aug 2016 08:22:46 +0200
+
 sbuild (0.71.0-1) unstable; urgency=medium
 
   * add autopkgtest to Suggests
@@ -418,6 +670,22 @@ sbuild (0.71.0-1) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Wed, 24 Aug 2016 13:42:26 +0200
 
+sbuild (0.70.0-1ubuntu1) yakkety; urgency=medium
+
+  * Merge from Debian unstable. Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - Set APT::Sandbox::User=root when running apt-get source in the
+      build-procenv autopkgtest, to avoid stderr noise from current apt.
+    - Silence a couple of warnings from sbuild-createchroot which caused some
+      autopkgtest runs to fail.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Wed, 03 Aug 2016 12:33:10 +0200
+
 sbuild (0.70.0-1) unstable; urgency=medium
 
   * new upstream version
@@ -477,6 +745,25 @@ sbuild (0.70.0-1) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Wed, 03 Aug 2016 10:58:48 +0200
 
+sbuild (0.69.0-2ubuntu1) yakkety; urgency=low
+
+  * Merge from Debian unstable (LP: #1591674). Remaining changes:
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - Set APT::Sandbox::User=root when running apt-get source in the
+      build-procenv autopkgtest, to avoid stderr noise from current apt.
+    - Silence a couple of warnings from sbuild-createchroot which caused some
+      autopkgtest runs to fail.
+    - utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+    - abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+      causing symlinks to files not ending in .dsc to no longer be buildable.
+  * Drop patches included/applied in Debian: apt-conf-quotes.patch,
+    copy-dummy-archive.patch, dummy-archive-sha512.patch,
+    fix-quoting-harder.patch
+
+ -- Gianfranco Costamagna <locutusofborg@debian.org>  Sun, 12 Jun 2016 12:48:21 +0200
+
 sbuild (0.69.0-2) unstable; urgency=medium
 
   * add patch 0001-lib-Sbuild-ResolverBase.pm-do-not-produce-non-error-.patch
@@ -556,12 +843,95 @@ sbuild (0.68.0-1) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Fri, 15 Jan 2016 10:18:53 +0100
 
+sbuild (0.67.0-2ubuntu7) xenial; urgency=medium
+
+  * utf-8-by-default.patch: Switch to C.UTF-8 by default (LP: #1566590)
+
+ -- Adam Conrad <adconrad@ubuntu.com>  Tue, 19 Apr 2016 07:51:15 -0600
+
+sbuild (0.67.0-2ubuntu6) xenial; urgency=medium
+
+  * dummy-archive-sha512.patch: Sbuild::ResolverBase: sign dummy archive
+    with SHA-512.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Thu, 07 Apr 2016 12:47:54 +0100
+
+sbuild (0.67.0-2ubuntu5) xenial; urgency=medium
+
+  * debian/patches/series: Patches apply much better when referenced here.
+
+ -- Adam Conrad <adconrad@ubuntu.com>  Mon, 28 Mar 2016 04:24:17 -0600
+
+sbuild (0.67.0-2ubuntu4) xenial; urgency=medium
+
+  * apt-conf-quotes.patch: Backport upstream commit to fix apt.conf quoting.
+
+ -- Adam Conrad <adconrad@ubuntu.com>  Mon, 28 Mar 2016 02:20:16 -0600
+
+sbuild (0.67.0-2ubuntu3) xenial; urgency=medium
+
+  * copy-dummy-archive.patch: Sbuild::ResolverBase: use copy: for dummy
+    archive.  Fixes launchpad-buildd crashes when analysing dep-waits.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Thu, 18 Feb 2016 14:32:21 +0000
+
+sbuild (0.67.0-2ubuntu2) xenial; urgency=medium
+
+  * abs-path-revert.patch: Revert upstream commit that breaks lp-buildd by
+    causing symlinks to files not ending in .dsc to no longer be buildable.
+  * fix-quoting-harder.patch: Switch from single to double quotes for args
+    when forking perl: "W: Stripped single quote from command for security"
+
+ -- Adam Conrad <adconrad@ubuntu.com>  Thu, 21 Jan 2016 03:19:26 -0700
+
+sbuild (0.67.0-2ubuntu1) xenial; urgency=low
+
+  * Merge with Debian.  Remaining changes:
+    - do-not-install-debfoster-into-chroots.patch: Do not install debfoster
+      into the chroots because it is in universe and not needed for package
+      building itself.
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+      package.
+    - Set APT::Sandbox::User=root when running apt-get source in the
+      build-procenv autopkgtest, to avoid stderr noise from current apt.
+    - Silence a couple of warnings from sbuild-createchroot which caused some
+      autopkgtest runs to fail.
+
+ -- Iain Lane <iain@orangesquash.org.uk>  Wed, 06 Jan 2016 09:46:08 +0000
+
 sbuild (0.67.0-2) unstable; urgency=medium
 
   * backport patch fix-quoting.patch (closes: #809175)
 
  -- Johannes Schauer <josch@debian.org>  Mon, 28 Dec 2015 03:23:42 +0100
 
+sbuild (0.67.0-1ubuntu3) xenial; urgency=medium
+
+  * Silence a couple of warnings from sbuild-createchroot which caused some
+    autopkgtest runs to fail.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Mon, 28 Dec 2015 14:00:28 +0000
+
+sbuild (0.67.0-1ubuntu2) xenial; urgency=medium
+
+  * Set APT::Sandbox::User=root when running apt-get source in the
+    build-procenv autopkgtest, to avoid stderr noise from current apt.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Mon, 28 Dec 2015 03:55:12 +0000
+
+sbuild (0.67.0-1ubuntu1) xenial; urgency=medium
+
+  * Resynchronise with Debian.  Remaining changes:
+    - do-not-install-debfoster-into-chroots.patch: Do not install debfoster
+      into the chroots because it is in universe and not needed for package
+      building itself.
+    - no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+      packages, as pkgbinarymangler's dpkg-deb expects to be run from a
+      source package.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Mon, 28 Dec 2015 00:09:27 +0000
+
 sbuild (0.67.0-1) unstable; urgency=medium
 
   * fix Vcs-Browser and Vcs-Git fields to point at the debian/unstable branch
@@ -611,6 +981,18 @@ sbuild (0.67.0-1) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Sat, 26 Dec 2015 15:19:29 +0100
 
+sbuild (0.66.0-5ubuntu1) xenial; urgency=medium
+
+  * Resynchronise with Debian.  Remaining changes:
+    - do-not-install-debfoster-into-chroots.patch: Do not install debfoster
+      into the chroots because it is in universe and not needed for package
+      building itself.
+  * no-pkg-mangle-deps.patch: Set NO_PKG_MANGLE=1 when building dummy
+    packages, as pkgbinarymangler's dpkg-deb expects to be run from a source
+    package.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Tue, 03 Nov 2015 13:02:14 +0000
+
 sbuild (0.66.0-5) unstable; urgency=medium
 
   * Backport commit 6456b3da to make sbuild binary packages reproducible
@@ -686,6 +1068,24 @@ sbuild (0.66.0-1) unstable; urgency=medi
 
  -- Johannes Schauer <josch@debian.org>  Sun, 04 Oct 2015 09:50:02 +0200
 
+sbuild (0.65.2-1ubuntu2) vivid; urgency=medium
+
+  * Backport from upstream:
+    - sbuild: Fix handling of exceptions while setting up chroot.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Wed, 15 Apr 2015 11:30:20 -0500
+
+sbuild (0.65.2-1ubuntu1) vivid; urgency=medium
+
+  * Resynchronise with Debian (LP: #1428656).  Remaining changes:
+    - debian/patches/do-not-install-debfoster-into-chroots.patch: do not
+      install debfoster into the chroots because it is in universe and not
+      needed for package building itself.
+  * Backport from upstream:
+    - sbuild: Don't sign dummy archive if apt_allow_unauthenticated is set.
+
+ -- Colin Watson <cjwatson@ubuntu.com>  Tue, 14 Apr 2015 10:16:02 -0500
+
 sbuild (0.65.2-1) unstable; urgency=medium
 
   * Team upload.
@@ -719,6 +1119,19 @@ sbuild (0.65.1-1) unstable; urgency=medi
 
  -- Ansgar Burchardt <ansgar@debian.org>  Tue, 24 Feb 2015 22:53:16 +0100
 
+sbuild (0.65.0-1ubuntu1) vivid; urgency=medium
+
+  * Merge from Debian unstable. Remaining changes:
+    - debian/patches/do-not-install-debfoster-into-chroots.patch: do not
+      install debfoster into the chroots because it is in universe and not
+      needed for package building itself.
+  * Dropped changes (merged into upstream):
+    - debian/patches/run-pre-build-hooks-as-root.patch: run pre-build hooks
+      as root.
+    - Added DEP-8 autopkgtest to build procenv.
+
+ -- Benjamin Drung <bdrung@ubuntu.com>  Sat, 25 Oct 2014 12:09:57 +0200
+
 sbuild (0.65.0-1) unstable; urgency=medium
 
   [ Benjamin Drung ]
@@ -804,6 +1217,59 @@ sbuild (0.64.2-1) unstable; urgency=low
 
  -- Luca Falavigna <dktrkranz@debian.org>  Fri, 12 Sep 2014 20:02:46 +0200
 
+sbuild (0.64.1-1ubuntu6) utopic; urgency=medium
+
+  * debian/tests/control: Updated Depends to allow more capable procenv to be
+    built. (LP: #1325896)
+
+ -- James Hunt <james.hunt@ubuntu.com>  Tue, 03 Jun 2014 10:30:03 +0100
+
+sbuild (0.64.1-1ubuntu5) utopic; urgency=medium
+
+  * debian/tests/build_procenv: Ask the host's apt for Acquire::http::Proxy
+    and use that for bootstrapping and the built schroot as well.
+  * debian/tests/build_procenv: Install apt-utils into the generated schroot,
+    to avoid "debconf: delaying package configuration, since apt-utils is not
+    installed" stderr message.
+
+ -- Martin Pitt <martin.pitt@ubuntu.com>  Wed, 04 Jun 2014 08:09:47 +0200
+
+sbuild (0.64.1-1ubuntu4) trusty; urgency=medium
+
+  * debian/source/include-binaries: Add static sbuild signing keys to work
+    around systems with little entropy.
+  * debian/tests/build_procenv: Install sbuild signing keys.
+  * debian/tests/control: Add libnuma1, required by test package that is
+    built (procenv).
+  * debian/tests/sbuild-key.{pub,sec}: Static sbuild signing keys.
+
+ -- James Hunt <james.hunt@ubuntu.com>  Wed, 05 Mar 2014 15:15:02 +0000
+
+sbuild (0.64.1-1ubuntu3) trusty; urgency=medium
+
+  * debian/tests/build_procenv: on Ubuntu, select the correct archive mirror
+    for the build architecture.
+
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Tue, 04 Mar 2014 16:18:11 -0800
+
+sbuild (0.64.1-1ubuntu2) trusty; urgency=medium
+
+  * debian/tests/control: Add missing debootstrap test dependency.
+
+ -- Martin Pitt <martin.pitt@ubuntu.com>  Tue, 25 Feb 2014 10:09:33 +0100
+
+sbuild (0.64.1-1ubuntu1) trusty; urgency=low
+
+  * Merge from Debian unstable. Remaining changes:
+    - debian/patches/do-not-install-debfoster-into-chroots.patch: do not
+      install debfoster into the chroots because it is in universe and not
+      needed for package building itself.
+    - debian/patches/run-pre-build-hooks-as-root.patch: run pre-build hooks
+      as root.
+    - Added DEP-8 autopkgtest to build procenv.
+
+ -- Marc Deslauriers <marc.deslauriers@ubuntu.com>  Mon, 04 Nov 2013 07:57:40 -0500
+
 sbuild (0.64.1-1) unstable; urgency=low
 
   [ Roger Leigh ]
@@ -820,6 +1286,25 @@ sbuild (0.64.1-1) unstable; urgency=low
 
  -- Roger Leigh <rleigh@debian.org>  Sun, 13 Oct 2013 19:35:57 +0100
 
+sbuild (0.64.0-1ubuntu2) trusty; urgency=low
+
+  * debian/tests/build_procenv: Add component universe for Ubuntu to make
+    procenv buildable (LP: #1247420)
+
+ -- Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>  Sat, 02 Nov 2013 22:45:08 +0100
+
+sbuild (0.64.0-1ubuntu1) saucy; urgency=low
+
+  * Merge from Debian unstable. Remaining changes:
+    - debian/patches/do-not-install-debfoster-into-chroots.patch: do not
+      install debfoster into the chroots because it is in universe and not
+      needed for package building itself.
+    - debian/patches/run-pre-build-hooks-as-root.patch: run pre-build hooks
+      as root.
+    - Added DEP-8 autopkgtest to build procenv.
+
+ -- Marc Deslauriers <marc.deslauriers@ubuntu.com>  Tue, 03 Sep 2013 09:04:59 -0400
+
 sbuild (0.64.0-1) unstable; urgency=low
 
   [ Thorsten Glaser ]
@@ -878,6 +1363,27 @@ sbuild (0.64.0-1) unstable; urgency=low
 
  -- Roger Leigh <rleigh@debian.org>  Fri, 17 May 2013 23:06:13 +0100
 
+sbuild (0.63.2-1.1ubuntu2) saucy; urgency=low
+
+  * Added DEP-8 autopkgtest to build procenv.
+
+ -- James Hunt <james.hunt@ubuntu.com>  Mon, 27 May 2013 10:18:26 +0200
+
+sbuild (0.63.2-1.1ubuntu1) raring; urgency=low
+
+  * Merge from Debian unstable. Remaining changes:
+    - Convert package back to source format 3.0 (quilt) so the patches get
+      applied.
+    - debian/patches/do-not-install-debfoster-into-chroots.patch: do not
+      install debfoster into the chroots because it is in universe and not
+      needed for package building itself.
+    - debian/patches/run-pre-build-hooks-as-root.patch: run pre-build hooks
+      as root.
+    - debian/patches/fix-rev-0.patch: convert inline change from 0.63.2-1.1
+      into patch.
+
+ -- Marc Deslauriers <marc.deslauriers@ubuntu.com>  Thu, 17 Jan 2013 08:59:27 -0500
+
 sbuild (0.63.2-1.1) unstable; urgency=low
 
   * Non-maintainer upload.
@@ -885,6 +1391,19 @@ sbuild (0.63.2-1.1) unstable; urgency=lo
 
  -- Roland Stigge <stigge@antcom.de>  Wed, 05 Dec 2012 14:44:45 +0100
 
+sbuild (0.63.2-1ubuntu1) raring; urgency=low
+
+  * Merge from Debian unstable. Remaining changes:
+    - debian/patches/do-not-install-debfoster-into-chroots.patch: do not
+      install debfoster into the chroots because it is in universe and not
+      needed for package building itself.
+    - debian/patches/run-pre-build-hooks-as-root.patch: run pre-build hooks
+      as root.
+    - Convert package back to source format 3.0 (quilt) so the patches get
+      applied.
+
+ -- Marc Deslauriers <marc.deslauriers@ubuntu.com>  Wed, 28 Nov 2012 07:44:25 -0500
+
 sbuild (0.63.2-1) unstable; urgency=low
 
   [ Roger Leigh ]
@@ -925,6 +1444,26 @@ sbuild (0.63.2-1) unstable; urgency=low
 
  -- Roger Leigh <rleigh@debian.org>  Sat, 18 Aug 2012 13:46:45 +0100
 
+sbuild (0.63.1-1ubuntu2) quantal; urgency=low
+
+  * Convert package back to source format 3.0 (quilt) so the patches get
+    applied.
+
+ -- Marc Deslauriers <marc.deslauriers@ubuntu.com>  Tue, 14 Aug 2012 12:42:58 -0400
+
+sbuild (0.63.1-1ubuntu1) quantal; urgency=low
+
+  * Resynchronize with Debian testing. Remaining changes:
+    - debian/patches/do-not-install-debfoster-into-chroots.patch:
+      do not install debfoster into the chroots because it is in universe and
+      not needed for package building itself.
+    - debian/patches/run-pre-build-hooks-as-root.patch:
+      run pre-build hooks as root
+  * Drop run-lintian-inside-chroot.patch: It hasn't been picked up
+    by Debian and doesn't work quite right (LP: #940410)
+
+ -- Jeremy Bicha <jbicha@ubuntu.com>  Sat, 23 Jun 2012 22:27:58 -0400
+
 sbuild (0.63.1-1) unstable; urgency=low
 
   [ Roger Leigh ]
@@ -3205,3 +3744,4 @@ sbuild (0.2) unstable; urgency=low
   * Initial package
 
  -- Rick Younie <younie@debian.org>  Thu,  8 Nov 2001 00:18:34 -0800
+
diff -pruN 0.80.0/debian/control 0.80.0ubuntu1/debian/control
--- 0.80.0/debian/control	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/debian/control	2020-08-04 14:28:23.000000000 +0000
@@ -1,7 +1,8 @@
 Source: sbuild
 Section: devel
 Priority: optional
-Maintainer: sbuild maintainers <sbuild@packages.debian.org>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: sbuild maintainers <sbuild@packages.debian.org>
 Uploaders: Johannes 'josch' Schauer <josch@debian.org>,
            Michael Banck <mbanck@debian.org>,
            Francesco Paolo Lovergine <frankie@debian.org>,
diff -pruN 0.80.0/debian/.gitignore 0.80.0ubuntu1/debian/.gitignore
--- 0.80.0/debian/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/debian/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1,10 +0,0 @@
-sbuild
-buildd
-files
-build
-install
-wanna-build
-libsbuild-perl
-*.substvars
-*.debhelper
-*.log
diff -pruN 0.80.0/debian/patches/abs-path-revert.patch 0.80.0ubuntu1/debian/patches/abs-path-revert.patch
--- 0.80.0/debian/patches/abs-path-revert.patch	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/debian/patches/abs-path-revert.patch	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1,24 @@
+Revert d15d5ea67b81cde811207ff6853b381c3ebe4b41
+Last-Update: 2016-06-28
+
+--- a/bin/sbuild
++++ b/bin/sbuild
+@@ -84,10 +84,6 @@ sub main () {
+ 	my $jobname = $ARGV[0];
+ 	my $source_dir = 0;
+ 
+-	if (-e $jobname) {
+-	    $jobname = abs_path($jobname);
+-	}
+-
+ 	if (-d $jobname) {
+ 	    $jobname = create_source_package($jobname);
+ 	    if ($jobname eq '.') {
+@@ -171,6 +167,7 @@ sub main () {
+ 
+ sub create_source_package ($) {
+     my $dsc = shift;
++    $dsc = abs_path($dsc);
+ 
+     open(my $pipe, '-|', 'dpkg-parsechangelog',
+ 	 '-l' . $dsc . '/debian/changelog')
diff -pruN 0.80.0/debian/patches/no-pkg-mangle-deps.patch 0.80.0ubuntu1/debian/patches/no-pkg-mangle-deps.patch
--- 0.80.0/debian/patches/no-pkg-mangle-deps.patch	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/debian/patches/no-pkg-mangle-deps.patch	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1,19 @@
+Description: Set NO_PKG_MANGLE=1 when building dummy packages
+ pkgbinarymangler's dpkg-deb expects to be run from a source package.
+Author: Colin Watson <cjwatson@ubuntu.com>
+Forwarded: not-needed
+Last-Update: 2016-06-28
+
+Index: sbuild-0.80.0ubuntu1/lib/Sbuild/ResolverBase.pm
+===================================================================
+--- sbuild-0.80.0ubuntu1.orig/lib/Sbuild/ResolverBase.pm
++++ sbuild-0.80.0ubuntu1/lib/Sbuild/ResolverBase.pm
+@@ -1218,7 +1218,7 @@ EOF
+ 
+     #Now build the package:
+     $session->run_command(
+-	{ COMMAND => ['dpkg-deb', '--build', $dummy_pkg_dir, $dummy_deb],
++	{ COMMAND => ['env', 'NO_PKG_MANGLE=1', 'dpkg-deb', '--build', $dummy_pkg_dir, $dummy_deb],
+ 	  USER => $self->get_conf('BUILD_USER'),
+ 	  PRIORITY => 0});
+     if ($?) {
diff -pruN 0.80.0/debian/patches/series 0.80.0ubuntu1/debian/patches/series
--- 0.80.0/debian/patches/series	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/debian/patches/series	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1,3 @@
+no-pkg-mangle-deps.patch
+abs-path-revert.patch
+
diff -pruN 0.80.0/debian/tests/control 0.80.0ubuntu1/debian/tests/control
--- 0.80.0/debian/tests/control	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/debian/tests/control	2020-08-04 14:28:23.000000000 +0000
@@ -1,3 +1,3 @@
 Tests: build-procenv
 Depends: @, debootstrap, distro-info, lsb-release, apt (>= 1.1~exp2), apt-utils
-Restrictions: needs-root
+Restrictions: needs-root, isolation-machine
diff -pruN 0.80.0/etc/.gitignore 0.80.0ubuntu1/etc/.gitignore
--- 0.80.0/etc/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/etc/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1 +0,0 @@
-profiles
diff -pruN 0.80.0/.gitattributes 0.80.0ubuntu1/.gitattributes
--- 0.80.0/.gitattributes	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/.gitattributes	1970-01-01 00:00:00.000000000 +0000
@@ -1,8 +0,0 @@
-.gitignore export-ignore
-.gitattributes export-ignore
-db/.gitignore export-ignore
-etc/.gitignore export-ignore
-lib/Sbuild/.gitignore export-ignore
-man/.gitignore export-ignore
-scripts/.gitignore export-ignore
-test/.gitignore export-ignore
diff -pruN 0.80.0/.gitignore 0.80.0ubuntu1/.gitignore
--- 0.80.0/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1,30 +0,0 @@
-*~
-.*.swp
-debian/sbuild.substvars
-*.1
-*.5
-*.7
-*.8
-*-stamp
-Makefile
-Makefile.in
-config.h
-config.h.in
-config.log
-config.status
-stamp-h1
-aclocal.m4
-autom4te.cache
-configure
-m4
-INSTALL
-ChangeLog
-*.o
-.deps
-.libs
-*.tar.*
-\#*
-.#*
-etc/buildd.conf
-etc/sbuild.conf
-scripts/test-driver
diff -pruN 0.80.0/lib/Sbuild/.gitignore 0.80.0ubuntu1/lib/Sbuild/.gitignore
--- 0.80.0/lib/Sbuild/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/lib/Sbuild/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1 +0,0 @@
-Sysconfig.pm
diff -pruN 0.80.0/lib/Sbuild/ResolverBase.pm 0.80.0ubuntu1/lib/Sbuild/ResolverBase.pm
--- 0.80.0/lib/Sbuild/ResolverBase.pm	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/lib/Sbuild/ResolverBase.pm	2020-08-04 14:28:23.000000000 +0000
@@ -1218,7 +1218,7 @@ EOF
 
     #Now build the package:
     $session->run_command(
-	{ COMMAND => ['dpkg-deb', '--build', $dummy_pkg_dir, $dummy_deb],
+	{ COMMAND => ['env', 'NO_PKG_MANGLE=1', 'dpkg-deb', '--build', $dummy_pkg_dir, $dummy_deb],
 	  USER => $self->get_conf('BUILD_USER'),
 	  PRIORITY => 0});
     if ($?) {
diff -pruN 0.80.0/man/.gitignore 0.80.0ubuntu1/man/.gitignore
--- 0.80.0/man/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/man/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1,7 +0,0 @@
-*.1
-*.5
-*.7
-*.8
-sbuild.conf.man
-buildd.conf.man
-defs.man
diff -pruN 0.80.0/.pc/abs-path-revert.patch/bin/sbuild 0.80.0ubuntu1/.pc/abs-path-revert.patch/bin/sbuild
--- 0.80.0/.pc/abs-path-revert.patch/bin/sbuild	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/.pc/abs-path-revert.patch/bin/sbuild	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1,383 @@
+#!/usr/bin/perl
+#
+# sbuild: build packages, obeying source dependencies
+# Copyright © 1998-2000 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
+# Copyright © 2005      Ryan Murray <rmurray@debian.org>
+# Copyright © 2005-2009 Roger Leigh <rleigh@debian.org
+# Copyright © 2008      Timothy G Abbott <tabbott@mit.edu>
+# Copyright © 2008      Simon McVittie <smcv@debian.org>
+#
+# 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+#######################################################################
+
+package main;
+
+use strict;
+use warnings;
+
+use Cwd qw(:DEFAULT abs_path);
+use File::Basename qw(basename dirname);
+use POSIX;
+use Data::Dumper;
+use Dpkg::Control;
+use Sbuild qw(isin check_group_membership $debug_level dsc_files debug);
+use Sbuild::Conf qw();
+use Sbuild::Sysconfig qw(%programs);
+use Sbuild::Options;
+use Sbuild::Build;
+use Sbuild::Exception;
+use Sbuild::Utility qw(check_url download);
+
+sub main ();
+sub create_source_package ($);
+sub download_source_package ($);
+sub write_jobs_file ();
+sub status_trigger ($$);
+sub shutdown ($);
+sub dump_main_state ();
+
+my $conf = Sbuild::Conf::new();
+exit 1 if !defined($conf);
+my $options = Sbuild::Options->new($conf, "sbuild", "1");
+exit 1 if !defined($options);
+check_group_membership() if $conf->get('CHROOT_MODE') eq 'schroot';
+
+if (!$conf->get('MAINTAINER_NAME') &&
+    ($conf->get('BIN_NMU') || $conf->get('APPEND_TO_VERSION'))) {
+	die "A maintainer name, uploader name or key ID must be specified in .sbuildrc,\nor use -m, -e or -k, when performing a binNMU or appending a version suffix\n";
+}
+
+umask(002);
+
+# Job state
+my $job = undef;
+
+main();
+
+sub main () {
+    $SIG{'INT'} = \&main::shutdown;
+    $SIG{'TERM'} = \&main::shutdown;
+    $SIG{'ALRM'} = \&main::shutdown;
+    $SIG{'PIPE'} = \&main::shutdown;
+
+    # If no arguments are supplied, assume we want to process the current dir.
+    push @ARGV, '.' unless (@ARGV);
+
+    die "Only one build is permitted\n"
+	if (@ARGV != 1);
+
+    # Create and run job
+    my $status = eval {
+	my $jobname = $ARGV[0];
+	my $source_dir = 0;
+
+	if (-e $jobname) {
+	    $jobname = abs_path($jobname);
+	}
+
+	if (-d $jobname) {
+	    $jobname = create_source_package($jobname);
+	    if ($jobname eq '.') {
+		chdir('..') or Sbuild::Exception::Build->throw(
+		    error => "Failed to change directory",
+		    failstage => "change-build-dir");
+		$conf->_set_default('BUILD_DIR', cwd());
+	    }
+	    $source_dir = 1;
+	} elsif (($jobname =~ m/\.dsc$/) && # Use apt to download
+		 check_url($jobname)) {
+	    # Valid URL
+	    $jobname = download_source_package($jobname);
+	}
+
+
+	# Check after source package build (which might set dist)
+	my $dist = $conf->get('DISTRIBUTION');
+	if (!defined($dist) || !$dist) {
+	    print STDERR "No distribution defined\n";
+	    exit(1);
+	}
+
+	print "Selected distribution " . $conf->get('DISTRIBUTION') . "\n"
+	    if $conf->get('DEBUG');
+	print "Selected chroot " . $conf->get('CHROOT') . "\n"
+	    if $conf->get('DEBUG') and defined $conf->get('CHROOT');
+	print "Selected host architecture " . $conf->get('HOST_ARCH') . "\n"
+	    if $conf->get('DEBUG' && defined($conf->get('HOST_ARCH')));
+	print "Selected build architecture " . $conf->get('BUILD_ARCH') . "\n"
+	    if $conf->get('DEBUG' && defined($conf->get('BUILD_ARCH')));
+	print "Selected build profiles " . $conf->get('BUILD_PROFILES') . "\n"
+	    if $conf->get('DEBUG' && defined($conf->get('BUILD_PROFILES')));
+
+	$job = Sbuild::Build->new($jobname, $conf);
+	$job->set('Pkg Status Trigger', \&status_trigger);
+	write_jobs_file(); # Will now update on trigger.
+
+	# Run job.
+	$job->run();
+
+	dump_main_state() if $conf->get('DEBUG');
+    };
+
+    my $e;
+    if ($e = Exception::Class->caught('Sbuild::Exception::Build')) {
+	print STDERR "E: $e\n";
+	print STDERR "I: " . $e->info . "\n"
+	    if ($e->info);
+	if ($debug_level) {
+	    #dump_main_state();
+	    #print STDERR $e->trace->as_string, "\n";
+	}
+    } elsif (!defined($e)) {
+	print STDERR "E: $@\n" if $@;
+    }
+
+    unlink($conf->get('JOB_FILE'))
+	if $conf->get('BATCH_MODE');
+
+    # Until buildd parses status info from sbuild output, skipped must
+    # be treated as a failure.
+    if (defined($job)) {
+	if ($job->get_status() eq "successful" ||
+	    ($conf->get('SBUILD_MODE') ne "buildd" &&
+	     $job->get_status() eq "skipped")) {
+	    exit 0;
+	} elsif ($job->get_status() eq "attempted") {
+	    exit 2;
+	} elsif ($job->get_status() eq "given-back") {
+	    #Probably needs a give back:
+	    exit 3;
+	}
+	# Unknown status - probably needs a give back, but needs to be
+	# reported to the admin as failure:
+	exit 1;
+    }
+    debug("Error main(): $@") if $@;
+    exit 1;
+}
+
+sub create_source_package ($) {
+    my $dsc = shift;
+
+    open(my $pipe, '-|', 'dpkg-parsechangelog',
+	 '-l' . $dsc . '/debian/changelog')
+	or Sbuild::Exception::Build->throw(
+	    error => "Could not parse $dsc/debian/changelog: $!",
+	    failstage => "pack-source");
+
+    my $pclog = Dpkg::Control->new(type => CTRL_CHANGELOG);
+    if (!$pclog->parse($pipe, 'dpkg-parsechangelog')) {
+	Sbuild::Exception::Build->throw(
+	    error => "Could not parse $dsc/debian/changelog: $!",
+	    failstage => "pack-source");
+    }
+
+    $pipe->close or Sbuild::Exception::Build->throw(
+	error => "dpkg-parsechangelog failed (exit status $?)",
+	failstage => "pack-source");
+
+    my $package = $pclog->{'Source'};
+    my $version = $pclog->{'Version'};
+
+    if (!defined($package) || !defined($version)) {
+	Sbuild::Exception::Build->throw(
+	    error => "Missing Source or Version in $dsc/debian/changelog",
+	    failstage => "pack-source");
+    }
+
+    my $dist = $pclog->{'Distribution'};
+    my $pver = Dpkg::Version->new($version, check => 1);
+    unless (defined $pver) {
+	Sbuild::Exception::Build->throw(
+	    error => "Bad version $version in $dsc/debian/changelog",
+	    failstage => "pack-source");
+    }
+
+    my ($uversion, $dversion);
+    $uversion = $pver->version();
+    $dversion = "-" . $pver->revision();
+    $dversion = "" if $pver->{'no_revision'};
+
+    if (!defined($conf->get('DISTRIBUTION')) ||
+	!$conf->get('DISTRIBUTION')) {
+	$conf->set('DISTRIBUTION', $dist);
+    }
+
+    my $dir = getcwd();
+    my $origdir=$dir;
+    my $origdsc=$dsc;
+    # Note: need to support cases when invoked from a subdirectory
+    # of the build directory, i.e. $dsc/foo -> $dsc/.. in addition
+    # to $dsc -> $dsc/.. as below.
+    # We won't attempt to build the source package from the source
+    # directory so the source package files will go to the parent dir.
+    my $dscdir = abs_path("$dsc/..");
+    if (index($dir, $dsc, 0) == 0) {
+	$conf->set('BUILD_DIR', $dscdir);
+    }
+
+    $dsc = "${dscdir}/${package}_${uversion}${dversion}.dsc";
+
+    $dir = $origdsc;
+
+    chdir($dir) or Sbuild::Exception::Build->throw(
+	error => "Failed to change directory",
+	failstage => "pack-source");
+    my @dpkg_source_before = ($conf->get('DPKG_SOURCE'), '--before-build');
+    push @dpkg_source_before, @{$conf->get('DPKG_SOURCE_OPTIONS')}
+	if ($conf->get('DPKG_SOURCE_OPTIONS'));
+    push @dpkg_source_before, '.';
+    system(@dpkg_source_before);
+    if ($?) {
+	Sbuild::Exception::Build->throw(
+	    error => "Failed to run dpkg-source --before-build " . getcwd(),
+	    failstage => "pack-source");
+    }
+    if ($conf->get('CLEAN_SOURCE')) {
+	system($conf->get('FAKEROOT'), 'debian/rules', 'clean');
+	if ($?) {
+	    Sbuild::Exception::Build->throw(
+		error => "Failed to clean source directory $dir ($dsc)",
+		failstage => "pack-source");
+	}
+    }
+    my @dpkg_source_command = ($conf->get('DPKG_SOURCE'), '-b');
+    push @dpkg_source_command, @{$conf->get('DPKG_SOURCE_OPTIONS')}
+    if ($conf->get('DPKG_SOURCE_OPTIONS'));
+    push @dpkg_source_command, '.';
+    system(@dpkg_source_command);
+    if ($?) {
+	Sbuild::Exception::Build->throw(
+	    error => "Failed to package source directory " . getcwd(),
+	    failstage => "pack-source");
+    }
+    my @dpkg_source_after = ($conf->get('DPKG_SOURCE'), '--after-build');
+    push @dpkg_source_after, @{$conf->get('DPKG_SOURCE_OPTIONS')}
+	if ($conf->get('DPKG_SOURCE_OPTIONS'));
+    push @dpkg_source_after, '.';
+    system(@dpkg_source_after);
+    if ($?) {
+	Sbuild::Exception::Build->throw(
+	    error => "Failed to run dpkg-source --after-build " . getcwd(),
+	    failstage => "pack-source");
+    }
+    chdir($origdir) or Sbuild::Exception::Build->throw(
+	error => "Failed to change directory",
+	failstage => "pack-source");
+
+    return $dsc;
+}
+
+sub download_source_package ($) {
+    my $dsc = shift;
+
+    my $srcdir = dirname($dsc);
+    my $dscbase = basename($dsc);
+
+    my @fetched;
+
+    # Work with a .dsc file.
+    # $file is the name of the downloaded dsc file written in a tempfile.
+    my $file;
+    $file = download($dsc, $dscbase) or
+	Sbuild::Exception::Build->throw(
+	    error => "Could not download $dsc",
+	    failstage => "download-source");
+    push(@fetched, $dscbase);
+
+    my @cwd_files = dsc_files($file);
+
+    foreach (@cwd_files) {
+	my $subfile = download("$srcdir/$_", $_);
+	if (!$subfile) {
+	    # Remove downloaded sources
+	    foreach my $rm (@fetched) {
+		unlink($rm);
+	    }
+	    Sbuild::Exception::Build->throw(
+		error => "Could not download $srcdir/$_",
+		failstage => "download-source");
+	}
+	push(@fetched, $_);
+    }
+
+    return $file;
+}
+
+# only called from main loop, but depends on job state.
+sub write_jobs_file () {
+    if ($conf->get('BATCH_MODE')) {
+
+	my $file = $conf->get('JOB_FILE');
+	local( *F );
+
+	return if !open( F, ">$file" );
+	if (defined($job)) {
+	    print F $job->get('Package_OVersion') . ": " .
+		$job->get_status() . "\n";
+	}
+	close( F );
+    }
+}
+
+sub status_trigger ($$) {
+    my $build = shift;
+    my $status = shift;
+
+    write_jobs_file();
+
+    # Rewrite status if we need to give back or mark attempted
+    # following failure.  Note that this must follow the above
+    # function calls because set_status will recursively trigger.
+    if ($status eq "failed" &&
+	isin($build->get('Pkg Fail Stage'),
+	     qw(fetch-src install-core install-essential install-deps
+		unpack check-unpacked-version check-space hack-binNMU
+		install-deps-env apt-get-clean apt-get-update
+		apt-get-upgrade apt-get-distupgrade))) {
+	$build->set_status('given-back');
+    } elsif ($status eq "failed" &&
+	     isin ($build->get('Pkg Fail Stage'),
+		   qw(build arch-check))) {
+	$build->set_status('attempted');
+    }
+}
+
+sub shutdown ($) {
+    my $signame = shift;
+
+    $SIG{'INT'} = 'IGNORE';
+    $SIG{'QUIT'} = 'IGNORE';
+    $SIG{'TERM'} = 'IGNORE';
+    $SIG{'ALRM'} = 'IGNORE';
+    $SIG{'PIPE'} = 'IGNORE';
+
+    if (defined($job)) {
+	$job->request_abort("Received $signame signal");
+    } else {
+	exit(1);
+    }
+
+    $SIG{'INT'} = \&main::shutdown;
+    $SIG{'TERM'} = \&main::shutdown;
+    $SIG{'ALRM'} = \&main::shutdown;
+    $SIG{'PIPE'} = \&main::shutdown;
+}
+
+sub dump_main_state () {
+    print STDERR Data::Dumper->Dump([$job],
+				    [qw($job)] );
+}
diff -pruN 0.80.0/.pc/applied-patches 0.80.0ubuntu1/.pc/applied-patches
--- 0.80.0/.pc/applied-patches	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/.pc/applied-patches	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1,2 @@
+no-pkg-mangle-deps.patch
+abs-path-revert.patch
diff -pruN 0.80.0/.pc/no-pkg-mangle-deps.patch/lib/Sbuild/ResolverBase.pm 0.80.0ubuntu1/.pc/no-pkg-mangle-deps.patch/lib/Sbuild/ResolverBase.pm
--- 0.80.0/.pc/no-pkg-mangle-deps.patch/lib/Sbuild/ResolverBase.pm	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/.pc/no-pkg-mangle-deps.patch/lib/Sbuild/ResolverBase.pm	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1,1687 @@
+# Resolver.pm: build library for sbuild
+# Copyright © 2005      Ryan Murray <rmurray@debian.org>
+# Copyright © 2005-2010 Roger Leigh <rleigh@debian.org>
+# Copyright © 2008      Simon McVittie <smcv@debian.org>
+#
+# 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+#######################################################################
+
+package Sbuild::ResolverBase;
+
+use strict;
+use warnings;
+use POSIX;
+use Fcntl;
+use File::Temp qw(mktemp);
+use File::Basename qw(basename);
+use File::Copy;
+use MIME::Base64;
+
+use Dpkg::Deps;
+use Sbuild::Base;
+use Sbuild qw(isin debug debug2);
+
+BEGIN {
+    use Exporter ();
+    our (@ISA, @EXPORT);
+
+    @ISA = qw(Exporter Sbuild::Base);
+
+    @EXPORT = qw();
+}
+
+sub new {
+    my $class = shift;
+    my $conf = shift;
+    my $session = shift;
+    my $host = shift;
+
+    my $self = $class->SUPER::new($conf);
+    bless($self, $class);
+
+    $self->set('Session', $session);
+    $self->set('Host', $host);
+    $self->set('Changes', {});
+    $self->set('AptDependencies', {});
+    $self->set('Split', $self->get_conf('CHROOT_SPLIT'));
+    # Typically set by Sbuild::Build, but not outside a build context.
+    $self->set('Host Arch', $self->get_conf('HOST_ARCH'));
+    $self->set('Build Arch', $self->get_conf('BUILD_ARCH'));
+    $self->set('Build Profiles', $self->get_conf('BUILD_PROFILES'));
+    $self->set('Multiarch Support', 1);
+    $self->set('Initial Foreign Arches', {});
+    $self->set('Added Foreign Arches', {});
+
+    my $dummy_archive_list_file =
+        '/etc/apt/sources.list.d/sbuild-build-depends-archive.list';
+    $self->set('Dummy archive list file', $dummy_archive_list_file);
+
+    my $extra_repositories_archive_list_file =
+        '/etc/apt/sources.list.d/sbuild-extra-repositories.list';
+    $self->set('Extra repositories archive list file', $extra_repositories_archive_list_file);
+
+    my $extra_packages_archive_list_file =
+        '/etc/apt/sources.list.d/sbuild-extra-packages-archive.list';
+    $self->set('Extra packages archive list file', $extra_packages_archive_list_file);
+
+    return $self;
+}
+
+sub setup {
+    my $self = shift;
+
+    my $session = $self->get('Session');
+    my $chroot_dir = $session->get('Location');
+
+    #Set up dpkg config
+    $self->setup_dpkg();
+
+    my $aptconf = "/var/lib/sbuild/apt.conf";
+    $self->set('APT Conf', $aptconf);
+
+    my $chroot_aptconf = $session->get('Location') . "/$aptconf";
+    $self->set('Chroot APT Conf', $chroot_aptconf);
+
+    my $tmpaptconf = $session->mktemp({ TEMPLATE => "$aptconf.XXXXXX"});
+    if (!$tmpaptconf) {
+	$self->log_error("Can't create $chroot_aptconf.XXXXXX: $!\n");
+	return 0;
+    }
+
+    my $F = $session->get_write_file_handle($tmpaptconf);
+    if (!$F) {
+	$self->log_error("Cannot open pipe: $!\n");
+	return 0;
+    }
+
+    # Always write out apt.conf, because it may become outdated.
+    if ($self->get_conf('APT_ALLOW_UNAUTHENTICATED')) {
+	print $F qq(APT::Get::AllowUnauthenticated "true";\n);
+    }
+    print $F qq(APT::Install-Recommends "false";\n);
+    print $F qq(APT::AutoRemove::SuggestsImportant "false";\n);
+    print $F qq(APT::AutoRemove::RecommendsImportant "false";\n);
+    print $F qq(Acquire::Languages "none";\n); # do not download translations
+
+    if ($self->get_conf('APT_KEEP_DOWNLOADED_PACKAGES')) {
+	print $F qq(APT::Keep-Downloaded-Packages "true";\n);
+    } else {
+	# remove packages from /var/cache/apt/archive/*.deb after installation
+	print $F qq(APT::Keep-Downloaded-Packages "false";\n);
+    }
+
+    if ($self->get('Split')) {
+	print $F "Dir \"$chroot_dir\";\n";
+    }
+
+    close $F;
+
+    if (!$session->rename($tmpaptconf, $aptconf)) {
+	$self->log_error("Can't rename $tmpaptconf to $aptconf: $!\n");
+	return 0;
+    }
+
+    if (!$session->chown($aptconf, $self->get_conf('BUILD_USER'), 'sbuild')) {
+	$self->log_error("Failed to set " . $self->get_conf('BUILD_USER') .
+			 ":sbuild ownership on apt.conf at $aptconf\n");
+	return 0;
+    }
+    if (!$session->chmod($aptconf, '0664')) {
+	$self->log_error("Failed to set 0664 permissions on apt.conf at $aptconf\n");
+	return 0;
+    }
+
+    # unsplit mode uses an absolute path inside the chroot, rather
+    # than on the host system.
+    if ($self->get('Split')) {
+	$self->set('APT Options',
+		   ['-o', "Dir::State::status=$chroot_dir/var/lib/dpkg/status",
+		    '-o', "DPkg::Options::=--root=$chroot_dir",
+		    '-o', "DPkg::Run-Directory=$chroot_dir"]);
+
+	$self->set('Aptitude Options',
+		   ['-o', "Dir::State::status=$chroot_dir/var/lib/dpkg/status",
+		    '-o', "DPkg::Options::=--root=$chroot_dir",
+		    '-o', "DPkg::Run-Directory=$chroot_dir"]);
+
+	# sudo uses an absolute path on the host system.
+	$session->get('Defaults')->{'ENV'}->{'APT_CONFIG'} =
+	    $self->get('Chroot APT Conf');
+    } else { # no split
+	$self->set('APT Options', []);
+	$self->set('Aptitude Options', []);
+	$session->get('Defaults')->{'ENV'}->{'APT_CONFIG'} =
+	    $self->get('APT Conf');
+    }
+
+    # Add specified extra repositories into /etc/apt/sources.list.d/.
+    # This has to be done this early so that the early apt
+    # update/upgrade/distupgrade steps also consider the extra repositories.
+    # If this step would be done too late, extra repositories would only be
+    # considered when resolving build dependencies but not for upgrading the
+    # base chroot.
+    if (scalar @{$self->get_conf('EXTRA_REPOSITORIES')} > 0) {
+	my $extra_repositories_archive_list_file = $self->get('Extra repositories archive list file');
+	if ($session->test_regular_file($extra_repositories_archive_list_file)) {
+	    $self->log_error("$extra_repositories_archive_list_file exists - will not write extra repositories to it\n");
+	} else {
+	    my $tmpfilename = $session->mktemp();
+
+	    my $tmpfh = $session->get_write_file_handle($tmpfilename);
+	    if (!$tmpfh) {
+		$self->log_error("Cannot open pipe: $!\n");
+		return 0;
+	    }
+	    for my $repospec (@{$self->get_conf('EXTRA_REPOSITORIES')}) {
+		print $tmpfh "$repospec\n";
+	    }
+	    close $tmpfh;
+	    # List file needs to be moved with root.
+	    if (!$session->chmod($tmpfilename, '0644')) {
+		$self->log("Failed to create apt list file for dummy archive.\n");
+		$session->unlink($tmpfilename);
+		return 0;
+	    }
+	    if (!$session->rename($tmpfilename, $extra_repositories_archive_list_file)) {
+		$self->log("Failed to create apt list file for dummy archive.\n");
+		$session->unlink($tmpfilename);
+		return 0;
+	    }
+	}
+    }
+
+    # Create an internal repository for packages given via --extra-package
+    # If this step would be done too late, extra packages would only be
+    # considered when resolving build dependencies but not for upgrading the
+    # base chroot.
+    if (scalar @{$self->get_conf('EXTRA_PACKAGES')} > 0) {
+	my $extra_packages_archive_list_file = $self->get('Extra packages archive list file');
+	if ($session->test_regular_file($extra_packages_archive_list_file)) {
+	    $self->log_error("$extra_packages_archive_list_file exists - will not write extra packages archive list to it\n");
+	} else {
+	    #Prepare a path to place the extra packages
+	    if (! defined $self->get('Extra packages path')) {
+		my $tmpdir = $session->mktemp({ TEMPLATE => $self->get('Build Dir') . '/resolver-XXXXXX', DIRECTORY => 1});
+		if (!$tmpdir) {
+		    $self->log_error("mktemp -d " . $self->get('Build Dir') . '/resolver-XXXXXX failed\n');
+		    return 0;
+		}
+		$self->set('Extra packages path', $tmpdir);
+	    }
+	    if (!$session->chown($self->get('Extra packages path'), $self->get_conf('BUILD_USER'), 'sbuild')) {
+		$self->log_error("Failed to set " . $self->get_conf('BUILD_USER') .
+		    ":sbuild ownership on extra packages dir\n");
+		return 0;
+	    }
+	    if (!$session->chmod($self->get('Extra packages path'), '0770')) {
+		$self->log_error("Failed to set 0770 permissions on extra packages dir\n");
+		return 0;
+	    }
+	    my $extra_packages_dir = $self->get('Extra packages path');
+	    my $extra_packages_archive_dir = $extra_packages_dir . '/apt_archive';
+	    my $extra_packages_release_file = $extra_packages_archive_dir . '/Release';
+
+	    $self->set('Extra packages archive directory', $extra_packages_archive_dir);
+	    $self->set('Extra packages release file', $extra_packages_release_file);
+	    my $extra_packages_archive_list_file = $self->get('Extra packages archive list file');
+
+	    if (!$session->test_directory($extra_packages_dir)) {
+		$self->log_warning('Could not create build-depends extra packages dir ' . $extra_packages_dir . ': ' . $!);
+		return 0;
+	    }
+	    if (!($session->test_directory($extra_packages_archive_dir) || $session->mkdir($extra_packages_archive_dir, { MODE => "00775"}))) {
+		$self->log_warning('Could not create build-depends extra packages archive dir ' . $extra_packages_archive_dir . ': ' . $!);
+		return 0;
+	    }
+
+	    # Copy over all the extra binary packages from the host into the
+	    # chroot
+	    for my $deb (@{$self->get_conf('EXTRA_PACKAGES')}) {
+		if (-f $deb) {
+		    my $base_deb = basename($deb);
+		    if ($session->test_regular_file("$extra_packages_archive_dir/$base_deb")) {
+			$self->log_warning("$base_deb already exists in $extra_packages_archive_dir inside the chroot. Skipping...\n");
+			next;
+		    }
+		    $session->copy_to_chroot($deb, $extra_packages_archive_dir);
+		} elsif (-d $deb) {
+		    opendir(D, $deb);
+		    while (my $f = readdir(D)) {
+			next if (! -f "$deb/$f");
+			next if ("$deb/$f" !~ /\.deb$/);
+			if ($session->test_regular_file("$extra_packages_archive_dir/$f")) {
+			    $self->log_warning("$f already exists in $extra_packages_archive_dir inside the chroot. Skipping...\n");
+			    next;
+			}
+			$session->copy_to_chroot("$deb/$f", $extra_packages_archive_dir);
+		    }
+		    closedir(D);
+		} else {
+		    $self->log_warning("$deb is neither a regular file nor a directory. Skipping...\n");
+		}
+	    }
+
+	    # Do code to run apt-ftparchive
+	    if (!$self->run_apt_ftparchive($self->get('Extra packages archive directory'))) {
+		$self->log("Failed to run apt-ftparchive.\n");
+		return 0;
+	    }
+
+	    # Write a list file for the extra packages archive if one not create yet.
+	    if (!$session->test_regular_file($extra_packages_archive_list_file)) {
+		my $tmpfilename = $session->mktemp();
+
+		if (!$tmpfilename) {
+		    $self->log_error("Can't create tempfile\n");
+		    return 0;
+		}
+
+		my $tmpfh = $session->get_write_file_handle($tmpfilename);
+		if (!$tmpfh) {
+		    $self->log_error("Cannot open pipe: $!\n");
+		    return 0;
+		}
+
+		# We always trust the extra packages apt repositories.
+		print $tmpfh 'deb [trusted=yes] file://' . $extra_packages_archive_dir . " ./\n";
+		print $tmpfh 'deb-src [trusted=yes] file://' . $extra_packages_archive_dir . " ./\n";
+
+		close($tmpfh);
+		# List file needs to be moved with root.
+		if (!$session->chmod($tmpfilename, '0644')) {
+		    $self->log("Failed to create apt list file for extra packages archive.\n");
+		    $session->unlink($tmpfilename);
+		    return 0;
+		}
+		if (!$session->rename($tmpfilename, $extra_packages_archive_list_file)) {
+		    $self->log("Failed to create apt list file for extra packages archive.\n");
+		    $session->unlink($tmpfilename);
+		    return 0;
+		}
+	    }
+
+	}
+    }
+
+    # Now, we'll add in any provided OpenPGP keys into the archive, so that
+    # builds can (optionally) trust an external key for the duration of the
+    # build.
+    #
+    # Keys have to be in a format that apt expects to land in
+    # /etc/apt/trusted.gpg.d as they are just copied to there. We could also
+    # support more formats by first importing them using gpg and then
+    # exporting them but that would require gpg to be installed inside the
+    # chroot.
+    if (@{$self->get_conf('EXTRA_REPOSITORY_KEYS')}) {
+	my $host = $self->get('Host');
+	# remember whether running gpg worked or not
+	my $has_gpg = 1;
+	for my $repokey (@{$self->get_conf('EXTRA_REPOSITORY_KEYS')}) {
+	    debug("Adding archive key: $repokey\n");
+	    if (!-f $repokey) {
+		$self->log("Failed to add archive key '${repokey}' - it doesn't exist!\n");
+		return 0;
+	    }
+	    # key might be armored but apt requires keys in binary format
+	    # We first try to run gpg from the host to convert the key into
+	    # binary format (this works even when the key already is in binary
+	    # format).
+	    my $tmpfilename = mktemp("/tmp/tmp.XXXXXXXXXX");
+	    if ($has_gpg == 1) {
+		$host->run_command({
+			COMMAND => ['gpg', '--yes', '--batch', '--output', $tmpfilename, '--dearmor', $repokey],
+			USER => $self->get_conf('BUILD_USER'),
+		    });
+		if ($?) {
+		    # don't try to use gpg again in later loop iterations
+		    $has_gpg = 0;
+		}
+	    }
+	    # If that doesn't work, then we manually convert the key
+	    # as it is just base64 encoded data with a header and footer.
+	    #
+	    # The decoding of armored gpg keys can even be done from a shell
+	    # script by using:
+	    #
+	    #    awk '/^$/{ x = 1; } /^[^=-]/{ if (x) { print $0; } ; }' | base64 -d
+	    #
+	    # As explained by dkg here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=831409#67
+	    if ($has_gpg == 0) {
+		# Test if we actually have an armored key. Otherwise, no
+		# conversion is needed.
+		open my $fh, '<', $repokey;
+		read $fh, my $first_line, 36;
+		if ($first_line eq "-----BEGIN PGP PUBLIC KEY BLOCK-----") {
+		    # Read the remaining part of the line until the newline.
+		    # We do it like this because the line might contain
+		    # additional whitespace characters or \r\n newlines.
+		    <$fh>;
+		    open my $out, '>', $tmpfilename;
+		    # the file is an armored gpg key, so we convert it to the
+		    # binary format
+		    my $header = 1;
+		    while( my $line = <$fh>) {
+			chomp $line;
+			# an empty line marks the end of the header
+			if ($line eq "") {
+			    $header = 0;
+			    next;
+			}
+			if ($header == 1) {
+			    next;
+			}
+			# the footer might contain lines starting with an
+			# equal sign or minuses
+			if ($line =~ /^[=-]/) {
+			    last;
+			}
+			print $out (decode_base64($line));
+		    }
+		    close $out;
+		}
+		close $fh;
+	    }
+	    # we could use incrementing integers to number the extra
+	    # repository keys but mktemp will also make sure that the new name
+	    # doesn't exist yet and avoids the complexity of an additional
+	    # variable
+	    my $keyfilename = $session->mktemp({TEMPLATE => "/etc/apt/trusted.gpg.d/sbuild-extra-repository-XXXXXXXXXX.gpg"});
+	    if (!$keyfilename) {
+		$self->log_error("Can't create tempfile for external repository key\n");
+		$session->unlink($keyfilename);
+		unlink $tmpfilename;
+		return 0;
+	    }
+	    if (!$session->copy_to_chroot($tmpfilename, $keyfilename)) {
+		$self->log_error("Failed to copy external repository key $repokey into chroot $keyfilename\n");
+		$session->unlink($keyfilename);
+		unlink $tmpfilename;
+		return 0;
+	    }
+	    unlink $tmpfilename;
+	    if (!$session->chmod($keyfilename, '0644')) {
+		$self->log_error("Failed to chmod $keyfilename inside the chroot\n");
+		$session->unlink($keyfilename);
+		return 0;
+	    }
+	}
+
+    }
+
+    # We have to do this early so that we can setup log filtering for the RESOLVERDIR
+    # We only set it up, if 'Build Dir' was set. It is not when the resolver
+    # is used by sbuild-createchroot, for example.
+    #Prepare a path to build a dummy package containing our deps:
+    if (! defined $self->get('Dummy package path') && defined $self->get('Build Dir')) {
+	my $tmpdir = $session->mktemp({ TEMPLATE => $self->get('Build Dir') . '/resolver-XXXXXX', DIRECTORY => 1});
+	if (!$tmpdir) {
+	    $self->log_error("mktemp -d " . $self->get('Build Dir') . '/resolver-XXXXXX failed\n');
+	    return 0;
+	}
+	$self->set('Dummy package path', $tmpdir);
+    }
+
+    return 1;
+}
+
+sub get_foreign_architectures {
+    my $self = shift;
+
+    my $session = $self->get('Session');
+
+    $session->run_command({ COMMAND => ['dpkg', '--assert-multi-arch'],
+                            USER => 'root'});
+    if ($?)
+    {
+        $self->set('Multiarch Support', 0);
+        $self->log_error("dpkg does not support multi-arch\n");
+        return {};
+    }
+
+    my $foreignarchs = $session->read_command({ COMMAND => ['dpkg', '--print-foreign-architectures'], USER => 'root' });
+
+    if (!defined($foreignarchs)) {
+        $self->set('Multiarch Support', 0);
+        $self->log_error("dpkg does not support multi-arch\n");
+        return {};
+    }
+
+    if (!$foreignarchs)
+    {
+        debug("There are no foreign architectures configured\n");
+        return {};
+    }
+
+    my %set;
+    foreach my $arch (split /\s+/, $foreignarchs) {
+	chomp $arch;
+	next unless $arch;
+	$set{$arch} = 1;
+    }
+
+    return \%set;
+}
+
+sub add_foreign_architecture {
+
+    my $self = shift;
+    my $arch = shift;
+
+    # just skip if dpkg is to old for multiarch
+    if (! $self->get('Multiarch Support')) {
+	debug("not adding $arch because of no multiarch support\n");
+	return 1;
+    };
+
+    # if we already have this architecture, we're done
+    if ($self->get('Initial Foreign Arches')->{$arch}) {
+	debug("not adding $arch because it is an initial arch\n");
+	return 1;
+    }
+    if ($self->get('Added Foreign Arches')->{$arch}) {
+	debug("not adding $arch because it has already been aded");
+	return 1;
+    }
+
+    my $session = $self->get('Session');
+
+    # FIXME - allow for more than one foreign arch
+    $session->run_command(
+                          # This is the Ubuntu dpkg 1.16.0~ubuntuN interface;
+                          # we ought to check (or configure) which to use with
+                          # check_dpkg_version:
+                          #	{ COMMAND => ['sh', '-c', 'echo "foreign-architecture ' . $self->get('Host Arch') . '" > /etc/dpkg/dpkg.cfg.d/sbuild'],
+                          #	  USER => 'root' });
+                          # This is the Debian dpkg >= 1.16.2 interface:
+                          { COMMAND => ['dpkg', '--add-architecture', $arch],
+                            USER => 'root' });
+    if ($?)
+    {
+        $self->log_error("Failed to set dpkg foreign-architecture config\n");
+        return 0;
+    }
+    debug("Added foreign arch: $arch\n") if $arch;
+
+    $self->get('Added Foreign Arches')->{$arch} = 1;
+    return 1;
+}
+
+sub cleanup_foreign_architectures {
+    my $self = shift;
+
+    # just skip if dpkg is to old for multiarch
+    if (! $self->get('Multiarch Support')) { return 1 };
+
+    my $added_foreign_arches = $self->get('Added Foreign Arches');
+
+    my $session = $self->get('Session');
+
+    if (defined ($session->get('Session Purged')) && $session->get('Session Purged') == 1) {
+	debug("Not removing foreign architectures: cloned chroot in use\n");
+	return;
+    }
+
+    foreach my $arch (keys %{$added_foreign_arches}) {
+        $self->log("Removing foreign architecture $arch\n");
+        $session->run_command({ COMMAND => ['dpkg', '--remove-architecture', $arch],
+                                USER => 'root',
+                                DIR => '/'});
+        if ($?)
+        {
+            $self->log_error("Failed to remove dpkg foreign-architecture $arch\n");
+            return;
+        }
+    }
+}
+
+sub setup_dpkg {
+    my $self = shift;
+
+    my $session = $self->get('Session');
+
+    # Record initial foreign arch state so it can be restored
+    $self->set('Initial Foreign Arches', $self->get_foreign_architectures());
+
+    if ($self->get('Host Arch') ne $self->get('Build Arch')) {
+	$self->add_foreign_architecture($self->get('Host Arch'))
+    }
+}
+
+sub cleanup {
+    my $self = shift;
+
+    #cleanup dpkg cross-config
+    # rm /etc/dpkg/dpkg.cfg.d/sbuild
+    $self->cleanup_apt_archive();
+    $self->cleanup_foreign_architectures();
+}
+
+sub update {
+    my $self = shift;
+
+    $self->run_apt_command(
+	{ COMMAND => [$self->get_conf('APT_GET'), 'update'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub update_archive {
+    my $self = shift;
+
+    if (!$self->get_conf('APT_UPDATE_ARCHIVE_ONLY')) {
+	# Update with apt-get; causes complete archive update
+	$self->run_apt_command(
+	    { COMMAND => [$self->get_conf('APT_GET'), 'update'],
+	      ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	      USER => 'root',
+	      DIR => '/' });
+    } else {
+	my $session = $self->get('Session');
+	# Create an empty sources.list.d directory that we can set as
+	# Dir::Etc::sourceparts to suppress the real one. /dev/null
+	# works in recent versions of apt, but not older ones (we want
+	# 448eaf8 in apt 0.8.0 and af13d14 in apt 0.9.3). Since this
+	# runs against the target chroot's apt, be conservative.
+	my $dummy_sources_list_d = $self->get('Dummy package path') . '/sources.list.d';
+	if (!($session->test_directory($dummy_sources_list_d) || $session->mkdir($dummy_sources_list_d, { MODE => "00700"}))) {
+	    $self->log_warning('Could not create build-depends dummy sources.list directory ' . $dummy_sources_list_d . ': ' . $!);
+	    return 0;
+	}
+
+	# Run apt-get update pointed at our dummy archive list file, and
+	# the empty sources.list.d directory, so that we only update
+	# this one source. Since apt doesn't have all the sources
+	# available to it in this run, any caches it generates are
+	# invalid, so we then need to run gencaches with all sources
+	# available to it. (Note that the tempting optimization to run
+	# apt-get update -o pkgCacheFile::Generate=0 is broken before
+	# 872ed75 in apt 0.9.1.)
+	for my $list_file ($self->get('Dummy archive list file'),
+			   $self->get('Extra packages archive list file'),
+			   $self->get('Extra repositories archive list file')) {
+	    if (!$session->test_regular_file_readable($list_file)) {
+		next;
+	    }
+	    $self->run_apt_command(
+		{ COMMAND => [$self->get_conf('APT_GET'), 'update',
+			'-o', 'Dir::Etc::sourcelist=' . $list_file,
+			'-o', 'Dir::Etc::sourceparts=' . $dummy_sources_list_d,
+			'--no-list-cleanup'],
+		    ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+		    USER => 'root',
+		    DIR => '/' });
+	    if ($? != 0) {
+		return 0;
+	    }
+	}
+
+	$self->run_apt_command(
+	    { COMMAND => [$self->get_conf('APT_CACHE'), 'gencaches'],
+	      ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	      USER => 'root',
+	      DIR => '/' });
+    }
+
+    if ($? != 0) {
+	return 0;
+    }
+
+    return 1;
+}
+
+sub upgrade {
+    my $self = shift;
+
+    $self->run_apt_command(
+	{ COMMAND => [$self->get_conf('APT_GET'), '-uy', '-o', 'Dpkg::Options::=--force-confold', 'upgrade'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub distupgrade {
+    my $self = shift;
+
+    $self->run_apt_command(
+	{ COMMAND => [$self->get_conf('APT_GET'), '-uy', '-o', 'Dpkg::Options::=--force-confold', 'dist-upgrade'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub clean {
+    my $self = shift;
+
+    $self->run_apt_command(
+	{ COMMAND => [$self->get_conf('APT_GET'), '-y', 'clean'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub autoclean {
+    my $self = shift;
+
+    $self->run_apt_command(
+	{ COMMAND => [$self->get_conf('APT_GET'), '-y', 'autoclean'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub autoremove {
+    my $self = shift;
+
+    $self->run_apt_command(
+	{ COMMAND => [$self->get_conf('APT_GET'), '-y', 'autoremove'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub add_dependencies {
+    my $self = shift;
+    my $pkg = shift;
+    my $build_depends = shift;
+    my $build_depends_arch = shift;
+    my $build_depends_indep = shift;
+    my $build_conflicts = shift;
+    my $build_conflicts_arch = shift;
+    my $build_conflicts_indep = shift;
+
+    debug("Build-Depends: $build_depends\n") if $build_depends;
+    debug("Build-Depends-Arch: $build_depends_arch\n") if $build_depends_arch;
+    debug("Build-Depends-Indep: $build_depends_indep\n") if $build_depends_indep;
+    debug("Build-Conflicts: $build_conflicts\n") if $build_conflicts;
+    debug("Build-Conflicts-Arch: $build_conflicts_arch\n") if $build_conflicts_arch;
+    debug("Build-Conflicts-Indep: $build_conflicts_indep\n") if $build_conflicts_indep;
+
+    my $deps = {
+	'Build Depends' => $build_depends,
+	'Build Depends Arch' => $build_depends_arch,
+	'Build Depends Indep' => $build_depends_indep,
+	'Build Conflicts' => $build_conflicts,
+	'Build Conflicts Arch' => $build_conflicts_arch,
+	'Build Conflicts Indep' => $build_conflicts_indep
+    };
+
+    $self->get('AptDependencies')->{$pkg} = $deps;
+}
+
+sub uninstall_deps {
+    my $self = shift;
+
+    my( @pkgs, @instd, @rmvd );
+
+    @pkgs = keys %{$self->get('Changes')->{'removed'}};
+    debug("Reinstalling removed packages: @pkgs\n");
+    $self->log("Failed to reinstall removed packages!\n")
+	if !$self->run_apt("-y", \@instd, \@rmvd, 'install', @pkgs);
+    debug("Installed were: @instd\n");
+    debug("Removed were: @rmvd\n");
+    $self->unset_removed(@instd);
+    $self->unset_installed(@rmvd);
+
+    @pkgs = keys %{$self->get('Changes')->{'installed'}};
+    debug("Removing installed packages: @pkgs\n");
+    $self->log("Failed to remove installed packages!\n")
+	if !$self->run_apt("-y", \@instd, \@rmvd, 'remove', @pkgs);
+    $self->unset_removed(@instd);
+    $self->unset_installed(@rmvd);
+}
+
+sub set_installed {
+    my $self = shift;
+
+    foreach (@_) {
+	$self->get('Changes')->{'installed'}->{$_} = 1;
+    }
+    debug("Added to installed list: @_\n");
+}
+
+sub set_removed {
+    my $self = shift;
+    foreach (@_) {
+	$self->get('Changes')->{'removed'}->{$_} = 1;
+	if (exists $self->get('Changes')->{'installed'}->{$_}) {
+	    delete $self->get('Changes')->{'installed'}->{$_};
+	    $self->get('Changes')->{'auto-removed'}->{$_} = 1;
+	    debug("Note: $_ was installed\n");
+	}
+    }
+    debug("Added to removed list: @_\n");
+}
+
+sub unset_installed {
+    my $self = shift;
+    foreach (@_) {
+	delete $self->get('Changes')->{'installed'}->{$_};
+    }
+    debug("Removed from installed list: @_\n");
+}
+
+sub unset_removed {
+    my $self = shift;
+    foreach (@_) {
+	delete $self->get('Changes')->{'removed'}->{$_};
+	if (exists $self->get('Changes')->{'auto-removed'}->{$_}) {
+	    delete $self->get('Changes')->{'auto-removed'}->{$_};
+	    $self->get('Changes')->{'installed'}->{$_} = 1;
+	    debug("Note: revived $_ to installed list\n");
+	}
+    }
+    debug("Removed from removed list: @_\n");
+}
+
+sub dump_build_environment {
+    my $self = shift;
+
+    my $status = $self->get_dpkg_status();
+
+    my $arch = $self->get('Arch');
+    my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
+    $self->log_subsection("Build environment");
+    $self->log("Kernel: $sysname $release $version $arch ($machine)\n");
+
+    $self->log("Toolchain package versions:");
+    foreach my $name (sort keys %{$status}) {
+        foreach my $regex (@{$self->get_conf('TOOLCHAIN_REGEX')}) {
+	    if ($name =~ m,^$regex, && defined($status->{$name}->{'Version'})) {
+		$self->log(' ' . $name . '_' . $status->{$name}->{'Version'});
+	    }
+	}
+    }
+    $self->log("\n");
+
+    $self->log("Package versions:");
+    foreach my $name (sort keys %{$status}) {
+	if (defined($status->{$name}->{'Version'})) {
+	    $self->log(' ' . $name . '_' . $status->{$name}->{'Version'});
+	}
+    }
+    $self->log("\n");
+
+    return $status->{'dpkg-dev'}->{'Version'};
+}
+
+sub run_apt {
+    my $self = shift;
+    my $mode = shift;
+    my $inst_ret = shift;
+    my $rem_ret = shift;
+    my $action = shift;
+    my @packages = @_;
+    my( $msgs, $status, $pkgs, $rpkgs );
+
+    $msgs = "";
+    # redirection of stdin from /dev/null so that conffile question
+    # are treated as if RETURN was pressed.
+    # dpkg since 1.4.1.18 issues an error on the conffile question if
+    # it reads EOF -- hardwire the new --force-confold option to avoid
+    # the questions.
+    my @apt_command = ($self->get_conf('APT_GET'), '--purge',
+	'-o', 'DPkg::Options::=--force-confold',
+	'-o', 'DPkg::Options::=--refuse-remove-essential',
+	'-o', 'APT::Install-Recommends=false',
+	'-o', 'Dpkg::Use-Pty=false',
+	'-q');
+    push @apt_command, '--allow-unauthenticated' if
+	($self->get_conf('APT_ALLOW_UNAUTHENTICATED'));
+    push @apt_command, "$mode", $action, @packages;
+    my $pipe =
+	$self->pipe_apt_command(
+	    { COMMAND => \@apt_command,
+	      ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	      USER => 'root',
+	      PRIORITY => 0,
+	      DIR => '/' });
+    if (!$pipe) {
+	$self->log("Can't open pipe to apt-get: $!\n");
+	return 0;
+    }
+
+    while(<$pipe>) {
+	$msgs .= $_;
+	$self->log($_) if $mode ne "-s" || debug($_);
+    }
+    close($pipe);
+    $status = $?;
+
+    $pkgs = $rpkgs = "";
+    if ($msgs =~ /NEW packages will be installed:\n((^[ 	].*\n)*)/mi) {
+	($pkgs = $1) =~ s/^[ 	]*((.|\n)*)\s*$/$1/m;
+	$pkgs =~ s/\*//g;
+    }
+    if ($msgs =~ /packages will be REMOVED:\n((^[ 	].*\n)*)/mi) {
+	($rpkgs = $1) =~ s/^[ 	]*((.|\n)*)\s*$/$1/m;
+	$rpkgs =~ s/\*//g;
+    }
+    @$inst_ret = split( /\s+/, $pkgs );
+    @$rem_ret = split( /\s+/, $rpkgs );
+
+    $self->log("apt-get failed.\n") if $status && $mode ne "-s";
+    return $mode eq "-s" || $status == 0;
+}
+
+sub run_xapt {
+    my $self = shift;
+    my $mode = shift;
+    my $inst_ret = shift;
+    my $rem_ret = shift;
+    my $action = shift;
+    my @packages = @_;
+    my( $msgs, $status, $pkgs, $rpkgs );
+
+    $msgs = "";
+    # redirection of stdin from /dev/null so that conffile question
+    # are treated as if RETURN was pressed.
+    # dpkg since 1.4.1.18 issues an error on the conffile question if
+    # it reads EOF -- hardwire the new --force-confold option to avoid
+    # the questions.
+    my @xapt_command = ($self->get_conf('XAPT'));
+    my $pipe =
+	$self->pipe_xapt_command(
+	    { COMMAND => \@xapt_command,
+	      ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	      USER => 'root',
+	      PRIORITY => 0,
+	      DIR => '/' });
+    if (!$pipe) {
+	$self->log("Can't open pipe to xapt: $!\n");
+	return 0;
+    }
+
+    while(<$pipe>) {
+	$msgs .= $_;
+	$self->log($_) if $mode ne "-s" || debug($_);
+    }
+    close($pipe);
+    $status = $?;
+
+    $pkgs = $rpkgs = "";
+    if ($msgs =~ /NEW packages will be installed:\n((^[ 	].*\n)*)/mi) {
+	($pkgs = $1) =~ s/^[ 	]*((.|\n)*)\s*$/$1/m;
+	$pkgs =~ s/\*//g;
+    }
+    if ($msgs =~ /packages will be REMOVED:\n((^[ 	].*\n)*)/mi) {
+	($rpkgs = $1) =~ s/^[ 	]*((.|\n)*)\s*$/$1/m;
+	$rpkgs =~ s/\*//g;
+    }
+    @$inst_ret = split( /\s+/, $pkgs );
+    @$rem_ret = split( /\s+/, $rpkgs );
+
+    $self->log("xapt failed.\n") if $status && $mode ne "-s";
+    return $mode eq "-s" || $status == 0;
+}
+
+sub format_deps {
+    my $self = shift;
+
+    return join( ", ",
+		 map { join( "|",
+			     map { ($_->{'Neg'} ? "!" : "") .
+				       $_->{'Package'} .
+				       ($_->{'Rel'} ? " ($_->{'Rel'} $_->{'Version'})":"")}
+			     scalar($_), @{$_->{'Alternatives'}}) } @_ );
+}
+
+sub get_dpkg_status {
+    my $self = shift;
+    my @interest = @_;
+    my %result;
+
+    debug("Requesting dpkg status for packages: @interest\n");
+    my $STATUS = $self->get('Session')->get_read_file_handle('/var/lib/dpkg/status');
+    if (!$STATUS) {
+	$self->log("Can't open /var/lib/dpkg/status inside chroot: $!\n");
+	return ();
+    }
+    local( $/ ) = "";
+    while( <$STATUS> ) {
+	my( $pkg, $status, $version, $provides );
+	/^Package:\s*(.*)\s*$/mi and $pkg = $1;
+	/^Status:\s*(.*)\s*$/mi and $status = $1;
+	/^Version:\s*(.*)\s*$/mi and $version = $1;
+	/^Provides:\s*(.*)\s*$/mi and $provides = $1;
+	if (!$pkg) {
+	    $self->log_error("parse error in /var/lib/dpkg/status: no Package: field\n");
+	    next;
+	}
+	if (defined($version)) {
+	    debug("$pkg ($version) status: $status\n") if $self->get_conf('DEBUG') >= 2;
+	} else {
+	    debug("$pkg status: $status\n") if $self->get_conf('DEBUG') >= 2;
+	}
+	if (!$status) {
+	    $self->log_error("parse error in /var/lib/dpkg/status: no Status: field for package $pkg\n");
+	    next;
+	}
+	if ($status !~ /\sinstalled$/) {
+	    $result{$pkg}->{'Installed'} = 0
+		if !(exists($result{$pkg}) &&
+		     $result{$pkg}->{'Version'} eq '~*=PROVIDED=*=');
+	    next;
+	}
+	if (!defined $version || $version eq "") {
+	    $self->log_error("parse error in /var/lib/dpkg/status: no Version: field for package $pkg\n");
+	    next;
+	}
+	$result{$pkg} = { Installed => 1, Version => $version }
+	    if (isin( $pkg, @interest ) || !@interest);
+	if ($provides) {
+	    foreach (split( /\s*,\s*/, $provides )) {
+		$result{$_} = { Installed => 1, Version => '~*=PROVIDED=*=' }
+		if isin( $_, @interest ) and (not exists($result{$_}) or
+					      ($result{$_}->{'Installed'} == 0));
+	    }
+	}
+    }
+    close( $STATUS );
+    return \%result;
+}
+
+# Create an apt archive. Add to it if one exists.
+sub setup_apt_archive {
+    my $self = shift;
+    my $dummy_pkg_name = shift;
+    my @pkgs = @_;
+
+    my $session = $self->get('Session');
+
+
+    if (!$session->chown($self->get('Dummy package path'), $self->get_conf('BUILD_USER'), 'sbuild')) {
+	$self->log_error("Failed to set " . $self->get_conf('BUILD_USER') .
+			 ":sbuild ownership on dummy package dir\n");
+	return 0;
+    }
+    if (!$session->chmod($self->get('Dummy package path'), '0770')) {
+	$self->log_error("Failed to set 0770 permissions on dummy package dir\n");
+	return 0;
+    }
+    my $dummy_dir = $self->get('Dummy package path');
+    my $dummy_gpghome = $dummy_dir . '/gpg';
+    my $dummy_archive_dir = $dummy_dir . '/apt_archive';
+    my $dummy_release_file = $dummy_archive_dir . '/Release';
+    my $dummy_archive_seckey = $dummy_archive_dir . '/sbuild-key.sec';
+    my $dummy_archive_pubkey = $dummy_archive_dir . '/sbuild-key.pub';
+
+    $self->set('Dummy archive directory', $dummy_archive_dir);
+    $self->set('Dummy Release file', $dummy_release_file);
+    my $dummy_archive_list_file = $self->get('Dummy archive list file');
+
+    if (!$session->test_directory($dummy_dir)) {
+        $self->log_warning('Could not create build-depends dummy dir ' . $dummy_dir . ': ' . $!);
+        return 0;
+    }
+    if (!($session->test_directory($dummy_gpghome) || $session->mkdir($dummy_gpghome, { MODE => "00700"}))) {
+        $self->log_warning('Could not create build-depends dummy gpg home dir ' . $dummy_gpghome . ': ' . $!);
+        return 0;
+    }
+    if (!$session->chown($dummy_gpghome, $self->get_conf('BUILD_USER'), 'sbuild')) {
+	$self->log_error('Failed to set ' . $self->get_conf('BUILD_USER') .
+			 ':sbuild ownership on $dummy_gpghome\n');
+	return 0;
+    }
+    if (!($session->test_directory($dummy_archive_dir) || $session->mkdir($dummy_archive_dir, { MODE => "00775"}))) {
+        $self->log_warning('Could not create build-depends dummy archive dir ' . $dummy_archive_dir . ': ' . $!);
+        return 0;
+    }
+
+    my $dummy_pkg_dir = $dummy_dir . '/' . $dummy_pkg_name;
+    my $dummy_deb = $dummy_archive_dir . '/' . $dummy_pkg_name . '.deb';
+    my $dummy_dsc = $dummy_archive_dir . '/' . $dummy_pkg_name . '.dsc';
+
+    if (!($session->mkdir("$dummy_pkg_dir", { MODE => "00775"}))) {
+	$self->log_warning('Could not create build-depends dummy dir ' . $dummy_pkg_dir . $!);
+	return 0;
+    }
+
+    if (!($session->mkdir("$dummy_pkg_dir/DEBIAN", { MODE => "00775"}))) {
+	$self->log_warning('Could not create build-depends dummy dir ' . $dummy_pkg_dir . '/DEBIAN: ' . $!);
+	return 0;
+    }
+
+    my $DUMMY_CONTROL = $session->get_write_file_handle("$dummy_pkg_dir/DEBIAN/control");
+    if (!$DUMMY_CONTROL) {
+	$self->log_warning('Could not open ' . $dummy_pkg_dir . '/DEBIAN/control for writing: ' . $!);
+	return 0;
+    }
+
+    my $arch = $self->get('Host Arch');
+    print $DUMMY_CONTROL <<"EOF";
+Package: $dummy_pkg_name
+Version: 0.invalid.0
+Architecture: $arch
+EOF
+
+    my @positive;
+    my @negative;
+    my @positive_arch;
+    my @negative_arch;
+    my @positive_indep;
+    my @negative_indep;
+
+    for my $pkg (@pkgs) {
+	my $deps = $self->get('AptDependencies')->{$pkg};
+
+	push(@positive, $deps->{'Build Depends'})
+	    if (defined($deps->{'Build Depends'}) &&
+		$deps->{'Build Depends'} ne "");
+	push(@negative, $deps->{'Build Conflicts'})
+	    if (defined($deps->{'Build Conflicts'}) &&
+		$deps->{'Build Conflicts'} ne "");
+	if ($self->get_conf('BUILD_ARCH_ANY')) {
+	    push(@positive_arch, $deps->{'Build Depends Arch'})
+		if (defined($deps->{'Build Depends Arch'}) &&
+		    $deps->{'Build Depends Arch'} ne "");
+	    push(@negative_arch, $deps->{'Build Conflicts Arch'})
+		if (defined($deps->{'Build Conflicts Arch'}) &&
+		    $deps->{'Build Conflicts Arch'} ne "");
+	}
+	if ($self->get_conf('BUILD_ARCH_ALL')) {
+	    push(@positive_indep, $deps->{'Build Depends Indep'})
+		if (defined($deps->{'Build Depends Indep'}) &&
+		    $deps->{'Build Depends Indep'} ne "");
+	    push(@negative_indep, $deps->{'Build Conflicts Indep'})
+		if (defined($deps->{'Build Conflicts Indep'}) &&
+		    $deps->{'Build Conflicts Indep'} ne "");
+	}
+    }
+
+    my $positive_build_deps = join(", ", @positive,
+				   @positive_arch, @positive_indep);
+    my $positive = deps_parse($positive_build_deps,
+			      reduce_arch => 1,
+			      host_arch => $self->get('Host Arch'),
+			      build_arch => $self->get('Build Arch'),
+			      build_dep => 1,
+			      reduce_profiles => 1,
+			      build_profiles => [ split / /, $self->get('Build Profiles') ]);
+    if( !defined $positive ) {
+        my $msg = "Error! deps_parse() couldn't parse the positive Build-Depends '$positive_build_deps'";
+        $self->log_error("$msg\n");
+        return 0;
+    }
+
+    my $negative_build_deps = join(", ", @negative,
+				   @negative_arch, @negative_indep);
+    my $negative = deps_parse($negative_build_deps,
+			      reduce_arch => 1,
+			      host_arch => $self->get('Host Arch'),
+			      build_arch => $self->get('Build Arch'),
+			      build_dep => 1,
+			      union => 1,
+			      reduce_profiles => 1,
+			      build_profiles => [ split / /, $self->get('Build Profiles') ]);
+    if( !defined $negative ) {
+        my $msg = "Error! deps_parse() couldn't parse the negative Build-Depends '$negative_build_deps'";
+        $self->log_error("$msg\n");
+        return 0;
+    }
+
+
+    # sbuild turns build dependencies into the dependencies of a dummy binary
+    # package. Since binary package dependencies do not support :native the
+    # architecture qualifier, these have to either be removed during native
+    # compilation or replaced by the build (native) architecture during cross
+    # building
+    my $handle_native_archqual = sub {
+        my ($dep) = @_;
+        if ($dep->{archqual} && $dep->{archqual} eq "native") {
+            if ($self->get('Host Arch') eq $self->get('Build Arch')) {
+                $dep->{archqual} = undef;
+            } else {
+                $dep->{archqual} = $self->get('Build Arch');
+            }
+        }
+        return 1;
+    };
+    deps_iterate($positive, $handle_native_archqual);
+    deps_iterate($negative, $handle_native_archqual);
+
+    $self->log("Merged Build-Depends: $positive\n") if $positive;
+    $self->log("Merged Build-Conflicts: $negative\n") if $negative;
+
+    # Filter out all but the first alternative except in special
+    # cases.
+    if (!$self->get_conf('RESOLVE_ALTERNATIVES')) {
+	my $positive_filtered = Dpkg::Deps::AND->new();
+	foreach my $item ($positive->get_deps()) {
+	    my $alt_filtered = Dpkg::Deps::OR->new();
+	    my @alternatives = $item->get_deps();
+	    my $first = shift @alternatives;
+	    $alt_filtered->add($first) if defined $first;
+	    # Allow foo (rel x) | foo (rel y) as the only acceptable
+	    # form of alternative.  i.e. where the package is the
+	    # same, but different relations are needed, since these
+	    # are effectively a single logical dependency.
+	    foreach my $alt (@alternatives) {
+		if ($first->{'package'} eq $alt->{'package'}) {
+		    $alt_filtered->add($alt);
+		} else {
+		    last;
+		}
+	    }
+	    $positive_filtered->add($alt_filtered);
+	}
+	$positive = $positive_filtered;
+    }
+
+    if ($positive ne "") {
+	print $DUMMY_CONTROL 'Depends: ' . $positive . "\n";
+    }
+    if ($negative ne "") {
+	print $DUMMY_CONTROL 'Conflicts: ' . $negative . "\n";
+    }
+
+    $self->log("Filtered Build-Depends: $positive\n") if $positive;
+    $self->log("Filtered Build-Conflicts: $negative\n") if $negative;
+
+    print $DUMMY_CONTROL <<"EOF";
+Maintainer: Debian buildd-tools Developers <buildd-tools-devel\@lists.alioth.debian.org>
+Description: Dummy package to satisfy dependencies with apt - created by sbuild
+ This package was created automatically by sbuild and should never appear on
+ a real system. You can safely remove it.
+EOF
+    close ($DUMMY_CONTROL);
+
+    foreach my $path ($dummy_pkg_dir . '/DEBIAN/control',
+		      $dummy_pkg_dir . '/DEBIAN',
+		      $dummy_pkg_dir,
+		      $dummy_archive_dir) {
+	if (!$session->chown($path, $self->get_conf('BUILD_USER'), 'sbuild')) {
+	    $self->log_error("Failed to set " . $self->get_conf('BUILD_USER')
+			   . ":sbuild ownership on $path\n");
+	    return 0;
+	}
+    }
+
+    #Now build the package:
+    $session->run_command(
+	{ COMMAND => ['dpkg-deb', '--build', $dummy_pkg_dir, $dummy_deb],
+	  USER => $self->get_conf('BUILD_USER'),
+	  PRIORITY => 0});
+    if ($?) {
+	$self->log("Dummy package creation failed\n");
+	return 0;
+    }
+
+    # Write the dummy dsc file.
+    my $dummy_dsc_fh = $session->get_write_file_handle($dummy_dsc);
+    if (!$dummy_dsc_fh) {
+        $self->log_warning('Could not open ' . $dummy_dsc . ' for writing: ' . $!);
+        return 0;
+    }
+
+    print $dummy_dsc_fh <<"EOF";
+Format: 1.0
+Source: $dummy_pkg_name
+Binary: $dummy_pkg_name
+Architecture: any
+Version: 0.invalid.0
+Maintainer: Debian buildd-tools Developers <buildd-tools-devel\@lists.alioth.debian.org>
+EOF
+    if (scalar(@positive)) {
+       print $dummy_dsc_fh 'Build-Depends: ' . join(", ", @positive) . "\n";
+    }
+    if (scalar(@negative)) {
+       print $dummy_dsc_fh 'Build-Conflicts: ' . join(", ", @negative) . "\n";
+    }
+    if (scalar(@positive_arch)) {
+       print $dummy_dsc_fh 'Build-Depends-Arch: ' . join(", ", @positive_arch) . "\n";
+    }
+    if (scalar(@negative_arch)) {
+       print $dummy_dsc_fh 'Build-Conflicts-Arch: ' . join(", ", @negative_arch) . "\n";
+    }
+    if (scalar(@positive_indep)) {
+       print $dummy_dsc_fh 'Build-Depends-Indep: ' . join(", ", @positive_indep) . "\n";
+    }
+    if (scalar(@negative_indep)) {
+       print $dummy_dsc_fh 'Build-Conflicts-Indep: ' . join(", ", @negative_indep) . "\n";
+    }
+    print $dummy_dsc_fh "\n";
+    close $dummy_dsc_fh;
+
+    # Do code to run apt-ftparchive
+    if (!$self->run_apt_ftparchive($self->get('Dummy archive directory'))) {
+        $self->log("Failed to run apt-ftparchive.\n");
+        return 0;
+    }
+
+    # Write a list file for the dummy archive if one not create yet.
+    if (!$session->test_regular_file($dummy_archive_list_file)) {
+	my $tmpfilename = $session->mktemp();
+
+	if (!$tmpfilename) {
+	    $self->log_error("Can't create tempfile\n");
+	    return 0;
+	}
+
+	my $tmpfh = $session->get_write_file_handle($tmpfilename);
+	if (!$tmpfh) {
+	    $self->log_error("Cannot open pipe: $!\n");
+	    return 0;
+	}
+
+	# We always trust the dummy apt repositories by setting trusted=yes.
+	#
+	# We use copy:// instead of file:// as URI because the latter will make
+	# apt use symlinks in /var/lib/apt/lists. These symlinks will become
+	# broken after the dummy archive is removed. This in turn confuses
+	# launchpad-buildd which directly tries to access
+	# /var/lib/apt/lists/*_Packages and cannot use `apt-get indextargets` as
+	# that apt feature is too new for it.
+        print $tmpfh 'deb [trusted=yes] copy://' . $dummy_archive_dir . " ./\n";
+        print $tmpfh 'deb-src [trusted=yes] copy://' . $dummy_archive_dir . " ./\n";
+
+        close($tmpfh);
+        # List file needs to be moved with root.
+        if (!$session->chmod($tmpfilename, '0644')) {
+            $self->log("Failed to create apt list file for dummy archive.\n");
+	    $session->unlink($tmpfilename);
+            return 0;
+        }
+        if (!$session->rename($tmpfilename, $dummy_archive_list_file)) {
+            $self->log("Failed to create apt list file for dummy archive.\n");
+	    $session->unlink($tmpfilename);
+            return 0;
+        }
+    }
+
+    return 1;
+}
+
+# Remove the apt archive.
+sub cleanup_apt_archive {
+    my $self = shift;
+
+    my $session = $self->get('Session');
+
+    if (defined $self->get('Dummy package path')) {
+	$session->unlink($self->get('Dummy package path'), { RECURSIVE => 1, FORCE => 1 });
+    }
+
+    if (defined $self->get('Extra packages path')) {
+	$session->unlink($self->get('Extra packages path'), { RECURSIVE => 1, FORCE => 1 });
+    }
+
+    $session->unlink($self->get('Dummy archive list file'), { FORCE => 1 });
+
+    $session->unlink($self->get('Extra repositories archive list file'), { FORCE => 1 });
+
+    $session->unlink($self->get('Extra packages archive list file'), { FORCE => 1 });
+
+    $self->set('Extra packages path', undef);
+    $self->set('Extra packages archive directory', undef);
+    $self->set('Extra packages release file', undef);
+    $self->set('Dummy archive directory', undef);
+    $self->set('Dummy Release file', undef);
+}
+
+# Function that runs apt-ftparchive
+sub run_apt_ftparchive {
+    my $self = shift;
+    my $dummy_archive_dir = shift;
+
+    my $session = $self->get('Session');
+
+    # We create the Packages, Sources and Release file inside the chroot.
+    # We cannot use IO::Compress::Gzip, Digest::MD5, or Digest::SHA because
+    # they are not available inside a chroot with only Essential:yes and apt
+    # installed.
+    # We cannot use apt-ftparchive as this is not available inside the chroot.
+    # Apt-ftparchive outside the chroot might not have access to the files
+    # inside the chroot (for example when using qemu or ssh backends).
+    # The only alternative would've been to set up the archive outside the
+    # chroot using apt-ftparchive and to then copy Packages, Sources and
+    # Release into the chroot.
+    # We do not do this to avoid copying files from and to the chroot.
+    # At the same time doing it like this has the advantage to have less
+    # dependencies of sbuild itself (no apt-ftparchive needed).
+    # The disadvantage of doing it this way is that we now have to maintain
+    # our own code creating the Release file which might break in the future.
+    my $packagessourcescmd = <<'SCRIPTEND';
+use strict;
+use warnings;
+
+use POSIX qw(strftime);
+use POSIX qw(locale_h);
+
+# Execute a command without /bin/sh but plain execvp while redirecting its
+# standard output to a file given as the first argument.
+# Using "print $fh `my_command`" has the disadvantage that "my_command" might
+# be executed through /bin/sh (depending on the characters used) or that the
+# output of "my_command" is very long.
+
+sub hash_file($$)
+{
+	my ($filename, $util) = @_;
+	my $output = `$util $filename`;
+	my ($hash, undef) = split /\s+/, $output;
+	return $hash;
+}
+
+{
+    opendir(my $dh, '.') or die "Can't opendir('.'): $!";
+    open my $out, '>', 'Packages';
+    while (my $entry = readdir $dh) {
+	next if $entry !~ /\.deb$/;
+	open my $in, '-|', 'dpkg-deb', '-I', $entry, 'control' or die "cannot fork dpkg-deb";
+	while (my $line = <$in>) {
+	    print $out $line;
+	}
+	close $in;
+	my $size = -s $entry;
+	my $md5 = hash_file($entry, 'md5sum');
+	my $sha1 = hash_file($entry, 'sha1sum');
+	my $sha256 = hash_file($entry, 'sha256sum');
+	print $out "Size: $size\n";
+	print $out "MD5sum: $md5\n";
+	print $out "SHA1: $sha1\n";
+	print $out "SHA256: $sha256\n";
+	print $out "Filename: ./$entry\n";
+	print $out "\n";
+    }
+    close $out;
+    closedir($dh);
+}
+{
+    opendir(my $dh, '.') or die "Can't opendir('.'): $!";
+    open my $out, '>', 'Sources';
+    while (my $entry = readdir $dh) {
+	next if $entry !~ /\.dsc$/;
+	my $size = -s $entry;
+	my $md5 = hash_file($entry, 'md5sum');
+	my $sha1 = hash_file($entry, 'sha1sum');
+	my $sha256 = hash_file($entry, 'sha256sum');
+	my ($sha1_printed, $sha256_printed, $files_printed) = (0, 0, 0);
+	open my $in, '<', $entry or die "cannot open $entry";
+	while (my $line = <$in>) {
+	    next if $line eq "\n";
+	    $line =~ s/^Source:/Package:/;
+	    print $out $line;
+	    if ($line eq "Checksums-Sha1:\n") {
+		print $out " $sha1 $size $entry\n";
+		$sha1_printed = 1;
+	    } elsif ($line eq "Checksums-Sha256:\n") {
+		print $out " $sha256 $size $entry\n";
+		$sha256_printed = 1;
+	    } elsif ($line eq "Files:\n") {
+		print $out " $md5 $size $entry\n";
+		$files_printed = 1;
+	    }
+	}
+	close $in;
+	if ($sha1_printed == 0) {
+	    print $out "Checksums-Sha1:\n";
+	    print $out " $sha1 $size $entry\n";
+	}
+	if ($sha256_printed == 0) {
+	    print $out "Checksums-Sha256:\n";
+	    print $out " $sha256 $size $entry\n";
+	}
+	if ($files_printed == 0) {
+	    print $out "Files:\n";
+	    print $out " $md5 $size $entry\n";
+	}
+	print $out "Directory: .\n";
+	print $out "\n";
+    }
+    close $out;
+    closedir($dh);
+}
+
+system('gzip -c --force Packages > Packages.gz') == 0 or die "gzip failed: $?\n";
+system('gzip -c --force Sources  > Sources.gz' ) == 0 or die "gzip failed: $?\n";
+
+my $packages_md5 = hash_file('Packages', 'md5sum');
+my $sources_md5 = hash_file('Sources', 'md5sum');
+my $packagesgz_md5 = hash_file('Packages.gz', 'md5sum');
+my $sourcesgz_md5 = hash_file('Sources.gz', 'md5sum');
+
+my $packages_sha1 = hash_file('Packages', 'sha1sum');
+my $sources_sha1 = hash_file('Sources', 'sha1sum');
+my $packagesgz_sha1 = hash_file('Packages.gz', 'sha1sum');
+my $sourcesgz_sha1 = hash_file('Sources.gz', 'sha1sum');
+
+my $packages_sha256 = hash_file('Packages', 'sha256sum');
+my $sources_sha256 = hash_file('Sources', 'sha256sum');
+my $packagesgz_sha256 = hash_file('Packages.gz', 'sha256sum');
+my $sourcesgz_sha256 = hash_file('Sources.gz', 'sha256sum');
+
+my $packages_size = -s 'Packages';
+my $sources_size = -s 'Sources';
+my $packagesgz_size = -s 'Packages.gz';
+my $sourcesgz_size = -s 'Sources.gz';
+
+# The timestamp format of release files is documented here:
+#   https://wiki.debian.org/RepositoryFormat#Date.2CValid-Until
+# It is specified to be the same format as described in Debian Policy §4.4
+#   https://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
+# or the same as in debian/changelog or the Date field in .changes files.
+# or the same format as `date -R`
+# To adhere to the specified format, the C or C.UTF-8 locale must be used.
+my $old_locale = setlocale(LC_TIME);
+setlocale(LC_TIME, "C.UTF-8");
+my $datestring = strftime "%a, %d %b %Y %H:%M:%S +0000", gmtime();
+setlocale(LC_TIME, $old_locale);
+
+open(my $releasefh, '>', 'Release') or die "cannot open Release for writing: $!";
+
+print $releasefh <<"END";
+Codename: invalid
+Date: $datestring
+Description: Sbuild Build Dependency Temporary Archive
+Label: sbuild-build-depends-archive
+Origin: sbuild-build-depends-archive
+Suite: invalid
+MD5Sum:
+ $packages_md5 $packages_size Packages
+ $sources_md5 $sources_size Sources
+ $packagesgz_md5 $packagesgz_size Packages.gz
+ $sourcesgz_md5 $sourcesgz_size Sources.gz
+SHA1:
+ $packages_sha1 $packages_size Packages
+ $sources_sha1 $sources_size Sources
+ $packagesgz_sha1 $packagesgz_size Packages.gz
+ $sourcesgz_sha1 $sourcesgz_size Sources.gz
+SHA256:
+ $packages_sha256 $packages_size Packages
+ $sources_sha256 $sources_size Sources
+ $packagesgz_sha256 $packagesgz_size Packages.gz
+ $sourcesgz_sha256 $sourcesgz_size Sources.gz
+END
+
+close $releasefh;
+
+SCRIPTEND
+
+    # Instead of using $(perl -e) and passing $packagessourcescmd as a command
+    # line argument, feed perl from standard input because otherwise the
+    # command line will be too long for certain backends (like the autopkgtest
+    # qemu backend).
+    my $pipe = $session->pipe_command(
+	{ COMMAND => ['perl'],
+	    USER => "root",
+	    DIR => $dummy_archive_dir,
+	    PIPE => 'out',
+	});
+    if (!$pipe) {
+	$self->log_error("cannot open pipe\n");
+	return 0;
+    }
+    print $pipe $packagessourcescmd;
+    close $pipe;
+    if ($? ne 0) {
+	$self->log_error("cannot create dummy archive\n");
+	return 0;
+    }
+
+    return 1;
+}
+
+sub get_apt_command_internal {
+    my $self = shift;
+    my $options = shift;
+
+    my $command = $options->{'COMMAND'};
+    my $apt_options = $self->get('APT Options');
+
+    debug2("APT Options: ", join(" ", @$apt_options), "\n")
+	if defined($apt_options);
+
+    my @aptcommand = ();
+    if (defined($apt_options)) {
+	push(@aptcommand, @{$command}[0]);
+	push(@aptcommand, @$apt_options);
+	if ($#$command > 0) {
+	    push(@aptcommand, @{$command}[1 .. $#$command]);
+	}
+    } else {
+	@aptcommand = @$command;
+    }
+
+    debug2("APT Command: ", join(" ", @aptcommand), "\n");
+
+    $options->{'INTCOMMAND'} = \@aptcommand;
+}
+
+sub run_apt_command {
+    my $self = shift;
+    my $options = shift;
+
+    my $session = $self->get('Session');
+    my $host = $self->get('Host');
+
+    # Set modfied command
+    $self->get_apt_command_internal($options);
+
+    if ($self->get('Split')) {
+	return $host->run_command_internal($options);
+    } else {
+	return $session->run_command_internal($options);
+    }
+}
+
+sub pipe_apt_command {
+    my $self = shift;
+    my $options = shift;
+
+    my $session = $self->get('Session');
+    my $host = $self->get('Host');
+
+    # Set modfied command
+    $self->get_apt_command_internal($options);
+
+    if ($self->get('Split')) {
+	return $host->pipe_command_internal($options);
+    } else {
+	return $session->pipe_command_internal($options);
+    }
+}
+
+sub pipe_xapt_command {
+    my $self = shift;
+    my $options = shift;
+
+    my $session = $self->get('Session');
+    my $host = $self->get('Host');
+
+    # Set modfied command
+    $self->get_apt_command_internal($options);
+
+    if ($self->get('Split')) {
+	return $host->pipe_command_internal($options);
+    } else {
+	return $session->pipe_command_internal($options);
+    }
+}
+
+sub get_aptitude_command_internal {
+    my $self = shift;
+    my $options = shift;
+
+    my $command = $options->{'COMMAND'};
+    my $apt_options = $self->get('Aptitude Options');
+
+    debug2("Aptitude Options: ", join(" ", @$apt_options), "\n")
+	if defined($apt_options);
+
+    my @aptcommand = ();
+    if (defined($apt_options)) {
+	push(@aptcommand, @{$command}[0]);
+	push(@aptcommand, @$apt_options);
+	if ($#$command > 0) {
+	    push(@aptcommand, @{$command}[1 .. $#$command]);
+	}
+    } else {
+	@aptcommand = @$command;
+    }
+
+    debug2("APT Command: ", join(" ", @aptcommand), "\n");
+
+    $options->{'INTCOMMAND'} = \@aptcommand;
+}
+
+sub run_aptitude_command {
+    my $self = shift;
+    my $options = shift;
+
+    my $session = $self->get('Session');
+    my $host = $self->get('Host');
+
+    # Set modfied command
+    $self->get_aptitude_command_internal($options);
+
+    if ($self->get('Split')) {
+	return $host->run_command_internal($options);
+    } else {
+	return $session->run_command_internal($options);
+    }
+}
+
+sub pipe_aptitude_command {
+    my $self = shift;
+    my $options = shift;
+
+    my $session = $self->get('Session');
+    my $host = $self->get('Host');
+
+    # Set modfied command
+    $self->get_aptitude_command_internal($options);
+
+    if ($self->get('Split')) {
+	return $host->pipe_command_internal($options);
+    } else {
+	return $session->pipe_command_internal($options);
+    }
+}
+
+sub get_sbuild_dummy_pkg_name {
+    my $self = shift;
+    my $name = shift;
+
+    return 'sbuild-build-depends-' . $name. '-dummy';
+}
+
+1;
diff -pruN 0.80.0/.pc/.quilt_patches 0.80.0ubuntu1/.pc/.quilt_patches
--- 0.80.0/.pc/.quilt_patches	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/.pc/.quilt_patches	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1 @@
+debian/patches
diff -pruN 0.80.0/.pc/.quilt_series 0.80.0ubuntu1/.pc/.quilt_series
--- 0.80.0/.pc/.quilt_series	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/.pc/.quilt_series	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1 @@
+series
diff -pruN 0.80.0/.pc/.version 0.80.0ubuntu1/.pc/.version
--- 0.80.0/.pc/.version	1970-01-01 00:00:00.000000000 +0000
+++ 0.80.0ubuntu1/.pc/.version	2020-08-04 14:28:23.000000000 +0000
@@ -0,0 +1 @@
+2
diff -pruN 0.80.0/scripts/.gitignore 0.80.0ubuntu1/scripts/.gitignore
--- 0.80.0/scripts/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/scripts/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1,5 +0,0 @@
-install-sh
-missing
-config.guess
-config.sub
-depcomp
diff -pruN 0.80.0/test/.gitignore 0.80.0ubuntu1/test/.gitignore
--- 0.80.0/test/.gitignore	2020-08-01 12:07:53.000000000 +0000
+++ 0.80.0ubuntu1/test/.gitignore	1970-01-01 00:00:00.000000000 +0000
@@ -1,10 +0,0 @@
-perl-syntax
-sbuild
-sbuild-checkpackages
-sbuild-clean
-sbuild-distupgrade
-sbuild-hold
-sbuild-stats
-sbuild-update
-sbuild-upgrade
-update
