Subject: [PATCH] Run the dbg-package-missing-depends check at the source package level so it knows about all the architecture-dependent packages built by the same source package (i.e. all the other packages the -dbg package may depen on).

From: Raphael Geissert <[email-masked]>
Date: Wed, 28 Jan 2009 02:59:10 -0600

This also increases the certainty and reduces the number of false positives by
not expecting X from X-dbg to actually exist.

Signed-off-by: Raphael Geissert <[email-masked]>
---
 checks/fields                |   30 ++++++++++++++++--------------
 checks/fields.desc           |   14 ++++----------
 testset/debug/debian/control |   27 +++++++++++++++++++++++++++
 testset/tags.debug           |    3 ++-
 4 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/checks/fields b/checks/fields
index fbc821f..65bf9b2 100644
--- a/checks/fields
+++ b/checks/fields
@@ -433,12 +433,6 @@ if ($type eq 'binary' && $arch_indep) {
 }
 if (($type eq "binary") || ($type eq 'udeb')) {
 	my (%deps, %fields, %parsed);
-	my $debugpackage = 0;
-	my ($debugbase, $debugfound);
-	if ($pkg =~ /^([^-]+)(?:-.*)?-dbg$/) {
-		$debugpackage = 1;
-		$debugbase = $1;
-	}
 	for my $field (qw(depends pre-depends recommends suggests conflicts provides enhances replaces breaks)) {
 		if (defined $info->field($field)) {
 			#Get data and clean it
@@ -488,11 +482,6 @@ if (($type eq "binary") || ($type eq 'udeb')) {
 				for my $part_d (@alternatives) {
 					my ($d_pkg, $d_version, $d_arch, $rest, $part_d_orig) = @$part_d;
 
-					# We have found a Depends: on our non-dbg equivalent.
-					if ($debugpackage && $field eq "depends" && $d_pkg =~ /^\Q$debugbase/) {
-						$debugfound = 1;
-					}
-
 					tag "versioned-provides", "$part_d_orig"
 					    if ($field eq "provides" && $d_version->[0]);
 
@@ -574,9 +563,6 @@ if (($type eq "binary") || ($type eq 'udeb')) {
 		}
 	}
 
-	tag "dbg-package-missing-depends", $debugbase
-		if ($debugpackage && !$debugfound);
-
 	# If Conflicts or Breaks is set, make sure it's not inconsistent with
 	# the other dependency fields.
 	for my $conflict (qw/conflicts breaks/) {
@@ -836,6 +822,22 @@ if ($type eq "source") {
 			}
 		}
 	}
+
+	my (@arch_dep_pkgs, @dbg_pkgs);
+	foreach my $binpkg (keys %$binpkgs) {
+		if ($binpkg =~ m/-dbg$/) {
+			push @dbg_pkgs, $binpkg;
+		} elsif ($info->binary_field($binpkg, 'architecture') ne 'all') {
+			push @arch_dep_pkgs, $binpkg;
+		}
+	}
+	foreach (@dbg_pkgs) {
+		my $deps;
+		$deps  = $info->binary_field($_, 'pre-depends') . ', ';
+		$deps .= $info->binary_field($_, 'depends');
+		tag 'dbg-package-missing-depends', $_
+		    unless (grep {my $quoted_name = qr<\Q$_>; $deps =~ m/(\s|^)$quoted_name(\s|$)/} @arch_dep_pkgs);
+	}
 }
 
 #----- Origin
diff --git a/checks/fields.desc b/checks/fields.desc
index fc02cfa..104fae5 100644
--- a/checks/fields.desc
+++ b/checks/fields.desc
@@ -3,7 +3,7 @@ Author: Marc 'HE' Brockschmidt <[email-masked]>
 Abbrev: fld
 Type: binary, udeb, source
 Unpack-Level: 1
-Needs-Info: debfiles
+Needs-Info: debfiles, source-control-fields
 Info: This script checks the syntax of the fields in package control files,
  as described in the Policy Manual.
 
@@ -728,8 +728,8 @@ Info: This package depends on makedev without a udev alternative.  This
 
 Tag: dbg-package-missing-depends
 Severity: normal
-Certainty: possible
-Info: This package has a name of the form of "X-dbg", indicating it
+Certainty: certain
+Info: The given binary package has a name of the form of "X-dbg", indicating it
  contains detached debugging symbols for the package X.  If so, it should
  depend on the corresponding package, generally with (= ${binary:Version})
  since the debugging symbols are only useful with the binaries created by
@@ -738,13 +738,7 @@ Info: This package has a name of the form of "X-dbg", indicating it
  If this package provides debugging symbols for multiple other
  packages, it should normally depend on all of those packages as
  alternatives.  In other words, <tt>pkga (= ${binary:Version}) | pkgb (=
- ${binary:Version)</tt> and so forth.  Provided that the non-dbg portion
- of the package name matches a prefix of the names of the packages on
- which it depends, Lintian should be able to recognize this dependency as
- correct.
- .
- In some cases, it may be necessary to override this tag because Lintian
- can't tell the correct dependency is in place.
+ ${binary:Version)</tt> and so forth.
 
 Tag: conflicts-with-dependency
 Severity: important
diff --git a/testset/debug/debian/control b/testset/debug/debian/control
index f623334..148de29 100644
--- a/testset/debug/debian/control
+++ b/testset/debug/debian/control
@@ -53,3 +53,30 @@ Description: Test for external debugging information (library symbols)
  This is a test package designed to exercise some feature or tag of
  Lintian.  It is part of the Lintian test suite and may do very odd
  things.  It should not be installed like a regular package.
+
+Package: hi-dbg
+Section: libdevel
+Priority: extra
+Architecture: any
+Depends: foo-pkg, not-libhello0
+Description: Test for external debugging symbols
+ Lintian regression test for external debugging files handling.  This test
+ contains the library symbols.
+ .
+ This is a test package designed to exercise some feature or tag of
+ Lintian.  It is part of the Lintian test suite and may do very odd
+ things.  It should not be installed like a regular package.
+
+Package: hello-hello-dbg
+Section: devel
+Priority: extra
+Architecture: any
+Depends: foo-pkg, not-libhello0, hello
+Description: Test for external debugging symbols - another try
+ Lintian regression test for external debugging files handling.  This test
+ contains the library symbols. This package actually tests a combination of
+ the above.
+ .
+ This is a test package designed to exercise some feature or tag of
+ Lintian.  It is part of the Lintian test suite and may do very odd
+ things.  It should not be installed like a regular package.
diff --git a/testset/tags.debug b/testset/tags.debug
index 064ff53..5cc53bb 100644
--- a/testset/tags.debug
+++ b/testset/tags.debug
@@ -20,12 +20,13 @@ E: libhello0: syntax-error-in-symbols-file 4
 E: libhello0: unknown-meta-field-in-symbols-file Build-Dep-Foo, line 10
 W: debug source: ancient-standards-version 3.7.0 (current is 3.8.0)
 W: debug source: changelog-should-not-mention-nmu
+W: debug source: dbg-package-missing-depends hi-dbg
+W: debug source: dbg-package-missing-depends libhello0-dbg
 W: debug source: debhelper-script-needs-versioned-build-depends dh_icons (>= 5.0.51~)
 W: debug source: debian-rules-sets-DH_COMPAT line 5
 W: debug source: timewarp-standards-version (2006-03-05 < 2006-04-26)
 W: hello: binary-without-manpage usr/bin/hello
 W: hello: binary-without-manpage usr/bin/hello.dbg
-W: libhello0-dbg: dbg-package-missing-depends libhello0
 W: libhello0-dbg: debug-file-should-use-detached-symbols ./usr/lib/debug/lib/libhello.so.0.0
 W: libhello0-dbg: shared-lib-without-dependency-information ./usr/lib/libhello.so.dbg
 W: libhello0: symbols-declares-dependency-on-other-package hello-dbg