From e8c9cdc7a80e630245d179fd702de3c8beb12abb Mon Sep 17 00:00:00 2001
From: Simon Ruderich <simon@ruderich.org>
Date: Wed, 14 Aug 2013 16:40:44 +0200
Subject: [PATCH] Fix detection of build dependencies for buildd logs.

Fixes Debian bug #719656, reported by Nicolas Boulenguez. Thanks.
---
 MANIFEST                                          | 1 +
 NEWS                                              | 2 ++
 bin/blhc                                          | 8 +++++---
 t/logs/ada                                        | 2 +-
 t/logs/debian                                     | 2 +-
 t/logs/debian-hardening-wrapper                   | 2 +-
 t/logs/debian-hardening-wrapper-old-build-depends | 9 +++++++++
 t/tests.t                                         | 4 +++-
 8 files changed, 23 insertions(+), 7 deletions(-)
 create mode 100644 t/logs/debian-hardening-wrapper-old-build-depends

diff --git a/MANIFEST b/MANIFEST
index 0c403db..d7fa680 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -33,6 +33,7 @@ t/logs/debian-cmake
 t/logs/debian-cmake-2
 t/logs/debian-cmake-ok
 t/logs/debian-hardening-wrapper
+t/logs/debian-hardening-wrapper-old-build-depends
 t/logs/debian-hardening-wrapper-pbuilder
 t/logs/dpkg-buildpackage-architecture-old
 t/logs/empty
diff --git a/NEWS b/NEWS
index a4f5503..d113ec7 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ Version 0.XX
   #710135), reported by Bastien Roucariès.
 - Handle another case of Qt's `moc` (Debian bug #710780), reported by Felix
   Geyer.
+- Fix detection of build dependencies for buildd logs (Debian bug #719656),
+  reported by Nicolas Boulenguez.
 
 - Sync architecture specific hardening support with dpkg 1.17.1.
 
diff --git a/bin/blhc b/bin/blhc
index 3ee8537..38d0834 100755
--- a/bin/blhc
+++ b/bin/blhc
@@ -729,9 +729,11 @@ foreach my $file (@ARGV) {
             }
         }
 
-        # Debian's build daemons use Build-Depends: for the build
-        # dependencies, but pbuilder just uses Depends:; support both.
-        if (index($line, 'Build-Depends: ') == 0
+        # Debian's build daemons use "Filtered Build-Depends:" (or just
+        # "Build-Depends:" in older versions) for the build dependencies, but
+        # pbuilder uses "Depends:"; support both.
+        if (index($line, 'Filtered Build-Depends: ') == 0
+                or index($line, 'Build-Depends: ') == 0
                 or index($line, 'Depends: ') == 0) {
             # If hardening wrapper is used (wraps calls to gcc and adds
             # hardening flags automatically) we can't perform any checks,
diff --git a/t/logs/ada b/t/logs/ada
index bc801c2..fceb8b1 100644
--- a/t/logs/ada
+++ b/t/logs/ada
@@ -1,4 +1,4 @@
-Build-Depends: ..., gnat, gnat-4.6, ...
+Filtered Build-Depends: ..., gnat, gnat-4.6, ...
 
 dpkg-buildpackage: source package ada package
 
diff --git a/t/logs/debian b/t/logs/debian
index e93b1c5..bbb65cf 100644
--- a/t/logs/debian
+++ b/t/logs/debian
@@ -1,4 +1,4 @@
-Build-Depends: .., gcc (>= 4:4.4.3), g++ (>= 4:4.4.3), ...
+Filtered Build-Depends: .., gcc (>= 4:4.4.3), g++ (>= 4:4.4.3), ...
 Toolchain package versions: ...
 Package versions: ...
 
diff --git a/t/logs/debian-hardening-wrapper b/t/logs/debian-hardening-wrapper
index 2e2966c..fbb06f7 100644
--- a/t/logs/debian-hardening-wrapper
+++ b/t/logs/debian-hardening-wrapper
@@ -1,4 +1,4 @@
-Build-Depends: .., hardening-wrapper, ...
+Filtered Build-Depends: .., hardening-wrapper, ...
 
 dpkg-buildpackage: source package test
 
diff --git a/t/logs/debian-hardening-wrapper-old-build-depends b/t/logs/debian-hardening-wrapper-old-build-depends
new file mode 100644
index 0000000..d460171
--- /dev/null
+++ b/t/logs/debian-hardening-wrapper-old-build-depends
@@ -0,0 +1,9 @@
+# Old buildd versions used Build-Depends instead of Filtered Build-Depends.
+Build-Depends: .., hardening-wrapper, ...
+
+dpkg-buildpackage: source package test
+
+gcc -g -O2 -c test-a.c
+gcc -g -O2 -c test-b.c
+gcc -g -O2 -c test-c.c
+gcc -o test test-a.o test-b.o test-c.o -ltest
diff --git a/t/tests.t b/t/tests.t
index 0330224..ad7a262 100644
--- a/t/tests.t
+++ b/t/tests.t
@@ -19,7 +19,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 206;
+use Test::More tests => 208;
 
 
 sub is_blhc {
@@ -884,6 +884,8 @@ my $debian_hardening_wrapper =
 ';
 is_blhc 'debian-hardening-wrapper', '', 16,
         $debian_hardening_wrapper;
+is_blhc 'debian-hardening-wrapper-old-build-depends', '', 16,
+        $debian_hardening_wrapper;
 is_blhc 'debian-hardening-wrapper-pbuilder', '', 16,
         $debian_hardening_wrapper;
 
-- 
2.49.0