Bug#832096: lintian: please check for common typos in debian/rules target names
> If there's override_dh_FOO, but dh_FOO is not in
> data/debhelper/dh_commands, and there's a known dh_* command that is
> within close edit distance to dh_FOO, then that's probably a typo.
Great idea! Updated patch attached.
Regards,
--
,''`.
: :' : Chris Lamb
`. `'` lamby@debian.org / chris-lamb.co.uk
`-
From 024d9bc1bb6b82645423f17a08a3359505448829 Mon Sep 17 00:00:00 2001
From: Chris Lamb <lamby@debian.org>
Date: Sat, 23 Jul 2016 19:12:03 +0100
Subject: [PATCH] c/rules: Check for common typos in debian/rules target names.
Misspelling a target (eg. "override_dh_install_debconf") results in that
rule silently not being called. See #831772 for an example in the wild.
Signed-off-by: Chris Lamb <lamby@debian.org>
---
checks/debhelper.desc | 12 ++++++++++++
checks/debhelper.pm | 14 +++++++++++++-
t/tests/debhelper-override-typos/debian/debian/control.in | 15 +++++++++++++++
t/tests/debhelper-override-typos/debian/debian/rules | 12 ++++++++++++
t/tests/debhelper-override-typos/desc | 5 +++++
t/tests/debhelper-override-typos/tags | 2 ++
6 files changed, 59 insertions(+), 1 deletion(-)
create mode 100644 t/tests/debhelper-override-typos/debian/debian/control.in
create mode 100755 t/tests/debhelper-override-typos/debian/debian/rules
create mode 100644 t/tests/debhelper-override-typos/desc
create mode 100644 t/tests/debhelper-override-typos/tags
diff --git a/checks/debhelper.desc b/checks/debhelper.desc
index 155aeb8..3c26b91 100644
--- a/checks/debhelper.desc
+++ b/checks/debhelper.desc
@@ -349,3 +349,15 @@ Severity: classification
Certainty: certain
Info: This is the build system that Lintian believes the package is
using.
+
+Tag: typo-in-debhelper-override-target
+Severity: normal
+Certainty: certain
+Info: The listed target in debian/rules command is a likely misspelling.
+ .
+ This can result in (for example) a <tt>dh_override_</tt>-style target
+ silently not being executed by <tt>make</tt>.
+ .
+ Implementation detail: The typo is detected by using "Levenshtein
+ edit distance". Therefore, if the typo involve several characters,
+ Lintian may not detect it.
diff --git a/checks/debhelper.pm b/checks/debhelper.pm
index 2bb76fc..2628aab 100644
--- a/checks/debhelper.pm
+++ b/checks/debhelper.pm
@@ -23,6 +23,8 @@ use strict;
use warnings;
use autodie;
+use Text::Levenshtein qw(distance);
+
use Lintian::Data;
use Lintian::Relation;
use Lintian::Tags qw(tag);
@@ -176,8 +178,18 @@ sub run {
$dhcompatvalue = $1;
# one can export and then set the value:
$level = $1 if ($level);
- } elsif (/^override_dh_/) {
+ } elsif (/^override_(dh_[^:]+)/) {
$needbuilddepends = 1;
+ my $dhcommand = $1;
+ if (not $dh_commands_depends->known($dhcommand)) {
+ # Unknown command, so check for likely misspellings
+ foreach my $x ($dh_commands_depends->all) {
+ if (distance($dhcommand, $x) < 3) {
+ tag 'typo-in-debhelper-override-target',
+ "override_$dhcommand", '->', "override_$x", "(line $.)";
+ }
+ }
+ }
} elsif (m,^include\s+/usr/share/cdbs/,) {
$inclcdbs = 1;
$build_systems{'cdbs-without-debhelper.mk'} = 1
diff --git a/t/tests/debhelper-override-typos/debian/debian/control.in b/t/tests/debhelper-override-typos/debian/debian/control.in
new file mode 100644
index 0000000..b65617f
--- /dev/null
+++ b/t/tests/debhelper-override-typos/debian/debian/control.in
@@ -0,0 +1,15 @@
+Source: {$source}
+Priority: extra
+Section: {$section}
+Maintainer: {$author}
+Standards-Version: {$standards_version}
+Build-Depends-Indep: debhelper (>= 9), python
+
+Package: {$source}
+Architecture: {$architecture}
+Depends: $\{shlibs:Depends\}, $\{misc:Depends\}
+Description: {$description}
+ 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. It may
+ be an empty package.
diff --git a/t/tests/debhelper-override-typos/debian/debian/rules b/t/tests/debhelper-override-typos/debian/debian/rules
new file mode 100755
index 0000000..849e63f
--- /dev/null
+++ b/t/tests/debhelper-override-typos/debian/debian/rules
@@ -0,0 +1,12 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
+# Good
+override_dh_install:
+override_dh_will_never_exist:
+
+# Bad
+override_dh_instakk:
+override_dh_install_examples:
diff --git a/t/tests/debhelper-override-typos/desc b/t/tests/debhelper-override-typos/desc
new file mode 100644
index 0000000..637e35b
--- /dev/null
+++ b/t/tests/debhelper-override-typos/desc
@@ -0,0 +1,5 @@
+Testname: debhelper-override-typos
+Sequence: 6000
+Version: 1.0
+Description: Test for typos in override targets
+Test-For: typo-in-debhelper-override-target
diff --git a/t/tests/debhelper-override-typos/tags b/t/tests/debhelper-override-typos/tags
new file mode 100644
index 0000000..ccd1906
--- /dev/null
+++ b/t/tests/debhelper-override-typos/tags
@@ -0,0 +1,2 @@
+W: debhelper-override-typos source: typo-in-debhelper-override-target override_dh_instakk -> override_dh_install (line 11)
+W: debhelper-override-typos source: typo-in-debhelper-override-target override_dh_install_examples -> override_dh_installexamples (line 12)
--
2.8.1
Reply to: