Subject: [PATCH] Move the hardcoded list of commands to data/ and only emit debhelper-but-no-miscDepends when a command that may actually use misc:Depends is called

From: Raphael Geissert <[email-masked]>
Date: Fri, 12 Sep 2008 16:06:43 -0500

Signed-off-by: Raphael Geissert <[email-masked]>
---
 checks/debhelper                     |   49 +++++++++-------------------------
 data/debhelper/maint_commands        |   24 ++++++++++++++++
 data/debhelper/misc-Depends_commands |    8 +++++
 3 files changed, 45 insertions(+), 36 deletions(-)
 create mode 100644 data/debhelper/maint_commands
 create mode 100644 data/debhelper/misc-Depends_commands

diff --git a/checks/debhelper b/checks/debhelper
index 7a4bc3e..12d35fc 100644
--- a/checks/debhelper
+++ b/checks/debhelper
@@ -22,6 +22,7 @@ package Lintian::debhelper;
 use strict;
 use Tags;
 use Util;
+use Lintian::Data;
 
 sub run {
 
@@ -31,8 +32,6 @@ my $type = shift;
 use lib "$ENV{'LINTIAN_ROOT'}/lib";
 use Dep;
 
-my %commands;
-
 my $seencommand = '';
 my $needbuilddepends = '';
 my $needtomodifyscripts = '';
@@ -42,6 +41,7 @@ my $compat = '';
 my $usescdbs = '';
 my $seendhpython = '';
 my $usescdbspython = '';
+my $needmiscdepends = 0;
 
 # If there is no debian/compat file present but cdbs is being used, cdbs will
 # create one automatically.  Currently it always uses compatibility level 5.
@@ -50,37 +50,9 @@ my $usescdbspython = '';
 
 my $cdbscompat = 5;
 
-# Parse the debian/rules file, and try to figure out if debhelper commands
-# are run in it that like to modify maintainer scripts. Those debhelper
-# commands can be found by "grep -l autoscript /usr/bin/dh_*", but I'll
-# hardcode them here.
+my $maint_commands = Lintian::Data->new ('debhelper/maint_commands');
 
-map { $commands{$_}=1 } qw(dh_desktop
-			   dh_gconf
-			   dh_icons
-			   dh_installcatalogs
-			   dh_installdebconf
-                           dh_installdefoma
-                           dh_installdocs
-			   dh_installemacsen
-			   dh_installinfo
-			   dh_installinit
-			   dh_installmenu
-			   dh_installmime
-			   dh_installmodules
-			   dh_installtex
-			   dh_installudev
-			   dh_installwm
-			   dh_installxfonts
-			   dh_installxmlcatalogs
-			   dh_makeshlibs
-			   dh_pycentral
-			   dh_pysupport
-			   dh_python
-			   dh_scrollkeeper
-			   dh_suidregister
-			   dh_usrlocal
-			   );
+my $miscDeps_commands = Lintian::Data->new ('debhelper/misc-Depends_commands');
 
 # The version at which debhelper commands were introduced.  Packages that use
 # one of these commands must have a dependency on that version of debhelper or
@@ -108,9 +80,12 @@ while (<RULES>) {
 	    tag "dh_suidregister-is-obsolete", "";
 	}
 	# if command is passed -n, it does not modify the scripts
-	if ($commands{$dhcommand} and not m/\s+\-n\s+/) {
+	if ($maint_commands->known($dhcommand) and not m/\s+\-n\s+/) {
 	    $needtomodifyscripts = 1;
 	}
+	if ($miscDeps_commands->known($dh_command)) {
+	    $needmiscdepends = 1;
+	}
         if ($versions{$dhcommand}) {
             push (@versioncheck, $dhcommand);
         }
@@ -119,11 +94,13 @@ while (<RULES>) {
     } elsif (m,^\s+dh\s+,) {
 	$seencommand = 1;
 	$needbuilddepends = 1;
+	$needmiscdepends = 1;
 	push (@versioncheck, 'dh');
     } elsif (m,^include\s+/usr/share/cdbs/1/rules/debhelper.mk,) {
 	$seencommand = 1;
 	$needbuilddepends = 1;
 	$needtomodifyscripts = 1;
+	$needmiscdepends = 1;
 
 	# CDBS sets DH_COMPAT but doesn't export it.  It does, however, create
 	# a debian/compat file if none was found; that logic is handled later.
@@ -169,8 +146,8 @@ while(my $binpkg = readdir(BINPKGS)) {
         }
 
         tag 'debhelper-but-no-miscDepends', $binpkg
-            unless ($depends =~ m/\$\{misc:Depends\}/
-                    || $pkgs{$binpkg} ne 'deb');
+            if ($needmiscdepends and $depends !~ m/\$\{misc:Depends\}/
+                and $pkgs{$binpkg} eq 'deb');
     }
 }
 closedir(BINPKGS);
diff --git a/data/debhelper/maint_commands b/data/debhelper/maint_commands
new file mode 100644
index 0000000..3127102
--- /dev/null
+++ b/data/debhelper/maint_commands
@@ -0,0 +1,24 @@
+# This list of debhelper commands that like to modify maintainer scripts was
+# generated by using the following commands:
+# grep -l autoscript $(dpkg -L debhelper | egrep '^/usr/bin/dh_.+$') \
+# | sed s,/usr/bin/,,g | sort
+dh_desktop
+dh_gconf
+dh_icons
+dh_installcatalogs
+dh_installdebconf
+dh_installdocs
+dh_installemacsen
+dh_installinfo
+dh_installinit
+dh_installmenu
+dh_installmime
+dh_installmodules
+dh_installudev
+dh_installwm
+dh_installxfonts
+dh_makeshlibs
+dh_python
+dh_scrollkeeper
+dh_suidregister
+dh_usrlocal
diff --git a/data/debhelper/misc-Depends_commands b/data/debhelper/misc-Depends_commands
new file mode 100644
index 0000000..9a1f26d
--- /dev/null
+++ b/data/debhelper/misc-Depends_commands
@@ -0,0 +1,8 @@
+# This list of debhelper commands that may make use of ${misc:Depends} was
+# generated by using the following commands:
+# grep -l misc:Depends $(dpkg -L debhelper | egrep '^/usr/bin/dh_.+$') \
+# | sed s,/usr/bin/,,g | sort
+dh_gconf
+dh_installcatalogs
+dh_installdebconf
+dh_installxfonts