Package: debhelper
Version: 9.20150811
Severity: normal
Tags: patch

dh_auto_configure's very useful code to dump out config.log on failures
doesn't work when using -B to have a separate build directory, as you
can see here:

  
https://buildd.debian.org/status/fetch.php?pkg=grub2&arch=ppc64el&ver=2.02~beta2-27&stamp=1441370730&file=log

This is because, when doit_in_sourcedir/doit_in_builddir raise an
exception, their code to chdir back to the original directory is
bypassed, and so the exception handler in
Debian::Debhelper::Buildsystem::autoconf runs from the wrong directory
and fails to find config.log.  The attached patch arranges that the
chdir-back always happens before further propagating the exception.

Thanks,

-- 
Colin Watson                                       [cjwat...@debian.org]
>From acd0e42e174bf0db6f2af61bfaf5bcdbf9d5b47c Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwat...@debian.org>
Date: Sat, 5 Sep 2015 20:57:04 +0100
Subject: [PATCH] Fix doit_in_sourcedir/doit_in_builddir exception handling

Buildsystem.pm: Fix doit_in_sourcedir/doit_in_builddir to always
chdir back to the original directory even if the subprocess exits
non-zero.  This makes sure that the autoconf and cmake buildsystems
can still dump out configuration artifacts even when doing
out-of-tree builds.

Signed-off-by: Colin Watson <cjwat...@debian.org>
---
 Debian/Debhelper/Buildsystem.pm | 12 ++++++++++--
 debian/changelog                |  4 ++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Debian/Debhelper/Buildsystem.pm b/Debian/Debhelper/Buildsystem.pm
index 03d7e32..2fbb476 100644
--- a/Debian/Debhelper/Buildsystem.pm
+++ b/Debian/Debhelper/Buildsystem.pm
@@ -301,8 +301,12 @@ sub doit_in_sourcedir {
 	if ($this->get_sourcedir() ne '.') {
 		my $sourcedir = $this->get_sourcedir();
 		$this->_cd($sourcedir);
-		print_and_doit(@_);
+		eval {
+			print_and_doit(@_);
+		};
+		my $saved_exception = $@;
 		$this->_cd($this->_rel2rel($this->{cwd}, $sourcedir));
+		die $saved_exception if $saved_exception;
 	}
 	else {
 		print_and_doit(@_);
@@ -336,8 +340,12 @@ sub doit_in_builddir {
 	if ($this->get_buildpath() ne '.') {
 		my $buildpath = $this->get_buildpath();
 		$this->_cd($buildpath);
-		print_and_doit(@_);
+		eval {
+			print_and_doit(@_);
+		};
+		my $saved_exception = $@;
 		$this->_cd($this->_rel2rel($this->{cwd}, $buildpath));
+		die $saved_exception if $saved_exception;
 	}
 	else {
 		print_and_doit(@_);
diff --git a/debian/changelog b/debian/changelog
index 70c8b1e..d84c0a1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -59,6 +59,10 @@ debhelper (9.20150811+unreleased) UNRELEASED; urgency=medium
   * dh: Call dh_strip_nondeterminism during build.
     (Closes: #759895)
 
+  [ Colin Watson ]
+  * Buildsystem.pm: Fix doit_in_sourcedir/doit_in_builddir to always chdir
+    back to the original directory even if the subprocess exits non-zero.
+
  -- Paul Tagliamonte <paul...@debian.org>  Fri, 14 Aug 2015 21:25:16 +0200
 
 debhelper (9.20150811) unstable; urgency=medium
-- 
2.5.1

Reply via email to