[lintian] 01/01: c/rules: Check for common typos in debian/rules target names.
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch typos-in-debhelper-commands
in repository lintian.
commit 65b0ea6a12d8e9741d3c5bb22b5dbc62dce1d340
Author: Chris Lamb <lamby@debian.org>
Date: Sat Jul 30 13:31:40 2016 -0400
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 | 15 ++++++++++++++-
t/tests/debhelper-override-typos/debian/debian/control.in | 15 +++++++++++++++
t/tests/debhelper-override-typos/debian/debian/rules | 15 +++++++++++++++
t/tests/debhelper-override-typos/desc | 5 +++++
t/tests/debhelper-override-typos/tags | 3 +++
6 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/checks/debhelper.desc b/checks/debhelper.desc
index 155aeb8..9b9d046 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: possible
+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..04394d9 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,19 @@ 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 (sort $dh_commands_depends->all) {
+ if (distance($dhcommand, $x) < 3) {
+ tag 'typo-in-debhelper-override-target',
+ "override_$dhcommand", '->', "override_$x", "(line $.)";
+ last; # Only emit a single match
+ }
+ }
+ }
} 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..4cfb47f
--- /dev/null
+++ b/t/tests/debhelper-override-typos/debian/debian/rules
@@ -0,0 +1,15 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
+# Good
+override_dh_install:
+override_dh_will_never_exist:
+
+# Bad
+override_dh_instakk:
+override_dh_install_examples:
+
+# Multiple matches should emit only one tag
+override_dh_nump: #
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..c8185b7
--- /dev/null
+++ b/t/tests/debhelper-override-typos/tags
@@ -0,0 +1,3 @@
+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)
+W: debhelper-override-typos source: typo-in-debhelper-override-target override_dh_nump -> override_dh_numpy (line 15)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: